List of usage examples for org.apache.commons.configuration CompositeConfiguration getKeys
public Iterator getKeys()
From source file:com.blazebit.jbake.mojo.BuildMojo.java
protected CompositeConfiguration createConfiguration() throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); if (properties != null) { config.addConfiguration(new MapConfiguration(properties)); }//from w ww.j av a 2s . co m config.addConfiguration(new MapConfiguration(project.getProperties())); config.addConfiguration(ConfigUtil.load(inputDirectory)); if (getLog().isDebugEnabled()) { getLog().debug("Configuration:"); Iterator<String> iter = config.getKeys(); while (iter.hasNext()) { String key = iter.next(); getLog().debug(key + ": " + config.getString(key)); } } return config; }
From source file:ffx.utilities.Keyword.java
/** * This method sets up configuration properties in the following precedence * * order://from www . j av a 2 s.c o m * * 1.) Structure specific properties (for example pdbname.properties) * * 2.) Java system properties a.) -Dkey=value from the Java command line b.) * System.setProperty("key","value") within Java code. * * 3.) User specific properties (~/.ffx/ffx.properties) * * 4.) System wide properties (file defined by environment variable * FFX_PROPERTIES) * * 5.) Internal force field definition. * * @since 1.0 * @param file a {@link java.io.File} object. * @return a {@link org.apache.commons.configuration.CompositeConfiguration} * object. */ public static CompositeConfiguration loadProperties(File file) { /** * Command line options take precedence. */ CompositeConfiguration properties = new CompositeConfiguration(); /** * Structure specific options are first. */ if (file != null) { String filename = file.getAbsolutePath(); filename = org.apache.commons.io.FilenameUtils.removeExtension(filename); String propertyFilename = filename + ".properties"; File structurePropFile = new File(propertyFilename); if (structurePropFile.exists() && structurePropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(structurePropFile)); properties.addProperty("propertyFile", structurePropFile.getCanonicalPath()); } catch (ConfigurationException | IOException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } else { propertyFilename = filename + ".key"; structurePropFile = new File(propertyFilename); if (structurePropFile.exists() && structurePropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(structurePropFile)); properties.addProperty("propertyFile", structurePropFile.getCanonicalPath()); } catch (ConfigurationException | IOException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } } } /** * Java system properties * * a.) -Dkey=value from the Java command line * * b.) System.setProperty("key","value") within Java code. */ properties.addConfiguration(new SystemConfiguration()); /** * User specific options are 3rd. */ String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties"; File userPropFile = new File(filename); if (userPropFile.exists() && userPropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(userPropFile)); } catch (ConfigurationException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } /** * System wide options are 2nd to last. */ filename = System.getenv("FFX_PROPERTIES"); if (filename != null) { File systemPropFile = new File(filename); if (systemPropFile.exists() && systemPropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(systemPropFile)); } catch (ConfigurationException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } } /** * Echo the interpolated configuration. */ if (logger.isLoggable(Level.FINE)) { //Configuration config = properties.interpolatedConfiguration(); Iterator<String> i = properties.getKeys(); StringBuilder sb = new StringBuilder(); sb.append(String.format("\n %-30s %s\n", "Property", "Value")); while (i.hasNext()) { String s = i.next(); //sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray()))); sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray()))); } logger.fine(sb.toString()); } return properties; }
From source file:org.apache.accumulo.core.conf.SiteConfiguration.java
@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "location of props is specified by an admin") private static ImmutableMap<String, String> createMap(URL accumuloPropsLocation, Map<String, String> overrides) { CompositeConfiguration config = new CompositeConfiguration(); config.setThrowExceptionOnMissing(false); config.setDelimiterParsingDisabled(true); PropertiesConfiguration propsConfig = new PropertiesConfiguration(); propsConfig.setDelimiterParsingDisabled(true); if (accumuloPropsLocation != null) { try {//from w w w .j a v a 2 s . c o m propsConfig.load(accumuloPropsLocation.openStream()); } catch (IOException | ConfigurationException e) { throw new IllegalArgumentException(e); } } config.addConfiguration(propsConfig); // Add all properties in config file Map<String, String> result = new HashMap<>(); config.getKeys().forEachRemaining(key -> result.put(key, config.getString(key))); // Add all overrides overrides.forEach(result::put); // Add sensitive properties from credential provider (if set) String credProvider = result.get(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey()); if (credProvider != null) { org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration(); hadoopConf.set(CredentialProviderFactoryShim.CREDENTIAL_PROVIDER_PATH, credProvider); for (Property property : Property.values()) { if (property.isSensitive()) { char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, property.getKey()); if (value != null) { result.put(property.getKey(), new String(value)); } } } } return ImmutableMap.copyOf(result); }
From source file:org.ejbca.ui.cli.config.scep.UploadFileCommand.java
private void readConfigurations(CompositeConfiguration config, String alias) { ScepConfiguration scepConfig = getScepConfiguration(); // if the alias does not already exist, create it. scepConfig.addAlias(alias);// w ww.ja v a 2 s . com // Reading all relevant configurations from file. boolean populated = false; Set<String> keys = ScepConfiguration.getAllAliasKeys(alias); @SuppressWarnings("unchecked") Iterator<String> itr = config.getKeys(); while (itr.hasNext()) { String key = itr.next(); String value = config.getString(key); if (StringUtils.contains(key, ScepConfiguration.SCEP_RAMODE_OLD)) { value = StringUtils.equalsIgnoreCase(config.getString(key), "true") ? "ra" : "ca"; key = alias + "." + ScepConfiguration.SCEP_OPERATIONMODE; } if (keys.contains(key)) { populated = true; scepConfig.setValue(key, value, alias); log.info("Setting value: " + key + "=" + value); } } // Save the new configurations. if (populated) { try { getGlobalConfigurationSession().saveConfiguration(getAuthenticationToken(), scepConfig); log.info("\nNew configurations saved successfully."); log.info( "If there are any issues with the configurations, check them in the AdminGUI and click 'Save'"); getGlobalConfigurationSession().flushConfigurationCache(ScepConfiguration.SCEP_CONFIGURATION_ID); } catch (AuthorizationDeniedException e) { log.error("Failed to save configuration from file: " + e.getLocalizedMessage()); } } else { scepConfig.removeAlias(alias); log.info("No relevent CMP configurations found with alias '" + alias + "' in the file."); } }
From source file:org.soaplab.clients.BatchTestClient.java
/************************************************************************* * * Entry point.../* w w w. ja v a 2 s. c om*/ * *************************************************************************/ public static void main(String[] args) { try { BaseCmdLine cmd = getCmdLine(args, BatchTestClient.class); // service location and protocol parameters ServiceLocator mainLocator = InputUtils.getServiceLocator(cmd); // file(s) with the testing data (a list of tested // services and their inputs) String[] batchFiles = null; String batchFile = cmd.getParam("-batchfile"); if (batchFile != null) { // take it from the command-line batchFiles = new String[] { batchFile }; } else { // take it from the client configuration file batchFiles = ClientConfig.get().getStringArray(ClientConfig.PROP_BATCH_TEST_FILE); } if (batchFiles == null || batchFiles.length == 0) { log.error("A file with a list of service to test must be given. " + "Use '-batchfile' or a property '" + ClientConfig.PROP_BATCH_TEST_FILE + "'."); System.exit(1); } // other arguments boolean tableReport = (cmd.hasOption("-table") || ClientConfig.isEnabled(ClientConfig.PROP_BATCH_REPORT_TABLE, false)); boolean keepResults = (cmd.hasOption("-keep") || ClientConfig.isEnabled(ClientConfig.PROP_BATCH_KEEP_RESULTS, false)); int maxThreads = -1; String strMaxThreads = cmd.getParam("-maxthreads"); if (strMaxThreads == null) maxThreads = ClientConfig.getInt(ClientConfig.PROP_BATCH_MAX_THREADS, 25); else maxThreads = getInt(strMaxThreads); if (maxThreads < 0) maxThreads = 0; boolean oneByOne = (maxThreads == 1); // get a list of available services // (for validation purposes later) Set<String> services = new HashSet<String>(); for (String name : new SoaplabBaseClient(mainLocator).getAvailableAnalyses()) { services.add(name); } // loop and do it... List<Properties> reports = Collections.synchronizedList(new ArrayList<Properties>()); List<Thread> threads = Collections.synchronizedList(new ArrayList<Thread>()); int countNotAvailable = 0; title("Progress"); for (String file : batchFiles) { log.info("Using batch file " + file); // treat each batch file as a property configuration // file - together with a usual Soaplab Client // configuration file; this allows handling // substitutions of referenced properties, etc. CompositeConfiguration cfg = new CompositeConfiguration(); cfg.addConfiguration(ClientConfig.get()); cfg.addConfiguration(Config.get()); try { cfg.addConfiguration(new PropertiesConfiguration(file)); } catch (ConfigurationException e) { log.error("Loading batch file from '" + file + "' failed: " + e.getMessage()); continue; } // for (Iterator it = cfg.getKeys(); it.hasNext();) { String propertyName = (String) it.next(); if (!propertyName.startsWith(PREFIX_SERVICE_TO_TEST)) continue; String serviceName = StringUtils.removeStart(propertyName, PREFIX_SERVICE_TO_TEST); if (!services.contains(serviceName)) { // log.warn (serviceName + " is not available for testing"); countNotAvailable += 1; continue; } String[] inputs = cfg.getStringArray(propertyName); for (String input : inputs) { MyLocator locator = new MyLocator(serviceName, mainLocator); locator.enableKeepResults(keepResults); locator.setInputLine(input); if (oneByOne) { // sequential invocation qmsg(String.format("%-50s", "Running " + serviceName + "... ")); Properties report = callService(locator, reports); qmsgln("finished: " + report.getProperty(REPORT_JOB_STATUS)); } else { // do it in parallel startService(threads, locator, reports); if (maxThreads > 0) { // limit the number of threads // (just wait for some to finish) while (threads.size() >= maxThreads) { try { Thread.sleep(1000); } catch (Exception e) { } } } } } } } if (!oneByOne) { // wait for all the threads to finish while (threads.size() > 0) { try { Thread.sleep(1000); } catch (Exception e) { } } } msgln(""); // report all tests if (tableReport) createTableReport(reports); // report results int countSuccessful = 0; int countErrors = 0; for (Properties report : reports) { if (report.containsKey(REPORT_ERROR_MESSAGE)) { report.remove(REPORT_STACK_TRACE); countErrors += 1; createErrorReport(report); } else { String status = report.getProperty(REPORT_JOB_STATUS); if (SoaplabConstants.JOB_COMPLETED.equals(status)) { countSuccessful += 1; } else { countErrors += 1; createErrorReport(report); } } } // make a summary title("Summary"); msgln("Successfully: " + countSuccessful); msgln("Erroneously: " + countErrors); msgln("Not available: " + countNotAvailable); exit(0); } catch (Throwable e) { processErrorAndExit(e); } }