Example usage for org.apache.commons.configuration SystemConfiguration SystemConfiguration

List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration SystemConfiguration SystemConfiguration.

Prototype

public SystemConfiguration() 

Source Link

Document

Create a Configuration based on the system properties.

Usage

From source file:com.netflix.iep.gov.Governator.java

private void initArchaius() {
    ConcurrentCompositeConfiguration composite = new ConcurrentCompositeConfiguration();
    composite.addConfiguration(new SystemConfiguration(), "system");
    composite.addConfiguration(new EnvironmentConfiguration(), "environment");
    ConfigurationManager.install(composite);
    loadProperties(ARCHAIUS_CONFIG_FILE);
    loadProperties("application");
}

From source file:com.kixeye.chassis.bootstrap.configuration.ConfigurationBuilder.java

/**
 * Build the Configuration//w ww  .  j a  v  a  2  s  .co  m
 *
 * @return the configuration
 */
public AbstractConfiguration build() {
    initApplicationFileConfiguration();
    initAppVersion();
    initApplicationConfiguration();
    initModuleConfiguration();

    ConcurrentCompositeConfiguration finalConfiguration = new ConcurrentCompositeConfiguration();
    if (addSystemConfigs) {
        finalConfiguration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
    }

    finalConfiguration.addProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);

    addServerInstanceProperties(finalConfiguration);

    if (applicationConfiguration == null) {
        LOGGER.warn("\n\n    ****** Default configuration being used ******\n    client application \""
                + appName
                + "\" is being configured with modules defaults. Defaults should only be used in development environments.\n    In non-developement environments, a configuration provider should be used to configure the client application and it should define ALL required configuration properties.\n");
        finalConfiguration.addConfiguration(applicationFileConfiguration);
        finalConfiguration.addConfiguration(moduleDefaultConfiguration);
    } else {
        finalConfiguration.addConfiguration(applicationConfiguration);
        finalConfiguration.addConfiguration(applicationFileConfiguration);
    }

    finalConfiguration.setProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);

    configureArchaius(finalConfiguration);

    logConfiguration(finalConfiguration);

    return finalConfiguration;
}

From source file:com.capgemini.archaius.spring.ArchaiusSpringPropertyPlaceholderSupport.java

private ConcurrentCompositeConfiguration addFileAndClasspathPropertyLocationsToConfiguration(
        ConcurrentCompositeConfiguration conComConfiguration, Map<String, String> parameterMap,
        Resource[] locations) throws IOException {

    int initialDelayMillis = Integer.valueOf(parameterMap.get(JdbcContants.INITIAL_DELAY_MILLIS));
    int delayMillis = Integer.valueOf(parameterMap.get(JdbcContants.DELAY_MILLIS));
    boolean ignoreDeletesFromSource = Boolean
            .parseBoolean(parameterMap.get(JdbcContants.IGNORE_DELETE_FROM_SOURCE));
    boolean ignoreResourceNotFound = Boolean
            .parseBoolean(parameterMap.get(JdbcContants.IGNORE_RESOURCE_NOT_FOUND));
    boolean includeSystemConfiguration = Boolean
            .parseBoolean(parameterMap.get(JdbcContants.INCLUDE_SYSTEM_CONFIGURATION));

    for (int i = locations.length - 1; i >= 0; i--) {
        try {/*from   w  w w. j  ava2s .  c om*/
            conComConfiguration.addConfiguration(new DynamicURLConfiguration(initialDelayMillis, delayMillis,
                    ignoreDeletesFromSource, locations[i].getURL().toString()));
        } catch (Exception ex) {
            if (!ignoreResourceNotFound) {
                LOGGER.error("Exception thrown when adding a configuration location.", ex);
                throw ex;
            }
        }
    }

    if (includeSystemConfiguration) {
        conComConfiguration.addConfiguration(new SystemConfiguration());
    }

    return conComConfiguration;
}

From source file:ffx.utilities.Keyword.java

