List of usage examples for org.apache.commons.configuration EnvironmentConfiguration EnvironmentConfiguration
public EnvironmentConfiguration()
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 w w w .j a va 2s. com*/ 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:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Resolves variable in path given as string * /* ww w . j av a 2 s.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:com.intel.mtwilson.MyConfiguration.java
private Configuration gatherConfiguration(Properties customProperties) { CompositeConfiguration composite = new CompositeConfiguration(); // first priority: custom properties take priority over any other source if (customProperties != null) { MapConfiguration customconfig = new MapConfiguration(customProperties); logConfiguration("custom", customconfig); composite.addConfiguration(customconfig); }// w w w . j a v a 2s .c om // second priority are properties defined on the current JVM (-D switch // or through web container) SystemConfiguration system = new SystemConfiguration(); logConfiguration("system", system); composite.addConfiguration(system); // third priority: environment variables (regular and also converted from dot-notation to all-caps) EnvironmentConfiguration env = new EnvironmentConfiguration(); logConfiguration("environment", env); composite.addConfiguration(env); // AllCapsEnvironmentConfiguration envAllCaps = new AllCapsEnvironmentConfiguration(); // logConfiguration("environment_allcaps", envAllCaps); // composite.addConfiguration(envAllCaps); List<File> files = listConfigurationFiles(); // add all the files we found so far, in the priority order for (File f : files) { // System.out.println("Looking for "+f.getAbsolutePath()); try { if (f.exists() && f.canRead()) { // first check if the file is encrypted... if it is, we need to decrypt it before loading! try (FileInputStream in = new FileInputStream(f)) { String content = IOUtils.toString(in); if (Pem.isPem(content)) { // starts with something like -----BEGIN ENCRYPTED DATA----- and ends with -----END ENCRYPTED DATA----- // a pem-format file indicates it's encrypted... we could check for "ENCRYPTED DATA" in the header and footer too. String password = getApplicationConfigurationPassword(); if (password == null) { log.warn( "Found encrypted configuration file, but no password was found in system properties or environment"); } if (password != null) { ExistingFileResource resource = new ExistingFileResource(f); PasswordEncryptedFile encryptedFile = new PasswordEncryptedFile(resource, password); String decryptedContent = encryptedFile.loadString(); Properties p = new Properties(); p.load(new StringReader(decryptedContent)); MapConfiguration encrypted = new MapConfiguration(p); logConfiguration("encrypted-file:" + f.getAbsolutePath(), encrypted); composite.addConfiguration(encrypted); } } else { log.debug("FILE {} IS IN REGULAR PROPERTIES FORMAT", f.getAbsolutePath()); PropertiesConfiguration standard = new PropertiesConfiguration(f); logConfiguration("file:" + f.getAbsolutePath(), standard); composite.addConfiguration(standard); } } } } catch (FileNotFoundException ex) { // shouldn't happen since we check for f.exists() first, but must handle it because FileInputStream can throw it log.error("File not found: " + f.getAbsolutePath(), ex); } catch (IOException ex) { log.error("Cannot load configuration: " + f.getAbsolutePath(), ex); } catch (ConfigurationException ex) { log.error("Cannot load configuration from " + f.getAbsolutePath(), ex); } } // seventh priority are properties defined on the classpath (for example defaults provided with the application, or placed in the web server container) String propertiesFilename = "mtwilson.properties"; InputStream in = getClass().getResourceAsStream("/" + propertiesFilename); try { // user's home directory (assuming it's on the classpath!) if (in != null) { Properties properties = new Properties(); properties.load(in); MapConfiguration classpath = new MapConfiguration(properties); logConfiguration("classpath:" + propertiesFilename, classpath); composite.addConfiguration(classpath); } } catch (IOException ex) { log.debug("Did not find [" + propertiesFilename + "] properties on classpath", ex); } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.error("Failed to close input stream for " + propertiesFilename); } } } return composite; }
From source file:com.nridge.core.app.mgr.AppMgr.java
/** * Loads the default property files ("application.properties" and * "logback.xml") from the file system and assigns default application * properties.//from w ww . ja v a2 s .c o m * <p> * <b>Note:</b> This method will establish a default 5 minute reloading * policy for the "application.properties" file. Therefore, any * changes to this property file while the application is running * will be recognized within a 5 minute period. * </p> * * @throws NSException Typically thrown for I/O related issues. */ public void loadPropertyFiles() throws NSException { String logFileName; try { // First, we will read our application properties. mConfiguration = new CompositeConfiguration(); mConfiguration.setDelimiterParsingDisabled(true); mConfiguration.addConfiguration(new SystemConfiguration()); mConfiguration.addConfiguration(new EnvironmentConfiguration()); PropertiesConfiguration propertyCfg = new PropertiesConfiguration(deriveCfgPathFileName()); FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(DateUtils.MILLIS_PER_MINUTE * 2L); propertyCfg.setReloadingStrategy(reloadingStrategy); mConfiguration.addConfiguration(propertyCfg); // Next, we will load our Logback properties file and configure our application logger. if (mCmdLine == null) logFileName = LOG_PROPERTY_FILE_NAME; else logFileName = mCmdLine.getOptionValue("logfile", LOG_PROPERTY_FILE_NAME); File logFile = new File(logFileName); if (!logFile.exists()) { String logPathFileName = String.format("%s%c%s", deriveCfgPathName(), File.separatorChar, logFileName); logFile = new File(logPathFileName); if (logFile.exists()) logFileName = logPathFileName; else throw new NSException("Unable to locate logging properties file: " + logFileName); } if (StringUtils.isEmpty(getString(APP_PROPERTY_INS_PATH))) mConfiguration.addProperty(APP_PROPERTY_INS_PATH, getInsPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_CFG_PATH))) mConfiguration.addProperty(APP_PROPERTY_CFG_PATH, deriveCfgPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_LOG_PATH))) mConfiguration.addProperty(APP_PROPERTY_LOG_PATH, deriveLogPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_DS_PATH))) mConfiguration.addProperty(APP_PROPERTY_DS_PATH, deriveDSPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_RDB_PATH))) mConfiguration.addProperty(APP_PROPERTY_RDB_PATH, deriveRDBMSPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_GDB_PATH))) mConfiguration.addProperty(APP_PROPERTY_GDB_PATH, deriveGraphPathName()); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator joranConfigurator = new JoranConfigurator(); joranConfigurator.setContext(loggerContext); loggerContext.reset(); joranConfigurator.doConfigure(logFileName); } catch (ConfigurationException e) { throw new NSException("Configuration parsing error: " + e.getMessage()); } catch (JoranException e) { throw new NSException("Logback parsing error: " + e.getMessage()); } catch (ClassCastException ignored) { /* Note that a WARNING related to java.lang.ClassCastException will trigger due to Smart GWT and NSD being dependent on different releases of the same logging framework. http://www.slf4j.org/codes.html */ } }
From source file:org.apache.accumulo.server.metrics.MetricsConfiguration.java
public Configuration getEnvironmentConfiguration() { synchronized (MetricsConfiguration.class) { if (null == envConfig) envConfig = new EnvironmentConfiguration(); return envConfig; }/* ww w . j a v a2s .co m*/ }
From source file:org.apache.servicecomb.config.ConfigUtil.java
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())), "configFromEnvironment"); // If there is extra configurations, add it into config. EXTRA_CONFIG_MAP.entrySet().stream().filter(mapEntry -> !mapEntry.getValue().isEmpty()) .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(configMapEntry.getValue()), configMapEntry.getKey())); // we have already copy the cse config to the serviceComb config when we load the config from local yaml files // hence, we do not need duplicate copy it. config.addConfiguration(new DynamicConfiguration(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfiguration(ConfigMapping.getConvertedMap(config)), "configFromMapping"); return config; }
From source file:org.mifos.dmt.configuration.DMTPropertiesLoader.java
private DMTPropertiesLoader() throws ConfigurationException { config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new EnvironmentConfiguration()); String confPath = config.getString("DMT_CONF"); if (confPath == null || confPath == "" || confPath.equalsIgnoreCase("")) { throw new ConfigurationException("DMT_CONF not defined"); }/*from w w w . j a v a 2s.co m*/ config.addConfiguration(new PropertiesConfiguration(confPath + "\\dmt.custom.properties")); config.addConfiguration(new PropertiesConfiguration("dmt.properties")); config.setThrowExceptionOnMissing(true); }
From source file:org.rzo.yajsw.wrapper.FileUtils.java
/** * The main method.//w w w .jav a 2 s . c o m * * @param args * the arguments */ public static void main(String[] args) { try { // String // fileName=FilenameUtils.separatorsToSystem("C:\\init\\MOBILEguard\\yajsw/lib/jvmstat/*.jar"); // System.out.println("FileName: "+fileName); CompositeConfiguration compConfig = new CompositeConfiguration(); AbstractConfiguration configuraton = new BaseConfiguration(); compConfig.addConfiguration(new EnvironmentConfiguration()); configuraton.setProperty("wrapper.java.classpath.1", "${VERSANT_ROOT}/lib/jvi.*jar"); configuraton.setProperty("wrapper.java.classpath.2", "${GROOVY_HOME}/lib/*.jar"); compConfig.addConfiguration(configuraton); System.out.println("Configuration: " + ConfigurationConverter.getProperties(compConfig)); System.out .println("subset: " + ConfigurationConverter.getProperties(compConfig.subset("wrapper.java"))); // Collection files=FileUtils.getFiles("../..", // "C:/versant/7_0_1/lib/jvi*.jar"); // Collection collection= // org.apache.commons.io.FileUtils.listFiles(new File("C:/"), // new WildcardFileFilter("jvi*.jar"), new // WildcardFileFilter("*jar")); // File[] files= new // File("C:").listFiles((FilenameFilter)FileFilterUtils.nameFileFilter("C:/versant/7_0_1/lib/jvi*.jar")); // // FileUtils.getFiles("C:/versant/7_0_1/lib/", "jvi*.jar"); // System.out.println("FileList="+ // FileUtils.getFiles("C:/versant/7_0_1/lib/", "jvi*.jar")); // java.util.Arrays.asList(files)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.sonar.ant.Launcher.java
private Configuration getInitialConfiguration(ProjectDefinition project) { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(project.getProperties())); return configuration; }
From source file:org.sonar.batch.MavenProjectBuilder.java
Configuration getStartupConfiguration(MavenProject pom) { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(pom.getModel().getProperties())); return configuration; }