Author: oheger Date: Thu May 26 19:53:21 2016 New Revision: 1745638 URL: http://svn.apache.org/viewvc?rev=1745638&view=rev Log: [CONFIGURATION-632] Better support for interpolation with arrays.
Variables that reference properties with multiple values are now handled correctly. The getList() and getStringArray() methods then return all values of the referenced property. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java?rev=1745638&r1=1745637&r2=1745638&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/CompositeConfiguration.java Thu May 26 19:53:21 2016 @@ -597,10 +597,10 @@ implements Cloneable * @param config the configuration to query * @param key the key of the property */ - private static void appendListProperty(List<Object> dest, Configuration config, + private void appendListProperty(List<Object> dest, Configuration config, String key) { - Object value = config.getProperty(key); + Object value = interpolate(config.getProperty(key)); if (value != null) { if (value instanceof Collection) Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java?rev=1745638&r1=1745637&r2=1745638&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestCompositeConfiguration.java Thu May 26 19:53:21 2016 @@ -17,6 +17,7 @@ package org.apache.commons.configuration2; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -795,6 +796,22 @@ public class TestCompositeConfiguration } /** + * Tests whether interpolation works if a variable references a property + * with multiple values. This test is related to CONFIGURATION-632. + */ + @Test + public void testInterpolationArrayReference() + { + Configuration props = new PropertiesConfiguration(); + String[] values = { "a", "property", "with", "multiple", "values" }; + props.addProperty("keyMultiValues", values); + props.addProperty("keyReference", "${keyMultiValues}"); + cc.addConfiguration(props); + assertArrayEquals("Wrong interpolated value", values, + cc.getStringArray("keyReference")); + } + + /** * Tests the behavior of setListDelimiterHandler() if the in-memory configuration * is not derived from BaseConfiguration. This test is related to * CONFIGURATION-476.