diff --git a/WHATSNEW b/WHATSNEW index 3b843092c..028e4af5a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -128,7 +128,7 @@ Fixed bugs: Bugzilla Report 51086. * the attributes of macrodef tasks had their values run through - property expansion twice. + property expansion twice. Still true by default, but can be disabled. Bugzilla Report 42046. * jvc doesn't like it if source file names in argument files are diff --git a/manual/Tasks/macrodef.html b/manual/Tasks/macrodef.html index b2d53e67f..8e60158c3 100644 --- a/manual/Tasks/macrodef.html +++ b/manual/Tasks/macrodef.html @@ -128,6 +128,15 @@ No + + doubleexpanding + + Controls whether or not property references in the attribute are expanded twice or just once. + See the FAQ for details. + since Ant 1.8.3 + + No; default true +

element

diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index a33c7e477..63143261b 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Iterator; import org.apache.tools.ant.util.CollectionUtils; +import org.apache.tools.ant.taskdefs.MacroDef; import org.apache.tools.ant.taskdefs.MacroInstance; import org.xml.sax.AttributeList; import org.xml.sax.helpers.AttributeListImpl; @@ -386,11 +387,17 @@ public class RuntimeConfigurable implements Serializable { // reflect these into the target, defer for // MacroInstance where properties are expanded for the // nested sequential - Object attrValue = null; + Object attrValue = PropertyHelper.getPropertyHelper(p).parseProperties(value); if (target instanceof MacroInstance) { - attrValue = value; - } else { - attrValue = PropertyHelper.getPropertyHelper(p).parseProperties(value); + for (Iterator attrs = ((MacroInstance) target).getMacroDef().getAttributes().iterator(); attrs.hasNext();) { + MacroDef.Attribute attr = (MacroDef.Attribute) attrs.next(); + if (attr.getName().equals(name)) { + if (!attr.isDoubleExpanding()) { + attrValue = value; + } + break; + } + } } try { ih.setAttribute(p, target, name, attrValue); diff --git a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java index 55bdca654..9a057655e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java +++ b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java @@ -331,6 +331,7 @@ public class MacroDef extends AntlibDefinition { private String name; private String defaultValue; private String description; + private boolean doubleExpanding = true; /** * The name of the attribute. @@ -386,6 +387,25 @@ public class MacroDef extends AntlibDefinition { return description; } + /** + * See {@link #isDoubleExpanding} for explanation. + * @param doubleExpanding true to expand twice, false for just once + * @since Ant 1.8.3 + */ + public void setDoubleExpanding(boolean doubleExpanding) { + this.doubleExpanding = doubleExpanding; + } + + /** + * Determines whether {@link RuntimeConfigurable#maybeConfigure(Project, boolean)} will reevaluate this property. + * For compatibility reasons (#52621) it will, though for most applications (#42046) it should not. + * @return true if expanding twice (the default), false for just once + * @since Ant 1.8.3 + */ + public boolean isDoubleExpanding() { + return doubleExpanding; + } + /** * equality method * diff --git a/src/tests/antunit/taskdefs/macrodef-test.xml b/src/tests/antunit/taskdefs/macrodef-test.xml index 7686a5484..8db9cd193 100644 --- a/src/tests/antunit/taskdefs/macrodef-test.xml +++ b/src/tests/antunit/taskdefs/macrodef-test.xml @@ -36,7 +36,7 @@ - +