/** * Return a new <code>Properties</code> object containing properties prefixed with <code>prefix</code>. If <code>prefix</code> is blank, the new properties object duplicates * the properties passed in. */ public static final Properties getPrefixedProperties(Properties properties, String prefix) { if (StringUtils.isBlank(prefix)) { return duplicate(properties); } Properties newProperties = new Properties(); for (String key : properties.stringPropertyNames()) { String value = properties.getProperty(key); String newKey = StringUtils.startsWith(key, prefix + ".") ? key : prefix + "." + key; newProperties.setProperty(newKey, value); } return newProperties; }
@Override public Properties getObject() { Assert.notNull(properties, "properties is null"); return PropertyUtils.duplicate(properties); }
@Override public void execute() { Assert.notNull(properties, "properties is null"); Properties duplicate = PropertyUtils.duplicate(properties); PropertyUtils.trim(duplicate, includes, excludes); logger.info("Displaying {} properties\n\n{}", duplicate.size(), PropertyUtils.toString(duplicate)); }
/** * Return a new properties object containing the properties passed in, plus any global properties as requested. If <code>mode</code> is <code>NONE</code> the new properties are * a duplicate of the properties passed in. If <code>mode</code> is <code>ENVIRONMENT</code> the new properties contain the original properties plus any properties returned by * <code>getEnvProperties()</code>. If <code>mode</code> is <code>SYSTEM</code> the new properties contain the original properties plus <code>System.getProperties()</code>. If * <code>mode</code> is <code>BOTH</code> the new properties contain the original properties plus <code>getEnvProperties()</code> and <code>System.getProperties()</code>. */ public static final Properties getProperties(Properties properties, GlobalPropertiesMode mode) { Properties newProperties = duplicate(properties); List<PropertyProcessor> modifiers = getPropertyProcessors(mode); for (PropertyProcessor modifier : modifiers) { modifier.process(newProperties); } return newProperties; }
protected Properties getLocationHelperProperties(Properties properties, GlobalPropertiesMode mode) { Properties locationHelperProperties = PropertyUtils.duplicate(PropertyUtils.toEmpty(properties)); List<PropertyProcessor> processors = getLocationHelperProcessors(); for (PropertyProcessor processor : processors) { processor.process(locationHelperProperties); } return locationHelperProperties; }
@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; }
@Override public void execute() { // Nothing to do in this case if (skip) { return; } // Make sure we have an output file Assert.notNull(outputFile, "outputFile is null"); // May not need to go any further if (LocationUtils.exists(outputFile) && skipIfExists) { return; } // Make sure we have some properties to work with Assert.notNull(properties, "properties is null"); // Clone the properties they passed us Properties duplicate = PropertyUtils.duplicate(properties); // Trim out unwanted properties PropertyUtils.trim(duplicate, includes, excludes); // Might not need to store them if (!isStoreProperties(outputFile, skipIfEqual, duplicate)) { return; } // Persist them to the file system store(duplicate, outputFile, encoding); }
protected Properties getFilterProperties(Project project) { String classpathPrefix = ProjectUtils.getClasspathPrefix(project.getGroupId(), project.getArtifactId()); Properties duplicate = PropertyUtils.duplicate(project.getProperties()); duplicate.setProperty(CLASSPATH_PREFIX_KEY, classpathPrefix); String location = getMetadataConfigFilePath(project, PROPS); Properties metadata = new Properties(); if (LocationUtils.exists(location)) { String encoding = ProjectUtils.getEncoding(project); metadata = PropertyUtils.load(location, encoding); } duplicate.putAll(metadata); return duplicate; }
@Override public void store(PropertyStoreContext context, Properties properties) { Properties duplicate = PropertyUtils.duplicate(properties); context.initialize(duplicate); PropertyUtils.process(duplicate, context.getProcessors()); PropertyUtils.store(duplicate, context.getFile(), context.getEncoding(), context.getComment()); }