/**
 * This method sets up configuration properties in the following precedence
 * * order:/*from  ww  w  . j  av a2 s  .  co m*/
 *
 * 1.) Structure specific properties (for example pdbname.properties)
 *
 * 2.) Java system properties a.) -Dkey=value from the Java command line b.)
 * System.setProperty("key","value") within Java code.
 *
 * 3.) User specific properties (~/.ffx/ffx.properties)
 *
 * 4.) System wide properties (file defined by environment variable
 * FFX_PROPERTIES)
 *
 * 5.) Internal force field definition.
 *
 * @since 1.0
 * @param file a {@link java.io.File} object.
 * @return a {@link org.apache.commons.configuration.CompositeConfiguration}
 * object.
 */
public static CompositeConfiguration loadProperties(File file) {
    /**
     * Command line options take precedence.
     */
    CompositeConfiguration properties = new CompositeConfiguration();

    /**
     * Structure specific options are first.
     */
    if (file != null) {
        String filename = file.getAbsolutePath();
        filename = org.apache.commons.io.FilenameUtils.removeExtension(filename);
        String propertyFilename = filename + ".properties";
        File structurePropFile = new File(propertyFilename);
        if (structurePropFile.exists() && structurePropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
            } catch (ConfigurationException | IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        } else {
            propertyFilename = filename + ".key";
            structurePropFile = new File(propertyFilename);
            if (structurePropFile.exists() && structurePropFile.canRead()) {
                try {
                    properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                    properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
                } catch (ConfigurationException | IOException e) {
                    logger.log(Level.INFO, " Error loading {0}.", filename);
                }
            }
        }
    }

    /**
     * Java system properties
     *
     * a.) -Dkey=value from the Java command line
     *
     * b.) System.setProperty("key","value") within Java code.
     */
    properties.addConfiguration(new SystemConfiguration());

    /**
     * User specific options are 3rd.
     */
    String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties";
    File userPropFile = new File(filename);
    if (userPropFile.exists() && userPropFile.canRead()) {
        try {
            properties.addConfiguration(new PropertiesConfiguration(userPropFile));
        } catch (ConfigurationException e) {
            logger.log(Level.INFO, " Error loading {0}.", filename);
        }
    }

    /**
     * System wide options are 2nd to last.
     */
    filename = System.getenv("FFX_PROPERTIES");
    if (filename != null) {
        File systemPropFile = new File(filename);
        if (systemPropFile.exists() && systemPropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(systemPropFile));
            } catch (ConfigurationException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        }
    }

    /**
     * Echo the interpolated configuration.
     */
    if (logger.isLoggable(Level.FINE)) {
        //Configuration config = properties.interpolatedConfiguration();
        Iterator<String> i = properties.getKeys();
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n %-30s %s\n", "Property", "Value"));
        while (i.hasNext()) {
            String s = i.next();
            //sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray())));
            sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray())));
        }
        logger.fine(sb.toString());
    }

    return properties;
}

From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationLoader.java

private org.apache.commons.configuration.Configuration createConfiguration() {
    AbstractConfiguration config;/*  w w w  . j av  a 2s  .  c  om*/

    switch (this.type) {
    case XML:
        config = new XMLConfiguration();
        break;

    case SYSTEM:
        config = new SystemConfiguration();
        break;

    default:
        config = new PropertiesConfiguration();
    }

    config.setDelimiterParsingDisabled(true);
    return config;
}

From source file:io.servicecomb.springboot.starter.configuration.CseAutoConfiguration.java

protected void configureArchaius(ConfigurableEnvironmentConfiguration envConfig) {
    if (INITIALIZED.compareAndSet(false, true)) {
        String appName = this.env.getProperty("spring.application.name");
        if (appName == null) {
            appName = "application";
            //log.warn("No spring.application.name found, defaulting to 'application'");
        }/*from   www.  jav  a  2  s. c  om*/
        System.setProperty(DeploymentContext.ContextKey.appId.getKey(), appName);

        ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();

        // support to add other Configurations (Jdbc, DynamoDb, Zookeeper, jclouds,
        // etc...)
        if (this.externalConfigurations != null) {
            for (AbstractConfiguration externalConfig : this.externalConfigurations) {
                config.addConfiguration(externalConfig);
            }
        }
        config.addConfiguration(envConfig, ConfigurableEnvironmentConfiguration.class.getSimpleName());

        // below come from ConfigurationManager.createDefaultConfigInstance()
        DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
        try {
            config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
        } catch (Throwable ex) {
            //log.error("Cannot create config from " + defaultURLConfig, ex);
        }

        // TODO: sys/env above urls?
        if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) {
            SystemConfiguration sysConfig = new SystemConfiguration();
            config.addConfiguration(sysConfig, SYS_CONFIG_NAME);
        }
        if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) {
            EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
            config.addConfiguration(environmentConfiguration, ENV_CONFIG_NAME);
        }

        ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration();
        config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES);
        config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig));

        addArchaiusConfiguration(config);
    }
    //        else {
    //            // TODO: reinstall ConfigurationManager
    //            //log.warn(
    //            //       "Netflix ConfigurationManager has already been installed, unable to re-install");
    //        }
}

