List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:pl.project13.maven.git.GitCommitIdMojo.java
private void appendPropertiesToReactorProjects(@NotNull Properties properties, @NotNull String trimmedPrefixWithDot) { for (MavenProject mavenProject : reactorProjects) { Properties mavenProperties = mavenProject.getProperties(); // TODO check message log.info("{}] project {}", mavenProject.getName(), mavenProject.getName()); for (Object key : properties.keySet()) { if (key.toString().startsWith(trimmedPrefixWithDot)) { mavenProperties.put(key, properties.get(key)); }/*from w w w . jav a 2 s . c o m*/ } } }
From source file:io.warp10.script.WarpScriptLib.java
public static void registerExtensions() { Properties props = WarpConfig.getProperties(); if (null == props) { return;/*from w w w.j a v a 2s .co m*/ } // // Extract the list of extensions // Set<String> ext = new LinkedHashSet<String>(); if (props.containsKey(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS)) { String[] extensions = props.getProperty(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS).split(","); for (String extension : extensions) { ext.add(extension.trim()); } } for (Object key : props.keySet()) { if (!key.toString().startsWith(Configuration.CONFIG_WARPSCRIPT_EXTENSION_PREFIX)) { continue; } ext.add(props.get(key).toString().trim()); } // Sort the extensions List<String> sortedext = new ArrayList<String>(ext); sortedext.sort(null); boolean failedExt = false; // // Determine the possible jar from which WarpScriptLib was loaded // String wsljar = null; URL wslurl = WarpScriptLib.class .getResource('/' + WarpScriptLib.class.getCanonicalName().replace('.', '/') + ".class"); if (null != wslurl && "jar".equals(wslurl.getProtocol())) { wsljar = wslurl.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); } for (String extension : sortedext) { // If the extension name contains '#', remove everything up to the last '#', this was used as a sorting prefix if (extension.contains("#")) { extension = extension.replaceAll("^.*#", ""); } try { // // Locate the class using the current class loader // URL url = WarpScriptLib.class.getResource('/' + extension.replace('.', '/') + ".class"); if (null == url) { LOG.error("Unable to load extension '" + extension + "', make sure it is in the class path."); failedExt = true; continue; } Class cls = null; // // If the class was located in a jar, load it using a specific class loader // so we can have fat jars with specific deps, unless the jar is the same as // the one from which WarpScriptLib was loaded, in which case we use the same // class loader. // if ("jar".equals(url.getProtocol())) { String jarfile = url.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); ClassLoader cl = WarpScriptLib.class.getClassLoader(); // If the jar differs from that from which WarpScriptLib was loaded, create a dedicated class loader if (!jarfile.equals(wsljar)) { cl = new WarpClassLoader(jarfile, WarpScriptLib.class.getClassLoader()); } cls = Class.forName(extension, true, cl); } else { cls = Class.forName(extension, true, WarpScriptLib.class.getClassLoader()); } //Class cls = Class.forName(extension); WarpScriptExtension wse = (WarpScriptExtension) cls.newInstance(); wse.register(); System.out.println("LOADED extension '" + extension + "'"); } catch (Exception e) { throw new RuntimeException(e); } } if (failedExt) { throw new RuntimeException("Some WarpScript extensions could not be loaded, aborting."); } }
From source file:org.apache.torque.task.TorqueSQLExec.java
/** * Load the sql file and then execute it * * @throws BuildException//from w ww .j a v a 2 s . co m */ public void execute() throws BuildException { if (sqldbmap == null || getSqlDbMap().exists() == false) { throw new BuildException( "You haven't provided an sqldbmap, or " + "the one you specified doesn't exist: " + sqldbmap); } if (driver == null) { throw new BuildException("Driver attribute must be set!", getLocation()); } if (userId == null) { throw new BuildException("User Id attribute must be set!", getLocation()); } if (password == null) { throw new BuildException("Password attribute must be set!", getLocation()); } if (url == null) { throw new BuildException("Url attribute must be set!", getLocation()); } Properties map = new Properties(); try { FileInputStream fis = new FileInputStream(getSqlDbMap()); map.load(fis); fis.close(); } catch (IOException ioe) { throw new BuildException("Cannot open and process the sqldbmap!"); } Map databases = new HashMap(); Iterator eachFileName = map.keySet().iterator(); while (eachFileName.hasNext()) { String sqlfile = (String) eachFileName.next(); String database = map.getProperty(sqlfile); List files = (List) databases.get(database); if (files == null) { files = new ArrayList(); databases.put(database, files); } // We want to make sure that the base schemas // are inserted first. if (sqlfile.indexOf("schema.sql") != -1) { files.add(0, sqlfile); } else { files.add(sqlfile); } } Iterator eachDatabase = databases.keySet().iterator(); while (eachDatabase.hasNext()) { String db = (String) eachDatabase.next(); List transactions = new ArrayList(); eachFileName = ((List) databases.get(db)).iterator(); while (eachFileName.hasNext()) { String fileName = (String) eachFileName.next(); File file = new File(srcDir, fileName); if (file.exists()) { Transaction transaction = new Transaction(); transaction.setSrc(file); transactions.add(transaction); } else { System.out.println( "File '" + file.getAbsolutePath() + "' in sqldbmap does not exist, so skipping it."); } } insertDatabaseSqlFiles(url, db, transactions); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopAppContextLoader.java
protected void initAppProperties() { AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.DESKTOP.toString()); String appPropertiesConfig = System.getProperty(APP_PROPERTIES_CONFIG_SYS_PROP); if (StringUtils.isBlank(appPropertiesConfig)) appPropertiesConfig = defaultAppPropertiesConfig; final Properties properties = new Properties(); StrTokenizer tokenizer = new StrTokenizer(appPropertiesConfig); for (String str : tokenizer.getTokenArray()) { InputStream stream = null; try {/*from w w w.j a v a2s . c o m*/ stream = getClass().getResourceAsStream(str); if (stream != null) { Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name()); properties.load(reader); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } for (String arg : args) { arg = arg.trim(); int pos = arg.indexOf('='); if (pos > 0) { String key = arg.substring(0, pos); String value = arg.substring(pos + 1); properties.setProperty(key, value); } } for (Object key : properties.keySet()) { AppContext.setProperty((String) key, properties.getProperty((String) key).trim()); } List<String> list = new ArrayList<>(); for (String key : AppContext.getPropertyNames()) { list.add(key + "=" + AppContext.getProperty(key)); } Collections.sort(list); log.info(new StrBuilder("AppProperties:\n").appendWithSeparators(list, "\n").toString()); }
From source file:com.hotelbeds.distribution.hotel_api_sdk.HotelApiClient.java
public void addPropertiesAsParams(Properties properties, final Map<String, String> params) { if (properties != null) { for (Object name : properties.keySet()) { String propertyName = (String) name; params.put(EXTRA_PARAM_PREFIX + propertyName, properties.getProperty(propertyName)); }/*w w w .j a v a 2 s . c o m*/ } }
From source file:org.eclipse.gemini.blueprint.test.AbstractDependencyManagerTests.java
/** * Returns the bundles that have to be installed as part of the test setup. * This method is preferred as the bundles are by their names rather then as * {@link Resource}s. It allows for a <em>declarative</em> approach for * specifying bundles as opposed to {@link #getTestBundles()} which provides * a programmatic one.// w w w .jav a2 s . c o m * * <p/>This implementation reads a predefined properties file to determine * the bundles needed. If the configuration needs to be changed, consider * changing the configuration location. * * @return an array of testing framework bundle identifiers * @see #getTestingFrameworkBundlesConfiguration() * @see #locateBundle(String) * */ protected String[] getTestFrameworkBundlesNames() { // load properties file Properties props = PropertiesUtil.loadAndExpand(getTestingFrameworkBundlesConfiguration()); if (props == null) throw new IllegalArgumentException( "cannot load default configuration from " + getTestingFrameworkBundlesConfiguration()); boolean trace = logger.isTraceEnabled(); if (trace) logger.trace("Loaded properties " + props); // pass properties to test instance running inside OSGi space System.getProperties().put(GEMINI_BLUEPRINT_VERSION_PROP_KEY, props.get(GEMINI_BLUEPRINT_VERSION_PROP_KEY)); System.getProperties().put(SPRING_VERSION_PROP_KEY, props.get(SPRING_VERSION_PROP_KEY)); Properties excluded = PropertiesUtil.filterKeysStartingWith(props, IGNORE); if (trace) { logger.trace("Excluded ignored properties " + excluded); } String[] bundles = props.keySet().toArray(new String[props.size()]); // sort the array (as the Properties file doesn't respect the order) //bundles = StringUtils.sortStringArray(bundles); if (logger.isDebugEnabled()) logger.debug("Default framework bundles :" + ObjectUtils.nullSafeToString(bundles)); return bundles; }
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
private void loadPresetProperties() { //Either look for /sdcard/GPSLogger/gpslogger.properties or /sdcard/gpslogger.properties File file = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/gpslogger.properties"); if (!file.exists()) { file = new File(Environment.getExternalStorageDirectory() + "/gpslogger.properties"); if (!file.exists()) { return; }/*from w w w . j av a2 s . co m*/ } try { Properties props = new Properties(); InputStreamReader reader = new InputStreamReader(new FileInputStream(file)); props.load(reader); for (Object key : props.keySet()) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); String value = props.getProperty(key.toString()); tracer.info("Setting preset property: " + key.toString() + " to " + value.toString()); if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) { editor.putBoolean(key.toString(), Boolean.parseBoolean(value)); } else { editor.putString(key.toString(), value); } editor.commit(); } } catch (Exception e) { tracer.error("Could not load preset properties", e); } }
From source file:com.mirth.connect.model.util.ImportConverter3_0_0.java
/** * Writes all the entries in the given properties object to the propertiesElement. Any existing * elements in propertiesElement will be removed first. *//*from www .j a v a2 s . c o m*/ public static void writePropertiesElement(DonkeyElement propertiesElement, Properties properties) { propertiesElement.removeChildren(); for (Object key : properties.keySet()) { DonkeyElement property = propertiesElement.addChildElement("property"); property.setAttribute("name", key.toString()); property.setTextContent(properties.getProperty(key.toString())); } }
From source file:fr.efl.chaine.xslt.GauloisPipe.java
private Destination buildSerializer(Output output, File inputFile, HashMap<QName, ParameterValue> parameters) throws InvalidSyntaxException, URISyntaxException { if (output.isNullOutput()) { return processor.newSerializer(new NullOutputStream()); } else if (output.isConsoleOutput()) { return processor.newSerializer("out".equals(output.getConsole()) ? System.out : System.err); }/*from w w w . j ava 2 s. c o m*/ final File destinationFile = output.getDestinationFile(inputFile, parameters); final Serializer ret = processor.newSerializer(destinationFile); Properties outputProps = output.getOutputProperties(); for (Object key : outputProps.keySet()) { ret.setOutputProperty(Output.VALID_OUTPUT_PROPERTIES.get(key.toString()).getSaxonProperty(), outputProps.getProperty(key.toString())); } if (config.isLogFileSize()) { Destination dest = new Destination() { @Override public Receiver getReceiver(Configuration c) throws SaxonApiException { return new ProxyReceiver(ret.getReceiver(c)) { @Override public void close() throws XPathException { super.close(); LOGGER.info("[" + instanceName + "] Written " + destinationFile.getAbsolutePath() + ": " + destinationFile.length()); } }; } @Override public void close() throws SaxonApiException { ret.close(); } }; return dest; } else { return ret; } }
From source file:com.google.api.ads.adwords.awreporting.processors.onfile.ReportProcessorOnFile.java
/** * Generate all the mapped reports to the given account IDs. * * @param dateRangeType the date range type. * @param dateStart the starting date.//from ww w. j av a2s.co m * @param dateEnd the ending date. * @param accountIdsSet the account IDs. * @param properties the properties file * @throws Exception error reaching the API. */ @Override public void generateReportsForMCC(String mccAccountId, ReportDefinitionDateRangeType dateRangeType, String dateStart, String dateEnd, Set<Long> accountIdsSet, Properties properties, ReportDefinitionReportType onDemandReportType, List<String> reportFieldsToInclude) throws Exception { LOGGER.info("*** Retrieving account IDs ***"); if (accountIdsSet == null || accountIdsSet.size() == 0) { accountIdsSet = this.retrieveAccountIds(mccAccountId); } else { LOGGER.info("Accounts loaded from file."); } AdWordsSessionBuilderSynchronizer sessionBuilder = new AdWordsSessionBuilderSynchronizer( authenticator.authenticate(mccAccountId, false)); LOGGER.info("*** Generating Reports for " + accountIdsSet.size() + " accounts ***"); Stopwatch stopwatch = Stopwatch.createStarted(); Set<ReportDefinitionReportType> reports = this.csvReportEntitiesMapping.getDefinedReports(); // reports Set<Object> propertiesKeys = properties.keySet(); for (Object key : propertiesKeys) { String reportDefinitionKey = key.toString(); ReportDefinitionReportType reportType = this.extractReportTypeFromKey(reportDefinitionKey); if (reportType != null && reports.contains(reportType)) { this.downloadAndProcess(mccAccountId, sessionBuilder, reportType, dateRangeType, dateStart, dateEnd, accountIdsSet, reportDefinitionKey, properties); } } this.multipleClientReportDownloader.finalizeExecutorService(); stopwatch.stop(); LOGGER.info("*** Finished processing all reports in " + (stopwatch.elapsed(TimeUnit.MILLISECONDS) / 1000) + " seconds ***\n"); }