From 9caa9ff4403ffbe97b9eae43d7cd79003319535b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 24 Feb 2010 16:52:16 +0000 Subject: [PATCH] enforce property immutability when resolving properties read as a map git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@915863 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/property/ResolvePropertyMap.java | 26 +++++++++++++++++++ .../apache/tools/ant/taskdefs/Property.java | 3 ++- src/tests/antunit/taskdefs/property-test.xml | 11 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java index 11468135c..ea0caf6e9 100644 --- a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java +++ b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java @@ -35,6 +35,7 @@ public class ResolvePropertyMap implements GetProperty { private final ParseProperties parseProperties; private final GetProperty master; private Map map; + private String prefix; /** * Constructor with a master getproperty and a collection of expanders. @@ -57,6 +58,19 @@ public class ResolvePropertyMap implements GetProperty { throw new BuildException( "Property " + name + " was circularly " + "defined."); } + + // if the property has already been set to the name it will + // have in the end, then return the existing value to ensure + // properties remain immutable + String masterPropertyName = name; + if (prefix != null) { + masterPropertyName = prefix + name; + } + Object masterProperty = master.getProperty(masterPropertyName); + if (masterProperty != null) { + return masterProperty; + } + try { seen.add(name); return parseProperties.parseProperties((String) map.get(name)); @@ -68,9 +82,21 @@ public class ResolvePropertyMap implements GetProperty { /** * The action method - resolves all the properties in a map. * @param map the map to resolve properties in. + * @deprecated since Ant 1.8.1, use the two-arg method instead. */ public void resolveAllProperties(Map map) { + resolveAllProperties(map, null); + } + + /** + * The action method - resolves all the properties in a map. + * @param map the map to resolve properties in. + * @param prefix the prefix the properties defined inside the map + * will finally receive - may be null. + */ + public void resolveAllProperties(Map map, String prefix) { this.map = map; // The map gets used in the getProperty callback + this.prefix = prefix; for (Iterator i = map.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); Object result = getProperty(key); diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java index 1b2bd4e6b..f84348247 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -715,7 +715,8 @@ public class Property extends Task { new ResolvePropertyMap( getProject(), propertyHelper, - propertyHelper.getExpanders()).resolveAllProperties(props); + propertyHelper.getExpanders()) + .resolveAllProperties(props, prefix); } } diff --git a/src/tests/antunit/taskdefs/property-test.xml b/src/tests/antunit/taskdefs/property-test.xml index 3a3e10a60..77d23608c 100644 --- a/src/tests/antunit/taskdefs/property-test.xml +++ b/src/tests/antunit/taskdefs/property-test.xml @@ -77,4 +77,15 @@ + + + + + + + +