List of usage examples for org.apache.commons.configuration EnvironmentConfiguration EnvironmentConfiguration
public EnvironmentConfiguration()
From source file:com.hpe.caf.worker.testing.SystemSettingsProvider.java
private static CompositeConfiguration createConfiguration() { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); return configuration; }
From source file:com.dattack.jtoolbox.commons.configuration.ConfigurationUtil.java
/** * Create a <code>Configuration</code> based on the environment variables and system properties. * * @return a <code>Configuration</code> based on the environment variables and system properties *///from w w w . j a va 2s . c o m public static CompositeConfiguration createEnvSystemConfiguration() { final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); return configuration; }
From source file:com.dattack.naming.loader.factory.DataSourceFactory.java
@Override public DataSource getObjectInstance(final Properties properties, final Collection<File> extraClasspath) throws NamingException { final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(properties)); final String driver = configuration.getString(DRIVER_KEY); if (driver == null) { throw new ConfigurationException(String.format("Missing property '%s'", DRIVER_KEY)); }/* w ww .java 2 s .com*/ final String url = configuration.getString(URL_KEY); if (url == null) { throw new ConfigurationException(String.format("Missing property '%s'", URL_KEY)); } final String user = configuration.getString(USERNAME_KEY); final String password = configuration.getString(PASSWORD_KEY); DataSource dataSource = null; try { final Properties props = ConfigurationConverter.getProperties(configuration); dataSource = BasicDataSourceFactory.createDataSource(props); } catch (final Exception e) { // NOPMD by cvarela on 8/02/16 22:28 // we will use a DataSource without a connection pool LOGGER.info(e.getMessage()); dataSource = new SimpleDataSource(driver, url, user, password); } return new DataSourceClasspathDecorator(dataSource, extraClasspath); }
From source file:com.vmware.qe.framework.datadriven.config.DDConfig.java
/** * Returns the configuration data. If configuration data is null, method first attempts to * create a configuration data from JVM's system properties.<br> * /*from ww w . j a v a 2 s .c o m*/ * @return test configuration data */ public synchronized Configuration getData() { if (data != null) { return data; } final HierarchicalConfiguration cfg = new HierarchicalConfiguration(); cfg.copy(new EnvironmentConfiguration());// copy the environment variables. cfg.copy(new SystemConfiguration());// JVM args log.debug("Configuration data from Env:\n" + ConfigurationUtils.toString(cfg)); return data = prepareData(cfg); }
From source file:com.dattack.naming.standalone.StandaloneContextFactory.java
private static CompositeConfiguration getConfiguration(final Map<?, ?> environment) { final BaseConfiguration baseConf = new BaseConfiguration(); for (final Entry<?, ?> entry : environment.entrySet()) { baseConf.setProperty(ObjectUtils.toString(entry.getKey()), entry.getValue()); }/*from w w w.j a va 2 s . co m*/ final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(baseConf); return configuration; }
From source file:com.intel.mtwilson.fs.ConfigurableFilesystem.java
/** * First priority is the configuration that is passed in. * Second is the java system properties specified on command line like -Dfs.name * Third is exported environment variables like FS_NAME * //from w w w . j a v a2 s. c om * @param configuration */ public ConfigurableFilesystem(Configuration configuration) { CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(configuration); SystemConfiguration system = new SystemConfiguration(); composite.addConfiguration(system); EnvironmentConfiguration env = new EnvironmentConfiguration(); composite.addConfiguration(env); AllCapsEnvironmentConfiguration envAllCaps = new AllCapsEnvironmentConfiguration(); composite.addConfiguration(envAllCaps); this.configuration = composite; }
From source file:io.servicecomb.config.ConfigUtil.java
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateServiceCombConfigToCse(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateServiceCombConfigToCse(config, new ConcurrentMapConfiguration(new EnvironmentConfiguration()), "configFromEnvironment"); duplicateServiceCombConfigToCse(config, new DynamicConfiguration(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); return config; }
From source file:com.yahoo.bard.webservice.config.LayeredFileSystemConfig.java
/** * Build a Layered File System Configuration, using first the environment and an application configuration source, * then drill down into available modules and load each of them in package dependency order. *//*www. java 2s . c om*/ @SuppressWarnings(value = "unchecked") public LayeredFileSystemConfig() { masterConfiguration = new CompositeConfiguration(); masterConfiguration.setThrowExceptionOnMissing(true); runtimeProperties = new Properties(); try { List<Configuration> userConfig = loader.loadConfigurations(USER_CONFIG_FILE_NAME); // User configuration provides overrides for configuration on a specific environment or specialized role if (userConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(USER_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_USER_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_USER_CONFIGS.format(resources.size())); } // Test application configuration provides overrides for configuration in a testing environment List<Configuration> testApplicationConfig = loader.loadConfigurationsNoJars(TEST_CONFIG_FILE_NAME); // Application configuration defines configuration at an application level for a bard instance List<Configuration> applicationConfig = loader.loadConfigurations(APPLICATION_CONFIG_FILE_NAME); if (applicationConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(APPLICATION_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_APPLICATION_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_APPLICATION_CONFIGS.format(resources.size())); } // Environment config has higher priority than java system properties // Java system properties have higher priority than file based configuration // Also, a runtime map is maintained to support on-the-fly configuration changes // Load the rest of the config "top down" through the layers, in highest to lowest precedence Stream.of(Stream.of(new MapConfiguration(runtimeProperties)), Stream.of(new EnvironmentConfiguration()), Stream.of(new SystemConfiguration()), userConfig.stream(), testApplicationConfig.stream(), applicationConfig.stream()).flatMap(Function.identity()).filter(Objects::nonNull) .forEachOrdered(masterConfiguration::addConfiguration); // Use the config which has been loaded to identify module dependencies List<String> dependentModules = (List<String>) masterConfiguration .getList(ConfigurationGraph.DEPENDENT_MODULE_KEY, Collections.<String>emptyList()); // Add module dependencies to the master configuration new ModuleLoader(loader).getConfigurations(dependentModules) .forEach(masterConfiguration::addConfiguration); } catch (IOException e) { throw new SystemConfigException(e); } }
From source file:cz.mzk.editor.server.config.EditorConfigurationImpl.java
public EditorConfigurationImpl() { File dir = new File(WORKING_DIR); if (!dir.exists()) { boolean mkdirs = dir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'"); }//ww w . jav a 2s. co m } File confFile = new File(CONFIGURATION); if (!confFile.exists()) { try { confFile.createNewFile(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } FileOutputStream confFos; try { confFos = new FileOutputStream(confFile); } catch (FileNotFoundException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } try { try { new Properties().store(confFos, "configuration file for module metadata editor"); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } } finally { try { if (confFos != null) confFos.close(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } finally { confFos = null; } } } CompositeConfiguration constconf = new CompositeConfiguration(); PropertiesConfiguration file = null; try { file = new PropertiesConfiguration(confFile); } catch (ConfigurationException e) { LOGGER.error(e.getMessage(), e); new RuntimeException("cannot read configuration"); } file.setReloadingStrategy(new FileChangedReloadingStrategy()); constconf.addConfiguration(file); constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR); this.configuration = constconf; String hostname = configuration.getString(EditorClientConfiguration.Constants.HOSTNAME, "editor.mzk.cz"); if (hostname.contains("://")) { hostname = hostname.substring(hostname.indexOf("://") + "://".length()); } File imagesDir = new File(ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator); if (!imagesDir.exists()) { boolean mkdirs = imagesDir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); } } constconf.setProperty(ServerConstants.IMAGES_LOCATION, ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator); EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(); for (Iterator it = environmentConfiguration.getKeys(); it.hasNext();) { String key = (String) it.next(); Object value = environmentConfiguration.getProperty(key); key = key.replaceAll("_", "."); key = key.replaceAll("\\.\\.", "__"); constconf.addProperty(key, value); } }
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"); }