Author: bodewig
Date: Wed Feb 24 16:52:16 2010
New Revision: 915863
URL: http://svn.apache.org/viewvc?rev=915863&view=rev
Log:
enforce property immutability when resolving properties read as a map
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java?rev=915863&r1=915862&r2=915863&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
Wed Feb 24 16:52:16 2010
@@ -35,6 +35,7 @@
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 @@
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 @@
/**
* 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);
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java?rev=915863&r1=915862&r2=915863&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java Wed Feb
24 16:52:16 2010
@@ -715,7 +715,8 @@
new ResolvePropertyMap(
getProject(),
propertyHelper,
-
propertyHelper.getExpanders()).resolveAllProperties(props);
+ propertyHelper.getExpanders())
+ .resolveAllProperties(props, prefix);
}
}
Modified: ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml?rev=915863&r1=915862&r2=915863&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml Wed Feb 24
16:52:16 2010
@@ -77,4 +77,15 @@
<property name="foo" location="${testfile}" relative="true" basedir=".."/>
<au:assertPropertyEquals name="foo"
value="taskdefs${file.separator}${testfile}"/>
</target>
+
+ <target name="testNestedExpansionHonorsImmutability">
+ <mkdir dir="${input}"/>
+ <property name="x" value="x"/>
+ <echo file="${input}/x.properties"><![CDATA[
+x=y
+y=$${x}
+]]></echo>
+ <property file="${input}/x.properties"/>
+ <au:assertPropertyEquals name="y" value="x"/>
+ </target>
</project>