List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:com.torodb.mongodb.core.DefaultBuildProperties.java
public DefaultBuildProperties(String propertiesFile) { PropertiesConfiguration properties;//from w w w.j a va2s . c o m try { properties = new PropertiesConfiguration(Resources.getResource(propertiesFile)); } catch (ConfigurationException e) { throw new RuntimeException("Cannot read build properties file '" + propertiesFile + "'"); } fullVersion = properties.getString("version"); Matcher matcher = FULL_VERSION_PATTERN.matcher(fullVersion); if (!matcher.matches()) { throw new RuntimeException("Invalid version string '" + fullVersion + "'"); } majorVersion = Integer.parseInt(matcher.group(1)); minorVersion = Integer.parseInt(matcher.group(2)); subVersion = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : 0; extraVersion = matcher.group(4); // DateUtils.parseDate may be replaced by SimpleDateFormat if using Java7 try { buildTime = Instant.parse(properties.getString("buildTimestamp")); } catch (DateTimeParseException e) { throw new RuntimeException("buildTimestamp property not in ISO8601 format", e); } gitCommitId = properties.getString("gitCommitId"); gitBranch = properties.getString("gitBranch"); gitRemoteOriginUrl = properties.getString("gitRemoteOriginURL"); javaVersion = properties.getString("javaVersion"); javaVendor = properties.getString("javaVendor"); javaVmSpecificationVersion = properties.getString("javaVMSpecificationVersion"); javaVmVersion = properties.getString("javaVMVersion"); osName = properties.getString("osName"); osArch = properties.getString("osArch"); osVersion = properties.getString("osVersion"); }
From source file:com.codspire.mojo.artifactlookup.LookupForDependency.java
public LookupForDependency(File artifactLocation, boolean recursive, List<String> remoteArtifactRepositoriesURL, File outputDirectory, Log log) { try {/*from ww w .j a va 2s . c o m*/ this.plugInConfig = new PropertiesConfiguration("artifact-lookup-maven-plugin.properties"); this.plugInConfig.setListDelimiter(','); } catch (ConfigurationException e) { throw new ContextedRuntimeException("Unable to load artifact-lookup-maven-plugin.properties", e); } this.log = log; this.outputDirectory = outputDirectory; this.remoteArtifactRepositoriesURL = remoteArtifactRepositoriesURL; this.notFoundList = loadArtifacts(artifactLocation, recursive); this.foundList = new ArrayList<ProcessingStatus>(); }
From source file:com.freemedforms.openreact.engine.Configuration.java
public static void loadConfiguration(String defaultConfig, String overrideConfig) { logger.trace("Entered loadConfiguration"); if (compositeConfiguration == null) { logger.info("Configuration object not present, instantiating"); compositeConfiguration = new CompositeConfiguration(); PropertiesConfiguration defaults = null; try {//from w w w . j a v a2s. co m logger.info("Attempting to create PropertiesConfiguration object for DEFAULT_CONFIG"); defaults = new PropertiesConfiguration(defaultConfig); logger.info("Loading default configuration from " + defaultConfig); defaults.load(); } catch (ConfigurationException e) { logger.error("Could not load default configuration from " + defaultConfig); logger.error(e); } if (overrideConfig != null) { PropertiesConfiguration overrides = null; try { logger.info("Attempting to create PropertiesConfiguration object for OVERRIDE_CONFIG"); overrides = new PropertiesConfiguration(); logger.info("Setting file for OVERRIDE_CONFIG"); overrides.setFile(new File(overrideConfig)); logger.info("Setting reload strategy for OVERRIDE_CONFIG"); overrides.setReloadingStrategy(new FileChangedReloadingStrategy()); logger.info("Loading OVERRIDE_CONFIG"); overrides.load(); } catch (ConfigurationException e) { logger.error("Could not load overrides", e); } catch (Exception ex) { logger.error(ex); } if (overrides != null) { compositeConfiguration.addConfiguration(overrides); } } // Afterwards, add defaults so they're read second. compositeConfiguration.addConfiguration(defaults); } }
From source file:com.yahoo.flowetl.services.factory.ServiceFactory.java
/** * Parses the config file and returns a configuration object for it. It * attempts to look at the extension of the file and then create the * corresponding apache commons configuration reader for that file type. * Currently this is supporting a .xml file and a .properties file. * /*from w w w. j a v a 2s .c o m*/ * @param configFileName * * @return the configuration * * @throws ConfigurationException */ protected Configuration parseConfigFile(String configFileName) throws ConfigurationException { if (configFileName == null) { return null; } Configuration out = null; String ext = FilenameUtils.getExtension(configFileName); if (StringUtils.equalsIgnoreCase("xml", ext)) { out = new XMLConfiguration(configFileName); } else if (StringUtils.equalsIgnoreCase("properties", ext)) { out = new PropertiesConfiguration(configFileName); } return out; }
From source file:com.torodb.BuildProperties.java
BuildProperties(String propertiesFile) { PropertiesConfiguration properties;/*from w ww. j ava 2s . c o m*/ try { properties = new PropertiesConfiguration(Resources.getResource(propertiesFile)); } catch (ConfigurationException e) { throw new RuntimeException("Cannot read build properties file '" + propertiesFile + "'"); } fullVersion = properties.getString("version"); Matcher matcher = FULL_VERSION_PATTERN.matcher(fullVersion); if (!matcher.matches()) { throw new RuntimeException("Invalid version string '" + fullVersion + "'"); } majorVersion = Integer.parseInt(matcher.group(1)); minorVersion = Integer.parseInt(matcher.group(2)); subVersion = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : 0; extraVersion = matcher.group(4); // DateUtils.parseDate may be replaced by SimpleDateFormat if using Java7 try { buildTime = DateUtils.parseDate(properties.getString("build.timestamp"), new String[] { ISO8601_FORMAT_STRING }); } catch (ParseException e) { throw new RuntimeException("build.timestamp property not in ISO8601 format"); } gitCommitId = properties.getString("git.commit.id"); gitBranch = properties.getString("git.branch"); gitRemoteOriginUrl = properties.getString("git.remote.origin.url"); javaVersion = properties.getString("java.version"); javaVendor = properties.getString("java.vendor"); javaVMSpecificationVersion = properties.getString("java.vm.specification.version"); javaVMVersion = properties.getString("java.vm.version"); osName = properties.getString("os.name"); osArch = properties.getString("os.arch"); osVersion = properties.getString("os.version"); }
From source file:com.manydesigns.elements.ElementsProperties.java
public static void addConfiguration(String resource) { try {//from www . j av a2s . c om configuration.addConfiguration(new PropertiesConfiguration(resource)); } catch (Throwable e) { logger.warn(String.format("Error loading properties from: %s", resource), e); } }
From source file:com.jaspersoft.buildomatic.crypto.MasterPropertiesObfuscator.java
@Override public void execute() throws BuildException { try {/*from ww w . j av a2s . c om*/ //load master props PropertiesConfiguration config = new PropertiesConfiguration(new File(propsFile)); PropertiesConfigurationLayout configLayout = config.getLayout(); configLayout.setGlobalSeparator("="); Boolean encFlag = Boolean.parseBoolean(config.getString(ENCRYPT_FLAG)); Boolean encDoneFlag = Boolean.parseBoolean(config.getString(ENCRYPT_DONE_FLAG)); if (encFlag && !encDoneFlag) { String blockSzStr = config.getString(CRYPTO_BLOCK_SIZE_PARAM); EncryptionProperties encProps = new EncryptionProperties( blockSzStr != null ? Integer.parseInt(blockSzStr) : null, config.getString(CRYPTO_TRANSFORMATION_PARAM)); List<Object> propsToEncryptList = config.getList(PROPS_TO_ENCRYPT_PARAM, Arrays.<Object>asList(PROPS_TO_ENCRYPT_DEF)); log("Encrypt " + StringUtils.join(propsToEncryptList.toArray(), ','), Project.MSG_INFO); log("Encryption block size: " + encProps.getBlockSize(), Project.MSG_DEBUG); log("Encryption mode: " + encProps.getCipherTransformation(), Project.MSG_DEBUG); //obtain Keystore Manager KeystoreManager.init(this.ksp); KeystoreManager ksManager = KeystoreManager.getInstance(); //obtain key Key secret = ksManager.getBuildKey(); Set<String> paramSet = new HashSet<String>(propsToEncryptList.size()); for (Object prop : propsToEncryptList) { String propNameToEnc = prop.toString().trim(); if (paramSet.contains(propNameToEnc)) continue; //was already encrypted once paramSet.add(propNameToEnc); String pVal = config.getString(propNameToEnc); if (pVal != null) { if (EncryptionEngine.isEncrypted(pVal)) log("encrypt=true was set, but param " + propNameToEnc + " was found already encrypted. " + " Skipping its encryption.", Project.MSG_WARN); else { String ct = EncryptionEngine.encrypt(secret, pVal, encProps); config.setProperty(propNameToEnc, ct); } } } //set encryption to done config.clearProperty(ENCRYPT_FLAG); config.setProperty(ENCRYPT_DONE_FLAG, "true"); //write master props back config.save(); } else if (encDoneFlag) { log("The master properties have already been encrypted. To re-enable the encryption, " + "make sure the passwords are in plain text, set master property " + "encrypt to true and remove encrypt.done.", Project.MSG_INFO); } } catch (Exception e) { throw new BuildException(e, getLocation()); } }
From source file:eu.optimis.mi.monitoring_manager.test.MonitoringManagerTest.java
public MonitoringManagerTest() { try {/*from ww w . j a va2 s.co m*/ PropertiesConfiguration config = new PropertiesConfiguration( MonitoringManagerTest.class.getClassLoader().getResource(RESOURCE_FILE)); AGGREGATOR_URL = config.getString("aggregator.url"); MMANAGER_URL = config.getString("mmanager.url"); DB_DRIVER = config.getString("db.driver"); TABLE_URL = config.getString("db.table.url"); DB_USER = config.getString("db.username"); DB_PASSWORD = config.getString("db.password"); } catch (Exception e) { System.err.println("Error: cannot find the resource bundle path."); throw new RuntimeException(e); } //{from}.{to} MMANAGER_PATH_PHYSICAL = "QueryResources/date/type/physical"; MMANAGER_PATH_VIRTUAL = "QueryResources/date/type/virtual"; }
From source file:edu.lternet.pasta.portal.ConfigurationListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); // Create an absolute path for accessing configuration properties String cwd = servletContext.getRealPath("."); // Initialize log4j String log4jPropertiesPath = cwd + "/WEB-INF/conf/log4j.properties"; PropertyConfigurator.configureAndWatch(log4jPropertiesPath); // Initialize commons configuration String appConfigPath = cwd + "/WEB-INF/conf/dataportal.properties"; try {//from ww w. j ava 2s .c om config = new PropertiesConfiguration(appConfigPath); config.setProperty("system.cwd", cwd); config.save(); } catch (ConfigurationException e) { logger.error(e); e.printStackTrace(); } }
From source file:fr.jetoile.hadoopunit.component.HiveServer2Bootstrap.java
private void loadConfig() throws BootstrapException { HadoopUtils.setHadoopHome();/* w ww .j av a2 s . co m*/ try { configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } host = configuration.getString(HadoopUnitConfig.HIVE_SERVER2_HOSTNAME_KEY); port = configuration.getInt(HadoopUnitConfig.HIVE_SERVER2_PORT_KEY); hostMetastore = configuration.getString(HadoopUnitConfig.HIVE_METASTORE_HOSTNAME_KEY); portMetastore = configuration.getInt(HadoopUnitConfig.HIVE_METASTORE_PORT_KEY); derbyDirectory = configuration.getString(HadoopUnitConfig.HIVE_METASTORE_DERBY_DB_DIR_KEY); scratchDirectory = configuration.getString(HadoopUnitConfig.HIVE_SCRATCH_DIR_KEY); warehouseDirectory = configuration.getString(HadoopUnitConfig.HIVE_WAREHOUSE_DIR_KEY); zookeeperConnectionString = configuration.getString(HadoopUnitConfig.ZOOKEEPER_HOST_KEY) + ":" + configuration.getInt(HadoopUnitConfig.ZOOKEEPER_PORT_KEY); }