From source file:br.eti.kinoshita.testlinkjavaapi.TestLinkAPI.java

/**
 * Creates application composite configuration.
 * //from  ww  w  . ja  va  2 s.c om
 * @return Application composite configuration.
 */
private CompositeConfiguration createApplicationConfiguration() {
    CompositeConfiguration appConfig = new CompositeConfiguration();
    appConfig.addConfiguration(new SystemConfiguration());
    try {
        appConfig.addConfiguration(new PropertiesConfiguration("testlinkjavaapi.properties"));
    } catch (ConfigurationException ce) {
        this.debug(ce);
    }
    return appConfig;
}

From source file:com.impetus.kundera.utils.KunderaCoreUtils.java

/**
 * Resolves variable in path given as string
 * /*www  .j  ava  2s  . c  o  m*/
 * @param input
 *            String input url Code inspired by
 *            :http://stackoverflow.com/questions/2263929/
 *            regarding-application-properties-file-and-environment-variable
 */
public static String resolvePath(String input) {
    if (null == input) {
        return input;
    }

    // matching for 2 groups match ${VAR_NAME} or $VAR_NAME
    Pattern pathPattern = Pattern.compile("\\$\\{(.+?)\\}");
    Matcher matcherPattern = pathPattern.matcher(input); // get a matcher
                                                         // object
    StringBuffer sb = new StringBuffer();
    EnvironmentConfiguration config = new EnvironmentConfiguration();
    SystemConfiguration sysConfig = new SystemConfiguration();

    while (matcherPattern.find()) {

        String confVarName = matcherPattern.group(1) != null ? matcherPattern.group(1)
                : matcherPattern.group(2);
        String envConfVarValue = config.getString(confVarName);
        String sysVarValue = sysConfig.getString(confVarName);

        if (envConfVarValue != null) {

            matcherPattern.appendReplacement(sb, envConfVarValue);

        } else if (sysVarValue != null) {

            matcherPattern.appendReplacement(sb, sysVarValue);

        } else {
            matcherPattern.appendReplacement(sb, "");
        }
    }
    matcherPattern.appendTail(sb);
    return sb.toString();
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader.java

/**
 * Returns the configuration class according to specified resource name and configuration type.
 * /*from w  ww  . j  av a  2 s .  c o  m*/
 * @param resource
 * @param type
 * @return a configuration
 */
private org.apache.commons.configuration.Configuration getConfiguration(String resource, ConfigType type) {
    org.apache.commons.configuration.Configuration config = null;

    try {
        switch (type) {
        case SYSTEM:
            config = new SystemConfiguration();
            break;

        case PROPERTIES:
            config = new PropertiesConfiguration(resource + ".properties");
            break;

        case XML:
            config = new XMLConfiguration(resource + ".xml");
            break;

        default:
            throw new ConfigurationException(
                    bundle.getString("configuration-type-not-implemented-yet", type.name()));
        }

    } catch (Exception cause) {
        throw new ConfigurationException(
                bundle.getString("error-creating-configuration-from-resource", resource), cause);
    }

    return config;
}

From source file:io.servicecomb.foundation.ssl.SSLOptionTest.java

@Test
public void testSSLOptionYamlOption2() throws Exception {
    System.setProperty("ssl.protocols", "TLSv1.2");
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(),
            new NeverStartPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(
            new SystemConfiguration());
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");

    SSLOption option = SSLOption.buildFromYaml("server", finalConfig);

    String protocols = option.getProtocols();
    option.setProtocols(protocols);/*w w w .ja v a  2 s .  co  m*/
    Assert.assertEquals("TLSv1.2", protocols);
    System.clearProperty("ssl.protocols");
}