/** * Return a new properties object containing the properties passed in, plus any properties returned by <code>getEnvAsProperties()</code> and <code>System.getProperties()</code> * . Properties from <code>getEnvAsProperties()</code> override <code>properties</code> and properties from <code>System.getProperties()</code> override everything. */ public static final Properties getGlobalProperties(Properties properties) { return getProperties(properties, Constants.DEFAULT_GLOBAL_PROPERTIES_MODE); }
/** * Return a new properties object containing the properties from <code>getEnvAsProperties()</code> and <code>System.getProperties()</code>. Properties from * <code>System.getProperties()</code> override properties from <code>getEnvAsProperties</code> if there are duplicates. */ public static final Properties getGlobalProperties() { return getProperties(Constants.DEFAULT_GLOBAL_PROPERTIES_MODE); }
/** * Search <code>properties</code> plus global properties to find a value for <code>key</code> according to the mode passed in. If the property is present in both, the value * from the global properties is returned. */ public static final String getProperty(String key, Properties properties, GlobalPropertiesMode mode) { return getProperties(properties, mode).getProperty(key); }
/** * Return a new properties object containing global properties as requested. If <code>mode</code> is <code>NONE</code> the new properties are empty. If <code>mode</code> is * <code>ENVIRONMENT</code> the new properties contain the properties returned by <code>getEnvProperties()</code>. If <code>mode</code> is <code>SYSTEM</code> the new * properties contain <code>System.getProperties()</code>. If <code>mode</code> is <code>BOTH</code> the new properties contain <code>getEnvProperties</code> plus * <code>System.getProperties()</code> with system properties overriding environment variables if the same case sensitive property key is supplied in both places. */ public static final Properties getProperties(GlobalPropertiesMode mode) { return getProperties(new Properties(), mode); }
public static void overrideWithGlobalValues(Properties properties, GlobalPropertiesMode mode) { List<String> keys = PropertyUtils.getSortedKeys(properties); Properties global = PropertyUtils.getProperties(mode); for (String key : keys) { String globalValue = global.getProperty(key); if (!StringUtils.isBlank(globalValue)) { properties.setProperty(key, globalValue); } } }
@Override public void process(Properties properties) { Properties global = PropertyUtils.getProperties(properties, globalPropertiesMode); List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes); for (String key : keys) { String newValue = global.getProperty(key); PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode); } }
/** * Return a new <code>Properties</code> object containing only those properties where the resolved value is different from the original value. Using global properties to * perform property resolution as indicated by <code>globalPropertiesMode</code> */ public static final Properties getResolvedProperties(Properties properties, PropertyPlaceholderHelper helper, GlobalPropertiesMode globalPropertiesMode) { Properties global = getProperties(properties, globalPropertiesMode); List<String> keys = getSortedKeys(properties); Properties newProperties = new Properties(); for (String key : keys) { String originalValue = properties.getProperty(key); String resolvedValue = helper.replacePlaceholders(originalValue, global); if (!resolvedValue.equals(originalValue)) { logger.debug("Resolved property '" + key + "' [{}] -> [{}]", Str.flatten(originalValue), Str.flatten(resolvedValue)); newProperties.setProperty(key, resolvedValue); } } return newProperties; }
protected List<Deployable> getApplicationConfig() { Properties properties = PropertySourceUtils.getAllEnumerableProperties(configurableEnvironment); Properties configProperties = PropertyUtils.getProperties(properties, "kdo.config.*.local", null); List<String> keys = PropertyUtils.getSortedKeys(configProperties); List<Deployable> deployables = new ArrayList<Deployable>(); for (String key : keys) { Deployable deployable = getApplicationConfig(key); if (deployable.isExists()) { deployables.add(deployable); } } return deployables; }
protected String getResolvedLocation(String location, Properties properties) { boolean resolve = PropertyUtils.containsUnresolvedPlaceholder(location); if (resolve) { GlobalPropertiesMode gpm = GlobalPropertiesMode.valueOf(globalPropertiesMode); Properties duplicate = PropertyUtils.getProperties(properties, gpm); List<PropertyProcessor> processors = getLocationProcessors(); for (PropertyProcessor processor : processors) { processor.process(duplicate); } return helper.replacePlaceholders(location, duplicate); } else { return location; } }
@Override public void initialize(Properties properties) { GlobalPropertiesMode gpm = GlobalPropertiesMode.valueOf(globalPropertiesMode); Properties global = PropertyUtils.getProperties(properties, gpm); this.encryptionMode = resolve(encryptionMode, global); this.encryptionPassword = resolveAndRemove(encryptionPassword, global, properties); this.encryptionStrength = resolve(encryptionStrength, global); this.style = resolve(style, global); this.prefix = resolve(prefix, global); this.resolvePlaceholders = resolve(resolvePlaceholders, global); log(); validate(); addProcessors(); logger.info("Proceeding with " + processors.size() + " processors."); }