Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 97281 invoked from network); 8 Nov 2009 20:54:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Nov 2009 20:54:17 -0000 Received: (qmail 46581 invoked by uid 500); 8 Nov 2009 20:54:17 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 46489 invoked by uid 500); 8 Nov 2009 20:54:16 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 46480 invoked by uid 99); 8 Nov 2009 20:54:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Nov 2009 20:54:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Nov 2009 20:54:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AF9992388906; Sun, 8 Nov 2009 20:53:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r833923 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java Date: Sun, 08 Nov 2009 20:53:52 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091108205352.AF9992388906@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Sun Nov 8 20:53:52 2009 New Revision: 833923 URL: http://svn.apache.org/viewvc?rev=833923&view=rev Log: [CONFIGURATION-399] Integrated EnvironmentLookup into the default interpolation mechanism. Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java?rev=833923&r1=833922&r2=833923&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java Sun Nov 8 20:53:52 2009 @@ -116,6 +116,13 @@ */ public static final String PREFIX_CONSTANTS = "const"; + /** + * Constant for the prefix of the standard lookup object for resolving + * environment properties. + * @since 1.7 + */ + public static final String PREFIX_ENVIRONMENT = "env"; + /** Constant for the prefix separator. */ private static final char PREFIX_SEPARATOR = ':'; @@ -376,5 +383,6 @@ globalLookups = new HashMap(); globalLookups.put(PREFIX_SYSPROPERTIES, StrLookup.systemPropertiesLookup()); globalLookups.put(PREFIX_CONSTANTS, new ConstantLookup()); + globalLookups.put(PREFIX_ENVIRONMENT, new EnvironmentLookup()); } } Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?rev=833923&r1=833922&r2=833923&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java (original) +++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java Sun Nov 8 20:53:52 2009 @@ -24,12 +24,12 @@ import java.util.List; import java.util.Map; +import junit.framework.TestCase; + import org.apache.commons.collections.CollectionUtils; import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; -import junit.framework.TestCase; - /** * A test class for some of the basic functionality implemented by * AbstractConfiguration. @@ -255,6 +255,31 @@ } /** + * Tests whether environment variables can be interpolated. + */ + public void testInterpolateEnvironmentVariables() + { + AbstractConfiguration config = new TestConfigurationImpl( + new PropertiesConfiguration()); + EnvironmentConfiguration envConfig = new EnvironmentConfiguration(); + Map env = new HashMap(); + for (Iterator it = envConfig.getKeys(); it.hasNext();) + { + String key = (String) it.next(); + String propKey = "envtest." + key; + env.put(propKey, envConfig.getProperty(key)); + config.addProperty(propKey, "${env:" + key + "}"); + } + assertFalse("No environment properties", env.isEmpty()); + for (Iterator it = env.entrySet().iterator(); it.hasNext();) + { + Map.Entry e = (Map.Entry) it.next(); + assertEquals("Wrong value for " + e.getKey(), e.getValue(), config + .getString((String) e.getKey())); + } + } + + /** * Creates the source configuration for testing the copy() and append() * methods. This configuration contains keys with an odd index and values * starting with the prefix "src". There are also some list properties.