public static Properties overWriteProperties(Properties bp, Properties ovp) { for (String propertyName : ovp.stringPropertyNames()) { bp.setProperty(propertyName,ovp.getProperty(propertyName)); } return bp; }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
/** * Put the given Properties into the Props. This method performs any variable substitution in the * value replacing any occurrence of ${name} with the value of get("name"). get() is called first * on the Props and next on the Properties object. * * @param properties The properties to put * @throws IllegalArgumentException If the variable given for substitution is not a valid key in * this Props. */ public void put(final Properties properties) { for (final String propName : properties.stringPropertyNames()) { this._current.put(propName, properties.getProperty(propName)); } }
@Override public void initializeVariablesFrom( VariableSpace parent ) { this.parent = parent; // Clone the system properties to avoid ConcurrentModificationException while iterating // and then add all of them to properties variable. Set<String> systemPropertiesNames = System.getProperties().stringPropertyNames(); for ( String key : systemPropertiesNames ) { getProperties().put( key, System.getProperties().getProperty( key ) ); } if ( parent != null ) { copyVariablesFrom( parent ); } if ( injection != null ) { properties.putAll( injection ); injection = null; } initialized = true; }
/** * Constructs a mapping of configuration and includes all properties that * start with the specified configuration prefix. Property names in the * mapping are trimmed to remove the configuration prefix. * * @param confPrefix configuration prefix * @return mapping of configuration properties with prefix stripped */ public Map<String, String> getPropsWithPrefix(String confPrefix) { Properties props = getProps(); Map<String, String> configMap = new HashMap<>(); for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { String value = get(name); String keyName = name.substring(confPrefix.length()); configMap.put(keyName, value); } } return configMap; }
@Test public void validateThatHyphensConvertedToCamelCase() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("foo-bar-zoo", "value"); poolProperties.setProperty("foo", "value"); poolProperties.setProperty("-bar", "value"); poolProperties.setProperty("zoo-", "value"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).containsExactlyInAnyOrder("foo", "Bar", "zoo", "fooBarZoo"); }
private static Collection<String> readPropertyKeys(String name) { try (InputStream in = PluginClassLoaderModule.class.getResourceAsStream(name)) { if (in == null) { throw new NullPointerException(String.format("Resource '%s' is not found in classpath. Jar file or classloader is broken.", name)); } Properties prop = new Properties(); prop.load(in); return prop.stringPropertyNames(); } catch (IOException ex) { throw new RuntimeException(ex); } }
List<ConfigChange> calcPropertyChanges(String namespace, Properties previous, Properties current) { if (previous == null) { previous = new Properties(); current = new Properties(); Set<String> previousKeys = previous.stringPropertyNames(); Set<String> currentKeys = current.stringPropertyNames(); changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey), PropertyChangeType.ADDED)); changes.add(new ConfigChange(namespace, removedKey, previous.getProperty(removedKey), null, PropertyChangeType.DELETED)); String previousValue = previous.getProperty(commonKey); String currentValue = current.getProperty(commonKey); if (Objects.equal(previousValue, currentValue)) {
private static String getPropertiesString(Properties props) { StringBuilder finalVersionList = new StringBuilder(); for(String propName: props.stringPropertyNames()) { if(finalVersionList.length() == 0) { finalVersionList.append(propName + "=" + props.getProperty(propName)); } else { finalVersionList.append("\n" + propName + "=" + props.getProperty(propName)); } } return finalVersionList.toString(); }
private Properties getOverriddenDefaults() throws IOException { Properties overriddenDefaults = new Properties(); overriddenDefaults.put(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.concat(LOG_FILE), getLogFile().getCanonicalPath()); for (String key : System.getProperties().stringPropertyNames()) { if (key.startsWith(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)) { overriddenDefaults.put(key, System.getProperty(key)); } } return overriddenDefaults; }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
public static Map<String, String[]> extractDimensions(Properties props, List<String> dimensions) { Map<String, String[]> dimensionsMap = new HashMap<>(); for (String property : props.stringPropertyNames()) { if (property.startsWith(MonitorsConfig.METRIC_DIMENSION_PREFIX)) { String dimension = property.substring(MonitorsConfig.METRIC_DIMENSION_PREFIX.length()); if (dimensions.contains(dimension)) { dimensionsMap.put( dimension, new String[]{props.getProperty(property)} ); } } } return dimensionsMap; }
public static Properties noClobberWriteProperties(Properties bp, Properties ovp) { for (String propertyName : ovp.stringPropertyNames()) { if (bp.containsKey(propertyName)) continue; bp.setProperty(propertyName,ovp.getProperty(propertyName)); } return bp; }
@Test public void validateThatJdbcDriverClassConvertedToDriverClassName() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("jdbc-driver-class", "foo"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("driverClassName"); }
/** * Loads the keys from the specified translation file into a set. * @param file translation file. * @return a Set object which holds the loaded keys. */ private Set<String> getTranslationKeys(File file) { Set<String> keys = new HashSet<>(); try (InputStream inStream = Files.newInputStream(file.toPath())) { final Properties translations = new Properties(); translations.load(inStream); keys = translations.stringPropertyNames(); } // -@cs[IllegalCatch] It is better to catch all exceptions since it can throw // a runtime exception. catch (final Exception ex) { logException(ex, file); } return keys; }
private void writeSystemProps(BufferedWriter fileWriter) throws IOException { fileWriter.write("System properties:\n"); Properties sysProps = system.properties(); for (String prop : new TreeSet<>(sysProps.stringPropertyNames())) { if (prop.startsWith(SONAR_PROP_PREFIX)) { continue; } fileWriter.append(String.format(KEY_VALUE_FORMAT, prop, sysProps.getProperty(prop))).append('\n'); } }
private Properties getOverriddenDefaults() throws IOException { final Properties overriddenDefaults = new Properties(); overriddenDefaults.put(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.concat(LOG_FILE), getLogFile().getCanonicalPath()); for (String key : System.getProperties().stringPropertyNames()) { if (key.startsWith(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)) { overriddenDefaults.put(key, System.getProperty(key)); } } return overriddenDefaults; }
private static Properties updatePropertiesWithOptions(Properties props, String[] args) { Properties allProperties = new Properties(); // copy it so props isn't changed but can be overridden by args for (String key : props.stringPropertyNames()) { allProperties.setProperty(key, props.getProperty(key)); } Properties options = StringUtils.argsToProperties(args); for (String key : options.stringPropertyNames()) { allProperties.setProperty(key, options.getProperty(key)); } return allProperties; }
private static Map<String, Object> propertiesToMap(final Properties properties) { final Map<String, Object> propertiesMap = new HashMap<>(); properties.stringPropertyNames().forEach( prop -> propertiesMap.put(prop, properties.getProperty(prop))); return propertiesMap; }
@Override public ChainedLogicalStreamBuilder withSlotOptions(Properties options) { for (String propertyName : options.stringPropertyNames()) { slotOptions.setProperty(propertyName, options.getProperty(propertyName)); } return this; }