private void loadConfigurationManager() { log.trace(() -> "Initializing configuration cache."); @NotNull Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName(PROPERTIES_FILE)); try { this.config = builder.getConfiguration(); } catch (ConfigurationException e) { log.fatal(e); throw new RuntimeException("Couldnt load configuration file " + PROPERTIES_FILE); } }
/** * Save property for standalone profile. * * @param pair the pair */ public void savePropertyForStandaloneProfile(final Pair<String, String> pair) { try { final File file = getStandaloneProfileConfigurationDirectory(); final Parameters params = new Parameters(); final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(file, getApplicationName() + ".properties"))); final Configuration config = builder.getConfiguration(); config.setProperty(pair.getKey(), pair.getValue()); builder.save(); } catch (final Exception e) { throw Throwables.propagate(e); } }
private static FileBasedConfiguration createPropertiesConfiguration(Reader reader) throws ConfigurationException, IOException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters() .properties() .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); FileBasedConfiguration config = builder.getConfiguration(); config.read(reader); return config; }
@Override public void showBoard() { File paramFile = new File("config/mainboardfx.properties"); try { final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class) .configure( new FileBasedBuilderParametersImpl().setFile(paramFile).setEncoding("utf8")); cfg = builder.getConfiguration(); } catch (ConfigurationException ex) { QLog.l().logger() .error("Не загружен файл конфигурации " + paramFile.getAbsolutePath(), ex); throw new ServerException( "Не загружен файл конфигурации " + paramFile.getAbsolutePath()); } super.showBoard(); }
/** * Instantiates a new config. */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("nlp.properties") .setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); // Adding TEKSTO_HOME path to Configuration String homePath = System.getenv(TEKSTO_HOME); if (homePath != null && !homePath.isEmpty()) { configuration.setProperty(MODEL_PATH, homePath + "/Models"); } } catch (ConfigurationException e) { LOG.error(e, e); } }
/** * Builds the Configuration object from the properties file (apache commons * properties file format). <br> * The values provided in the config file will be overwritten environment * variables (if present) * * List of the properties <br> * loginsight.host = host name <br> * loginsight.port = port number <br> * loginsight.user = User name <br> * loginsight.password = password <br> * loginsight.ingestion.agentId = agentId <br> * loginsight.connection.scheme = http protocol scheme <br> * loginsight.ingestion.port = Ingestion port number <br> * * @param configFileName * Name of the config file to read * @return Newly created Configuration object */ public static Configuration buildFromConfig(String configFileName) { try { List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(), new FileSystemLocationStrategy(), new ClasspathLocationStrategy()); FileLocationStrategy strategy = new CombinedLocationStrategy(subs); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>( PropertiesConfiguration.class).configure( new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName)); PropertiesConfiguration propConfig = builder.getConfiguration(); Map<String, String> propMap = new HashMap<String, String>(); Iterator<String> keys = propConfig.getKeys(); keys.forEachRemaining(key -> { logger.info(key + ":" + propConfig.getString(key)); propMap.put(key, propConfig.getString(key)); }); Configuration config = Configuration.buildConfig(propMap); config.loadFromEnv(); return config; } catch (ConfigurationException e1) { throw new RuntimeException("Unable to load config", e1); } }
@Test public void testOverride() { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName("file.properties")); Configuration config = null; try { config = builder.getConfiguration(); config.setProperty("somekey", "somevalue"); builder.save(); } catch (ConfigurationException e) { e.printStackTrace(); } }
/** * Applies the specified function to the specified set of parameters contained in the input file. * * @param input The specified name of file to encrypt * @param mustBeModified the specified set of parameters * @param function the specified function to apply to the set of specified parameters */ private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) { Path inputFilePath = Paths.get(input); if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = // new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) // .configure(params.fileBased() // .setFile(inputFilePath.toFile())); // PropertiesConfiguration config = builder.getConfiguration(); mustBeModified.stream().filter(config::containsKey) .forEach(key -> config.setProperty(key, function.apply(config.getString(key)))); builder.save(); } catch (ConfigurationException e) { LOGGER.error("unable to read {} {}", input, e); } } else { LOGGER.debug("No readable file at {}", input); } }
private AliceRecognition() { try { CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner()); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration()); this.enabled = config.getBoolean(ALICE_ENABLED, false); String url = config.getString(ALICE_SERVICE_URL, null); String accessToken = config.getString(ALICE_ACCESS_TOKEN, null); String command = config.getString(ALICE_COMMAND, null); if(enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) { this.client = new AliceClient(url, command); this.client.setAuthToken(accessToken); this.enabled = this.client.isAvailable(); } } catch (Exception e) { LOGGER.error("Unable to initialize Alice: " + e.getMessage()); } }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getHotkeysFile())); config = builder.getConfiguration(); loadHotkeys(); }
public static void init(String worldLocation) throws ConfigurationException { log.debug("World Location for properties: " + worldLocation); configManager = new Configurations(); if(worldLocation == null){ builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(defaultWorldPropertiesLocation)); }else { builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName(worldLocation)); } config = builder.getConfiguration(); }
public static void init() throws ConfigurationException { configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getAppPropFile())); config = builder.getConfiguration(); }
public static void firstInit() throws Exception{ configManager = new Configurations(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(configManager.getParameters().fileBased().setFileName("src/main/resources/app.properties")); config = builder.getConfiguration(); }
private ConfigurationManager() throws ConfigurationException{ FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFileName(configFilePath) .setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); config = builder.getConfiguration(); }
private static PropertiesConfiguration getPropertiesConfiguration(final String fileName) throws ConfigurationException { val propertiesPath = ofNullable(ClassLoader.getSystemClassLoader().getResource(fileName)) .map(URL::getFile) .orElseThrow(IllegalArgumentException::new); return new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters().properties().setFile(new File(propertiesPath))) .getConfiguration(); }
private Config() { // https://issues.apache.org/jira/browse/CONFIGURATION-677 /*BuilderParameters params = new Parameters().properties() .setFileName(CONFIG_NAME) .setLocationStrategy(new HomeDirectoryLocationStrategy()) .setEncoding("UTF-8");*/ // workaround: HomeDirectoryLocationStrategy location = new HomeDirectoryLocationStrategy(); File configFile = new File(location.getHomeDirectory(), CONFIG_NAME); BuilderParameters params = new Parameters().properties() .setFile(configFile) .setEncoding("UTF-8"); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class, params.getParameters(), true); builder.setAutoSave(true); try { config = builder.getConfiguration(); logger.info("User configuration has been loaded from: {}", configFile); } catch(ConfigurationException cex) { logger.error("Error loading configuration", cex); throw new IllegalStateException("Error loading/creating configuration"); } }
/** * Instantiates a new config. */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("pdf2xml.properties").setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); } catch (ConfigurationException e) { LOG.error(e, e); } }
private Configuration getHeapSpankJarConfiguration() throws ConfigurationException { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName(PROPERTIES_FILE) .setLocationStrategy(new ClasspathLocationStrategy()) ); Configuration config = builder.getConfiguration(); return config; }
private Configuration getHomeFolderConfiguration() throws ConfigurationException { File homeDir = new File( System.getProperty("user.home")); File heapSpankProperties = new File(homeDir, this.PROPERTIES_FILE); Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFile(heapSpankProperties)); return builder.getConfiguration(); }
private Configuration getCurrentFolderConfiguration() throws ConfigurationException { URL location = ApacheCommonsConfigFile.class.getProtectionDomain().getCodeSource().getLocation(); File heapSpankjarFile = new File(location.getFile()); File dirOfHeapSpankjarFile = new File(location.getFile()).getParentFile(); File heapSpankProperties = new File(dirOfHeapSpankjarFile, this.PROPERTIES_FILE); Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFile(heapSpankProperties)); return builder.getConfiguration(); }
public ImportCommandGenerator() { PropertiesConfiguration config = PropertiesHolder.getInstance(); this.inputFolderPath = config.getString("output.folder"); this.outputFolderPath = config.getString("output.folder") + File.separator + "graph-db" + File.separator + "data" + File.separator +"databases" + File.separator + "graph.db"; this.neoTypeToManualFiles = getNeoTypeToManualFiles(config); }
private Multimap<String, String> getNeoTypeToManualFiles(PropertiesConfiguration config) { Multimap<String,String> result = HashMultimap.create(); Iterator<String> keys = config.getKeys("manualUpload"); while (keys.hasNext()) { String key = keys.next(); String propertyValue = config.getString(key); if (StringUtils.isNotEmpty(propertyValue)) { String[] split = propertyValue.split(COMMA); for (String s : split) { result.put(StringUtils.remove(key, "manualUpload."), s); } } } return result; }
public static void main(String[] args) throws IOException { PropertiesConfiguration config = PropertiesHolder.getInstance(); String outputFolderPath = config.getString("output.folder"); File storeDir = new File(outputFolderPath + File.separator + "graph-db"); ServerBootstrapper serverBootstrapper = new CommunityBootstrapper(); serverBootstrapper.start( storeDir, Optional.empty(), // omit configfile, properties follow Pair.of("dbms.connector.http.address","127.0.0.1:7474"), Pair.of("dbms.connector.http.enabled", "true"), Pair.of("dbms.connector.bolt.enabled", "true"), // allow the shell connections via port 1337 (default) Pair.of("dbms.shell.enabled", "true"), Pair.of("dbms.shell.host", "127.0.0.1"), Pair.of("dbms.shell.port", "1337"), Pair.of("dbms.security.auth_enabled", "false") ); // ^^ serverBootstrapper.start() also registered shutdown hook! NeoServer neoServer = serverBootstrapper.getServer(); System.out.println("Press ENTER to quit."); System.in.read(); neoServer.stop(); }
/** * Returns a HashMap of the default values * @return */ public static PropertiesConfiguration getDefaults(){ PropertiesConfiguration default_configuration = null; try { default_configuration = getDefaultParametersBuilder().getConfiguration(); } catch (ConfigurationException e) { AptaLogger.log(Level.SEVERE, Configuration.class, e); e.printStackTrace(); } return default_configuration; }
/** * Stores properties which can not be modified from UI to config file, * changes in config file will be applied after system restart */ private void storePropertiesEditableFromConfigFile(String retentionCronExpression, int pollingRate, int waitTimeBeforeNewSync, int maxWaitTimeToDetachVolume) { File file = Paths.get(System.getProperty(catalinaHomeEnvPropName), confFolderName, propFileName).toFile(); try { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout(); layout.setLineSeparator("\n"); String headerComment = "EnhancedSnapshots properties. Changes in this config file will be applied after application restart."; layout.setHeaderComment(headerComment); layout.setBlancLinesBefore(RETENTION_CRON_SCHEDULE, 1); layout.setComment(RETENTION_CRON_SCHEDULE, "Cron schedule for retention policy"); propertiesConfiguration.setProperty(RETENTION_CRON_SCHEDULE, retentionCronExpression); layout.setBlancLinesBefore(WORKER_POLLING_RATE, 1); layout.setComment(WORKER_POLLING_RATE, "Polling rate to check whether there is some new task, in ms"); propertiesConfiguration.setProperty(WORKER_POLLING_RATE, Integer.toString(pollingRate)); layout.setBlancLinesBefore(WAIT_TIME_BEFORE_NEXT_CHECK_IN_SECONDS, 1); layout.setComment(WAIT_TIME_BEFORE_NEXT_CHECK_IN_SECONDS, "Wait time before new sync of Snapshot/Volume with AWS data, in seconds"); propertiesConfiguration.setProperty(WAIT_TIME_BEFORE_NEXT_CHECK_IN_SECONDS, Integer.toString(waitTimeBeforeNewSync)); layout.setBlancLinesBefore(MAX_WAIT_TIME_VOLUME_TO_DETACH_IN_SECONDS, 1); layout.setComment(MAX_WAIT_TIME_VOLUME_TO_DETACH_IN_SECONDS, "Max wait time for volume to be detached, in seconds"); propertiesConfiguration.setProperty(MAX_WAIT_TIME_VOLUME_TO_DETACH_IN_SECONDS, Integer.toString(maxWaitTimeToDetachVolume)); propertiesConfiguration.write(new FileWriter(file)); LOG.debug("Config file {} stored successfully.", file.getPath()); } catch (Exception ioException) { LOG.error("Can not create property file", ioException); throw new ConfigurationException("Can not create property file. Check path or permission: " + file.getAbsolutePath(), ioException); } }
private ApplicationConfig() { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class) .configure(params.properties() .setFileName("application.properties")); try { config = builder.getConfiguration(); } catch (ConfigurationException e) { logger.error("failed to load application.properties: {}", e, e.getMessage()); } }
@Test public void compileTest() throws IOException, ClassNotFoundException { CompilationTask compilationTask; PropertiesConfiguration config = compileProperties(compilePropertiesFile); CompilationTaskBuilder taskBuilder = newBuilder(config); DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>(); // Add the implicit/standard configuration to this test compilation task. taskBuilder.addProc(new RoundZeroProcessor()) .addProc(new RoundOneProcessor()) .setDiagnosticListener(diagnosticCollector) .getFileManagerConfig().addToSourcePath(SOURCES_DIR) .addToClassPath(PANINI_PROC_CLASSES_DIR) .addToClassPath(PANINI_RUNTIME_CLASSES_DIR) .setSourceOutputDir(sourceOutputDir()) .setClassOutputDir(classOutputDir()); // Make sure that the output directories exist. sourceOutputDir().mkdirs(); classOutputDir().mkdirs(); // Build the compilation task itself. compilationTask = taskBuilder.build(); compilationTask.call(); boolean hasActualErrors = diagnosticCollector.getDiagnostics().stream() .map(Diagnostic::getKind) .anyMatch(k -> k == ERROR); assertEquals("Compilation error diagnostics?", isExpectingErrors(config), hasActualErrors); }
private boolean isExpectingErrors(PropertiesConfiguration config) { String value = config.getString("errors", "no").toLowerCase().trim(); if (value.equals("yes")) { return true; } else if (value.equals("no")) { return false; } else { String msg = format("`errors` property in {0} set to an unexpected value: {1}", compilePropertiesFile.getPath(), value); throw new RuntimeException(msg); } }
private void checkRole(String user, File roleFile, String... roles) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile); PropertiesConfiguration roleConfig = roleBuilder.getConfiguration(); for (String r : roles) { String storedUsers = (String) roleConfig.getProperty(r); System.out.println("users in role: " + r + " ; " + storedUsers); List<String> userList = StringUtil.splitStringList(storedUsers, ","); assertTrue(userList.contains(user)); } }
private boolean checkPassword(String user, String password, File userFile) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> userBuilder = configs.propertiesBuilder(userFile); PropertiesConfiguration userConfig = userBuilder.getConfiguration(); String storedPassword = (String) userConfig.getProperty(user); HashProcessor processor = PasswordMaskingUtil.getHashProcessor(storedPassword); return processor.compare(password.toCharArray(), storedPassword); }
private SolverFactory() { Configuration configuration = null; try { String baseDir = System.getProperty("user.dir"); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFileName(String.format("%s%s%s", baseDir, File.separator, PROPERTY_FILE))); configuration = builder.getConfiguration(); } catch (Exception ce) { //log.error("There went something wrong while reading the clingo configuration. Using Default configruation.", ce); } if (configuration!=null) { clingoParameters = getClingoParameters(configuration); clingoExec = configuration.getString("clingo.exec", "clingo.exe"); } else { //defaults if (OsUtils.isUnix()) clingoExec = "clingo"; else if (OsUtils.isWindows()) clingoExec = "clingo.exe"; clingoParameters = new String[] {"--warn=no-atom-undefined", "--quiet=0,2,2", "--verbose=0", "--project"}; } }
private static void mergeExtraOptions(PropertiesConfiguration baseOptions, PropertiesConfiguration extraOptions) { if (isNull(extraOptions) || extraOptions.size() == 0) { return; } trace("loadOptions: have to merge extra Options"); Iterator<String> allKeys = extraOptions.getKeys(); while (allKeys.hasNext()) { String key = allKeys.next(); if ("sxversion".equals(key)) { baseOptions.setProperty("sxversion_saved", extraOptions.getProperty(key)); continue; } if ("sxbuild".equals(key)) { baseOptions.setProperty("sxbuild_saved", extraOptions.getProperty(key)); continue; } Object value = baseOptions.getProperty(key); if (isNull(value)) { baseOptions.addProperty(key, extraOptions.getProperty(key)); trace("Option added: %s", key); } else { Object extraValue = extraOptions.getProperty(key); if (!value.getClass().getName().equals(extraValue.getClass().getName()) || !value.toString().equals(extraValue.toString())) { baseOptions.setProperty(key, extraValue); trace("Option changed: %s = %s", key, extraValue); } } } }
public Config() { config = new PropertiesConfiguration(); basicConfig(); }
public FilePropertiesConfiguration toConfiguration(String defaultsFile) throws ConfigurationException, IOException { int i = 1; FilePropertiesConfiguration jnlpConf = new FilePropertiesConfiguration(); List jars = getJars(_doc); for (Iterator it = jars.listIterator(); it.hasNext();) { jnlpConf.setProperty("wrapper.java.classpath." + i++, it.next()); } jnlpConf.setProperty("wrapper.base", getCodebase(_doc)); jnlpConf.setProperty("wrapper.java.app.mainclass", getMainClass(_doc)); i = 1; for (Iterator it = getArguments(_doc).listIterator(); it.hasNext();) { jnlpConf.setProperty("wrapper.app.parameter." + i++, it.next()); } i = 1; List props = getResourceProperties(_doc); for (Iterator it = props.listIterator(); it.hasNext();) { jnlpConf.setProperty("wrapper.java.additional." + i++, it.next()); } i = 1; List resources = getResources(_doc); for (Iterator it = resources.listIterator(); it.hasNext();) { jnlpConf.setProperty("wrapper.resource." + i++, it.next()); } if (defaultsFile == null || "".equals(defaultsFile)) return jnlpConf; // jnlpConf.addProperty("include", defaultsFile); if (defaultsFile != null) { PropertiesConfiguration defaultsConf = new PropertiesConfiguration(); FileObject fo = VFSUtils.resolveFile(".", defaultsFile); InputStreamReader in = new InputStreamReader(fo.getContent().getInputStream()); defaultsConf.read(in); in.close(); for (Iterator it = defaultsConf.getKeys(); it.hasNext();) { String key = (String) it.next(); if (jnlpConf.containsKey(key)) System.out.println("configuration conflict: " + key); else jnlpConf.addProperty(key, defaultsConf.getProperty(key)); } } return jnlpConf; }
Configuration() { config = new PropertiesConfiguration(); layout = new PropertiesConfigurationLayout(); }
public HeaderGenerator() { PropertiesConfiguration config = PropertiesHolder.getInstance(); this.outputFolder = config.getString("output.folder"); }
public FileUnion() { PropertiesConfiguration config = PropertiesHolder.getInstance(); this.inputFolder = config.getString("output.folder"); this.outputFolder = config.getString("output.folder"); }
public static PropertiesConfiguration getInstance() { return INSTANCE; }
/** * only used for unit testing -- loads * @param heapSpankPropertiesFile * @throws ConfigurationException * @throws MultiPropertyException */ public ApacheCommonsConfigFile(File heapSpankPropertiesFile) throws ConfigurationException, MultiPropertyException { Configurations configurations = new Configurations(); PropertiesConfiguration config = configurations.properties(heapSpankPropertiesFile); this.compositeConfiguration.addConfiguration( config ); }
/** * Adds the configuration stored on disk to the current set of parameters. The * file <code>fileName</code> must be a valid configuration file as per Javas * <code>Properties</code> class. * * @param fileName */ public static void setConfiguration(String fileName) { try { AptaLogger.log(Level.INFO, Configuration.class, "Reading configuration from file."); builder = new FileBasedConfigurationBuilder<org.apache.commons.configuration2.FileBasedConfiguration>( PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(fileName) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); // Create a composite configuration which allows to keep user parameters and defaults separated CompositeConfiguration cc = new CompositeConfiguration(); cc.addConfiguration(builder.getConfiguration(), true); // changes will be saved in the user config cc.addConfiguration(getDefaultParametersBuilder().getConfiguration(), false); parameters = cc; } catch (Exception e) { AptaLogger.log(Level.SEVERE, Configuration.class, "Error, could not read configuration file. Please check it for correctness"); AptaLogger.log(Level.SEVERE, Configuration.class, e); e.printStackTrace(); } // TODO: Sanity checks! }