Author: gnodet Date: Thu Sep 7 19:21:21 2017 New Revision: 1807637 URL: http://svn.apache.org/viewvc?rev=1807637&view=rev Log: [FELIX-5688] TypedProperties#put method is not idempotent
Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java?rev=1807637&r1=1807636&r2=1807637&view=diff ============================================================================== --- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java (original) +++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java Thu Sep 7 19:21:21 2017 @@ -281,6 +281,10 @@ public class Properties extends Abstract return old; } + void putAllSubstituted(Map<? extends String, ? extends String> m) { + storage.putAll(m); + } + public String put(String key, List<String> commentLines, List<String> valueLines) { commentLines = new ArrayList<String>(commentLines); valueLines = new ArrayList<String>(valueLines); Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java?rev=1807637&r1=1807636&r2=1807637&view=diff ============================================================================== --- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java (original) +++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java Thu Sep 7 19:21:21 2017 @@ -336,7 +336,7 @@ public class TypedProperties extends Abs ((DynamicMap) map).init(callback, finalSubstitution); } for (Map.Entry<String, TypedProperties> entry : properties.entrySet()) { - entry.getValue().storage.putAll(dynamic.get(entry.getKey())); + entry.getValue().storage.putAllSubstituted(dynamic.get(entry.getKey())); } } Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java?rev=1807637&r1=1807636&r2=1807637&view=diff ============================================================================== --- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java (original) +++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java Thu Sep 7 19:21:21 2017 @@ -340,4 +340,17 @@ public class PropertiesTest extends Test assertEquals(Arrays.asList("#", "# List of good fruits", "#"), p1.getComments("fruits")); assertEquals("apple, banana, pear", p1.getProperty("fruits")); } + + public void testSubstitution() throws IOException + { + String str = "port = 4141\n" + + "host = localhost\n" + + "url = https://${host}:${port}/service\n"; + Properties properties = new Properties(); + properties.load(new StringReader(str)); + properties.put("url", "https://localhost:4141/service"); + StringWriter sw = new StringWriter(); + properties.save(sw); + assertEquals(str, sw.toString()); + } } Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java?rev=1807637&r1=1807636&r2=1807637&view=diff ============================================================================== --- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java (original) +++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/TypedPropertiesTest.java Thu Sep 7 19:21:21 2017 @@ -99,4 +99,16 @@ public class TypedPropertiesTest extends assertEquals("key = F\"1137191584\"\n", sw.toString()); } + public void testSubstitution() throws IOException + { + String str = "port = 4141\n" + + "host = localhost\n" + + "url = https://${host}:${port}/service\n"; + TypedProperties properties = new TypedProperties(); + properties.load(new StringReader(str)); + properties.put("url", "https://localhost:4141/service"); + StringWriter sw = new StringWriter(); + properties.save(sw); + assertEquals(str, sw.toString()); + } }