All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.avaje.glue.properties.PropertiesLoader Maven / Gradle / Ivy

The newest version!
package org.avaje.glue.properties;

import java.util.Enumeration;
import java.util.Properties;

/**
 * Loads and evaluates properties and yml configuration.
 */
public class PropertiesLoader {

  private static Properties properties;

  /**
   * Provides properties by reading known locations.
   * 

*

Main configuration

*

*

Firstly loads from main resources

*
   *   - application.properties
   *   - application.yml
   * 
*

*

Then loads from local files

*
   *   - application.properties
   *   - application.yml
   * 
*

*

Then loads from environment variable PROPS_FILE

*

Then loads from system property props.file

*

Then loads from load.properties

*

*

Test configuration

*

* Once the main configuration is read it will try to read common test configuration. * This will only be successful if the test resources are available (i.e. running tests). *

*

Loads from test resources

*
   *   - application-test.properties
   *   - application-test.yml
   * 
*/ public static synchronized Properties load(String[] args) { if (properties == null) { Loader loader = new Loader(); loader.load(args); properties = loader.eval(); } return properties; } /** * Load the properties (if not already loaded) without using any command line args to pass properties file(s). */ public static synchronized Properties load() { return load(null); } /** * Return a copy of the properties with 'eval' run on all the values. * This resolves expressions like ${HOME} etc. */ public static Properties eval(Properties properties) { Properties evalCopy = new Properties(); Enumeration names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = PropertyEval.eval(properties.getProperty(name)); evalCopy.setProperty(name, value); } return evalCopy; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy