List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:fr.inria.atlanmod.neoemf.data.blueprints.neo4j.option.BlueprintsNeo4jResourceSaveTest.java
@Test public void testSaveGraphNeo4jResourceNoneCacheTypeOption() throws IOException, ConfigurationException { Map<String, Object> options = BlueprintsNeo4jOptionsBuilder.newBuilder().noCache().asMap(); resource.save(options);//from www. j a v a 2 s.com File configFile = new File(file() + configFileName); assertThat(configFile).exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assertConfigurationHasEntry(configuration, BlueprintsNeo4jResourceOptions.CACHE_TYPE, BlueprintsNeo4jResourceOptions.CacheType.NONE.toString()); assertConfigurationHasSize(configuration, 1); }
From source file:fr.jetoile.hadoopunit.component.HBaseBootstrap.java
private void loadConfig() throws BootstrapException { HadoopUtils.setHadoopHome();//from w w w .j ava 2s.c om try { configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } port = configuration.getInt(HadoopUnitConfig.HBASE_MASTER_PORT_KEY); infoPort = configuration.getInt(HadoopUnitConfig.HBASE_MASTER_INFO_PORT_KEY); nbRegionServer = configuration.getInt(HadoopUnitConfig.HBASE_NUM_REGION_SERVERS_KEY); rootDirectory = configuration.getString(HadoopUnitConfig.HBASE_ROOT_DIR_KEY); zookeeperConnectionString = configuration.getString(HadoopUnitConfig.ZOOKEEPER_HOST_KEY) + ":" + configuration.getInt(HadoopUnitConfig.ZOOKEEPER_PORT_KEY); zookeeperPort = configuration.getInt(HadoopUnitConfig.ZOOKEEPER_PORT_KEY); zookeeperZnodeParent = configuration.getString(HadoopUnitConfig.HBASE_ZNODE_PARENT_KEY); enableWalReplication = configuration.getBoolean(HadoopUnitConfig.HBASE_WAL_REPLICATION_ENABLED_KEY); }
From source file:edu.umich.its.google.oauth.GoogleServiceAccount.java
static private void initProperties() { String propertiesFilePath = System.getProperty(SYSTEM_PROPERTY_FILE_PATH); File in = null;//from w w w . j a v a 2 s . c om try { // loads the file from the tomcat directory if (!isEmpty(propertiesFilePath)) { in = new File(propertiesFilePath); } else { // loads the file from inside of the war String packagePath = GoogleServiceAccount.class.getPackage().getName().replace(".", File.separator); in = new File(GoogleServiceAccount.class.getClassLoader() .getResource(packagePath + File.separator + SYSTEM_PROPERTY_FILE_DEFAULT_NAME).toURI()); } if (in != null) { config = new PropertiesConfiguration(in); config.setReloadingStrategy(new FileChangedReloadingStrategy()); } } catch (Exception err) { M_log.error("Failed to load system properties(googleServiceProps.properties) for GoogleServiceAccount", err); } finally { } }
From source file:de.chaosfisch.uploader.UploaderModule.java
@Override protected void configure() { bind(String.class).annotatedWith(Names.named(IPersistenceService.PERSISTENCE_FOLDER)) .toInstance(String.format("%s/%s", ApplicationData.DATA_DIR, ApplicationData.VERSION)); try {//from ww w .j a v a2 s. c om final String configFile = ApplicationData.DATA_DIR + "/config.properties"; if (!Files.exists(Paths.get(configFile))) { Files.createFile(Paths.get(configFile)); } final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(configFile); propertiesConfiguration.setAutoSave(true); bind(Configuration.class).toInstance(propertiesConfiguration); } catch (IOException | ConfigurationException e) { throw new RuntimeException(e); } install(new PersistenceModule()); install(new GoogleModule()); final Multibinder<UploadPreProcessor> preProcessorMultibinder = Multibinder.newSetBinder(binder(), UploadPreProcessor.class); preProcessorMultibinder.addBinding().to(PlaceholderPreProcessor.class); final Multibinder<UploadPostProcessor> uploadPostProcessorMultibinder = Multibinder.newSetBinder(binder(), UploadPostProcessor.class); uploadPostProcessorMultibinder.addBinding().to(ExportPostProcessor.class); bind(ResourceBundle.class).annotatedWith(Names.named("i18n-resources")) .toInstance(ResourceBundle.getBundle("de.chaosfisch.uploader.resources.application")); mapServices(); mapUtil(); }
From source file:net.elsched.utils.SettingsBinder.java
/** * Bind configuration parameters into Guice Module. * /*from w ww .j a va2 s . c o m*/ * @return a Guice module configured with setting support. * @throws ConfigurationException * on configuration error */ public static Module bindSettings(String propertiesFileKey, Class<?>... settingsArg) throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); String propertyFile = config.getString(propertiesFileKey); if (propertyFile != null) { config.addConfiguration(new PropertiesConfiguration(propertyFile)); } List<Field> fields = new ArrayList<Field>(); for (Class<?> settings : settingsArg) { fields.addAll(Arrays.asList(settings.getDeclaredFields())); } // Reflect on settings class and absorb settings final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>(); for (Field field : fields) { if (!field.isAnnotationPresent(Setting.class)) { continue; } // Validate target type SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType()); if (typeHelper == null || !typeHelper.check(field.getGenericType())) { throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types"); } Setting setting = field.getAnnotation(Setting.class); settings.put(setting, field); } // Now validate them List<String> missingProperties = new ArrayList<String>(); for (Setting setting : settings.keySet()) { if (setting.defaultValue().isEmpty()) { if (!config.containsKey(setting.name())) { missingProperties.add(setting.name()); } } } if (missingProperties.size() > 0) { StringBuilder error = new StringBuilder(); error.append("The following required properties are missing from the server configuration: "); error.append(Joiner.on(", ").join(missingProperties)); } // bundle everything up in an injectable guice module return new AbstractModule() { @Override protected void configure() { // We must iterate the settings a third time when binding. // Note: do not collapse these loops as that will damage // early error detection. The runtime is still O(n) in setting // count. for (Map.Entry<Setting, Field> entry : settings.entrySet()) { Class<?> type = entry.getValue().getType(); Setting setting = entry.getKey(); if (int.class.equals(type)) { Integer defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Integer.parseInt(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getInteger(setting.name(), defaultValue)); } else if (boolean.class.equals(type)) { Boolean defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Boolean.parseBoolean(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getBoolean(setting.name(), defaultValue)); } else if (String.class.equals(type)) { bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getString(setting.name(), setting.defaultValue())); } else { String[] value = config.getStringArray(setting.name()); if (value.length == 0 && !setting.defaultValue().isEmpty()) { value = setting.defaultValue().split(","); } bind(new TypeLiteral<List<String>>() { }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value)); } } } }; }
From source file:eu.optimis_project.monitoring.config.ConfigurationManager.java
/** * Load configuration file as specified in the system property, and fall * back on the default file if required. */// w w w. j a v a 2 s . c o m private void loadConfigurationFile(String defaultConfigFilePath, String defaultConfigFileName) throws ConfigurationException { String configFilePath = System.getProperty("configuration.file.path"); String configFileName = System.getProperty("configuration.file.name"); String filePath = configFilePath == null ? defaultConfigFilePath : configFilePath; String fileName = configFileName == null ? defaultConfigFileName : configFileName; URL configURL; if (!filePath.endsWith(File.separator)) { filePath += File.separatorChar; } // Check if the file exists on the system, else try reading it from the // classpath File configFile = new File(filePath + fileName); if (configFile.exists()) { try { configURL = new URL(filePath + fileName); } catch (MalformedURLException e) { throw new ConfigurationException(e); } } else { configURL = this.getClass().getClassLoader().getResource(fileName); } PropertiesConfiguration config = null; try { config = new PropertiesConfiguration(configURL); } catch (ConfigurationException e) { if (defaultConfigFileName.equals(configFileName) && configFilePath.equals(defaultConfigFilePath)) { log.fatal("Could not find default configuration file: '" + configURL + "'", e); throw e; } else { // Try default file too try { config = new PropertiesConfiguration(defaultConfigFilePath); } catch (ConfigurationException e2) { log.warn("Could not find default file, trying same dir"); } // Try file in same dir if (config == null) { String sameDirPath = System.getProperty("user.dir") + File.separatorChar + defaultConfigFileName; try { config = new PropertiesConfiguration(sameDirPath); log.info("Using file in same directory:" + sameDirPath); } catch (ConfigurationException e2) { log.fatal("Could not find specified " + "configuration file: '" + configFilePath + File.separatorChar + configFileName + "', could not find default " + "configuration file: '" + defaultConfigFilePath + File.separatorChar + defaultConfigFileName + "', and could not find file in same dir: " + sameDirPath + "'", e2); throw e2; } } log.warn("Could not find specified " + "configuration file: '" + configFilePath + File.separatorChar + configFileName + "', using default configuration at : '" + defaultConfigFilePath + File.separatorChar + defaultConfigFileName + "'"); } } config.setThrowExceptionOnMissing(true); this.configuration = config; }
From source file:fr.jetoile.hadoopunit.component.SolrCloudBootstrap.java
private void loadConfig() throws BootstrapException { HadoopUtils.setHadoopHome();// ww w . j a va 2s.com try { configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } solrDirectory = configuration.getString(SOLR_DIR_KEY); solrCollectionName = configuration.getString(SOLR_COLLECTION_NAME); solrPort = configuration.getInt(SOLR_PORT); zkHostString = configuration.getString(HadoopUnitConfig.ZOOKEEPER_HOST_KEY) + ":" + configuration.getInt(HadoopUnitConfig.ZOOKEEPER_PORT_KEY); }
From source file:fr.inria.atlanmod.neoemf.data.blueprints.option.BlueprintsResourceSaveTest.java
@Test public void testSaveGraphResourceDefaultGraphTypeOption() throws IOException, ConfigurationException { resource.save(BlueprintsOptionsBuilder.newBuilder().asMap()); File configFile = new File(file() + configFileName); assertThat(configFile).exists(); // "Config file does not exist" PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assertThat(configuration.containsKey(BlueprintsResourceOptions.GRAPH_TYPE)).isTrue(); assertThat(configuration.getString(BlueprintsResourceOptions.GRAPH_TYPE)) .isEqualTo(BlueprintsResourceOptions.GRAPH_TYPE_DEFAULT); assertThat(getKeyCount(configuration)).isEqualTo(3); // "Too much content in the .properties file" }
From source file:com.opensoc.test.AbstractConfigTest.java
protected void setUp(String configName) throws Exception { super.setUp(); this.setConfigPath("src/test/resources/config/" + getClass().getSimpleName() + ".config"); try {/*from w w w . j ava2s . c o m*/ this.setConfig(new PropertiesConfiguration(this.getConfigPath())); Map configOptions = SettingsLoader.getConfigOptions((PropertiesConfiguration) this.config, configName + "="); this.setSettings( SettingsLoader.getConfigOptions((PropertiesConfiguration) this.config, configName + ".")); this.getSettings().put(configName, (String) configOptions.get(configName)); } catch (ConfigurationException e) { fail("Config not found !!" + e); e.printStackTrace(); } }
From source file:fr.inria.atlanmod.neoemf.map.datastore.MapPersistenceBackendFactory.java
@Override public PersistenceBackend createPersistentBackend(File file, Map<?, ?> options) throws InvalidDataStoreException { File dbFile = FileUtils.getFile( NeoMapURI.createNeoMapURI(URI.createFileURI(file.getAbsolutePath()).appendSegment("neoemf.mapdb")) .toFileString());/*from ww w. j av a2 s .c o m*/ if (!dbFile.getParentFile().exists()) { dbFile.getParentFile().mkdirs(); } PropertiesConfiguration neoConfig = null; Path neoConfigPath = Paths.get(file.getAbsolutePath()).resolve(NEO_CONFIG_FILE); try { neoConfig = new PropertiesConfiguration(neoConfigPath.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!neoConfig.containsKey(BACKEND_PROPERTY)) { neoConfig.setProperty(BACKEND_PROPERTY, MAPDB_BACKEND); } if (neoConfig != null) { try { neoConfig.save(); } catch (ConfigurationException e) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } Engine mapEngine = DBMaker.newFileDB(dbFile).cacheLRUEnable().mmapFileEnableIfSupported().asyncWriteEnable() .makeEngine(); return new MapPersistenceBackend(mapEngine); }