/** * Default environment that uses system properties / environment variables (prefixed with <code>env</code>) */ public PropertiesEnvironment() { this(PropertyUtils.getGlobalProperties()); }
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); } } }
public OverridingProcessor(Properties overrides, Mode overrideMode, List<String> includes, List<String> excludes, int indent) { this.overrides = PropertyUtils.toImmutable(overrides); this.overrideMode = overrideMode; this.includes = ImmutableList.copyOf(includes); this.excludes = ImmutableList.copyOf(excludes); this.indent = indent; Builder.validate(this); }
protected Properties getGlobalProperties(Properties properties) { return PropertyUtils.getGlobalProperties(PropertyUtils.toEmpty(properties)); }
@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); } }
@Override public void process(Properties properties) { List<String> keys = PropertyUtils.getSortedKeys(overrideProperties, includes, excludes); for (String key : keys) { String newValue = overrideProperties.getProperty(key); PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode, indent); } }
@Override public Properties getObject() throws Exception { Assert.notNull(helper, "helper is null"); Assert.notNull(locations, "locations are null"); Assert.notNull(encoding, "encoding is null"); Assert.notNull(missingLocationsMode, "missingLocationsMode is null"); Properties global = PropertyUtils.getGlobalProperties(); this.properties = PropertyUtils.toEmpty(properties); Properties result = new Properties(); for (String location : locations) { Properties resolverProperties = PropertyUtils.combine(properties, result, global); String resolvedLocation = helper.replacePlaceholders(location, resolverProperties); if (LocationUtils.exists(resolvedLocation)) { Properties properties = PropertyUtils.load(location, encoding); result.putAll(properties); } else { ModeUtils.validate(missingLocationsMode, "Skipping non-existent location [" + resolvedLocation + "]"); } } return result; }
public static final void addOptions(List<String> args, Properties options) { if (options == null) { return; } List<String> keys = PropertyUtils.getSortedKeys(options); for (String key : keys) { String value = options.getProperty(key); logger.debug("Adding option [-o {}={}]", key, value); args.add("-o"); args.add(key + "=" + value); } }
/** * Process the properties passed in so they are ready for use by a Spring context.<br> * * 1 - Override with system/environment properties<br> * 2 - Decrypt any ENC(...) values<br> * 3 - Resolve all property values throwing an exception if any are unresolvable.<br> */ public static void prepareContextProperties(Properties properties, String encoding) { // Override with additional properties (if any) properties.putAll(getAdditionalProperties(properties, encoding)); // Override with system/environment properties properties.putAll(getGlobalProperties()); // Are we decrypting property values? decrypt(properties); // Are we resolving placeholders resolve(properties); }
@Deprecated public static PropertySource<?> getGlobalPropertySource(String name, List<org.kuali.common.util.property.ProjectProperties> pps) { // Load them from disk Properties source = PropertyUtils.load(pps); // Add in system/environment properties Properties globalSource = PropertyUtils.getGlobalProperties(source); logger.debug("Before prepareContextProperties()"); PropertyUtils.debug(globalSource); // Prepare them so they are ready for use PropertyUtils.prepareContextProperties(globalSource); logger.debug("After prepareContextProperties()"); PropertyUtils.debug(globalSource); // Return a PropertySource backed by the properties return new PropertiesPropertySource(name, globalSource); }
Properties global = PropertyUtils.getGlobalProperties(); Properties resolver = PropertyUtils.combine(properties, overrides, global); Properties loaded = PropertyUtils.load(resolvedLocation, location.getEncoding()); new OverrideProcessor(Mode.INFORM, loaded, 2).process(properties); } else { PropertyUtils.decrypt(properties); PropertyUtils.resolve(properties);
/** * Return a SpringContext that resolves all placeholders from the PropertySource passed in */ @Deprecated public static PropertySource<?> getGlobalPropertySource(List<String> locations, String encoding) { Properties loaded = PropertyUtils.load(locations, encoding); Properties global = PropertyUtils.getGlobalProperties(loaded); PropertyUtils.prepareContextProperties(global); return getGlobalPropertySource(global); }
private Properties getOverrides(Project project) { // Get a reference to system + environment properties Properties global = PropertyUtils.getGlobalProperties(); // Setup a properties object where system properties "win" over project properties return ImmutableProperties.copyOf(PropertyUtils.combine(project.getProperties(), global)); }
@Deprecated public static Properties load(List<org.kuali.common.util.property.ProjectProperties> pps) { // Create some storage for the Properties object we will be returning Properties properties = new Properties(); // Cycle through the list of project properties, loading them as we go for (org.kuali.common.util.property.ProjectProperties pp : pps) { logger.debug("oracle.dba.url.1={}", properties.getProperty("oracle.dba.url")); // Extract the properties context object PropertiesContext ctx = pp.getPropertiesContext(); // Retain the original properties object from the context Properties original = PropertyUtils.duplicate(PropertyUtils.toEmpty(ctx.getProperties())); // Override any existing property values with properties stored directly on the context Properties combined = PropertyUtils.combine(properties, ctx.getProperties()); // Store the combined properties on the context itself ctx.setProperties(combined); // Load properties as dictated by the context Properties loaded = load(ctx); logger.debug("oracle.dba.url.2={}", loaded.getProperty("oracle.dba.url")); // Override any existing property values with those we just loaded properties.putAll(loaded); // Override any existing property values with the properties that were stored directly on the context properties.putAll(original); } // Return the property values we now have return properties; }
/** * 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 property keys that should be included as a sorted list. */ public static final List<String> getSortedKeys(Properties properties, List<String> includes, List<String> excludes) { List<String> keys = getSortedKeys(properties); List<String> includedKeys = new ArrayList<String>(); for (String key : keys) { if (include(key, includes, excludes)) { includedKeys.add(key); } } return includedKeys; }
/** * Encrypt properties as dictated by <code>includes</code> and <code>excludes</code>. Encrypted values are surrounded by ENC(...). * * <pre> * my.value = ENC(DGA$S24FaIO) * </pre> */ public static void encrypt(Properties properties, TextEncryptor encryptor, List<String> includes, List<String> excludes) { List<String> keys = getSortedKeys(properties, includes, excludes); for (String key : keys) { String originalValue = properties.getProperty(key); String encryptedValue = encryptPropertyValue(encryptor, originalValue); properties.setProperty(key, encryptedValue); } }
/** * Decrypt any encrypted property values matching the <code>includes</code>, <code>excludes</code> patterns. Encrypted values are surrounded by ENC(...). * * <pre> * my.value = ENC(DGA$S24FaIO) * </pre> * * @deprecated */ @Deprecated public static void decrypt(Properties properties, TextEncryptor encryptor, List<String> includes, List<String> excludes) { List<String> keys = getSortedKeys(properties, includes, excludes); for (String key : keys) { String value = properties.getProperty(key); if (org.kuali.common.util.enc.EncUtils.isEncrypted(value)) { String decryptedValue = decryptPropertyValue(encryptor, value); properties.setProperty(key, decryptedValue); } } }
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; } }