You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2009/11/08 21:53:52 UTC

svn commit: r833923 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java

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.