I was just adding to the Ant Wiki AntOddities page the following macrodef : <!-- Allows you define a new property with a value of ${${a}.${b}} which can't be done by the Property task alone. --> <macrodef name="macro.compose-property"> <attribute name="name"/> <attribute name="stem"/> <attribute name="selector"/> <sequential> <property name="@{name}" value="${@{stem}.@{selector}}"/> </sequential> </macrodef> I wrote a quick counter-example which shows how expansions of properties in Ant is not recursive: <?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="all" name="changeme"> <target name="all"> <property name="a" value="arf"/> <property name="b" value="bark"/> <property name="arf.bark" value="woof woof woof"/> <echo message="${${a}.${b}}"/> </target> </project> but when I ran it, in Ant version 1.7 alpha built from CVS last night, instead of getting the unexpanded value of the overall expression which I expected: [echo] ${${a}.${b}} I received the unexpected: [echo] ${${a}.bark} This does not seem to me to be correct by the rules of Ant. Either the internal expansion should be complete or not at all ... the right term should not expand and leave the left unexpanded. It seems to me the expected answer was the one returned by Ant version 1.6.1 but I don't have that built now to see if the current behavior is a regression.
Well, the whole reason for not having nested property expansion is that the parser does not do recursive nesting of brakets, which means that it cannot detect that you are in a nested situation. It it were able to detect the case, then I am almost certain we would allow nested expansion instead forbid it. Looking at your example, you have: ${${a}.${b}} the syntax for a property is: <prop> --> '${' <name>'}' and <name> --> [^}]* which means the above gets interpreted as: '${' "${a" '}' '.' '${' "b" '}' '}' - property "${a" does not exist so it is printed out textually - property "b" does exists, hence it is expanded If we change this to understand recursion, we may as well do nested expansions.
I've done a sample enhancement to allow recursive property expansion. See attachments.
Created attachment 11753 [details] A patch which along with a new file adds recursive property expansion ... messier patch file than the actual changes warrant since I reformatted the file in NetBeans.
Created attachment 11754 [details] This new file accompanies the PropertyHandler.java patch and goes in ..ant/util
Created attachment 11755 [details] Test case to illustrate recursive property expansion
Changing title to reflect the recursive patch and making this an enhancement
In a recent message (http://marc.theaimsgroup.com/?l=ant-user&m=108819303623796&w=2) to the users@ mailing list, Wascally Wabbit proposes a fix in my proposed patch to the file ant/PropertyHelper.java. His fix is added to my patch and the new patch for that one file is being attached to this report.
Created attachment 11961 [details] Patch for file PropertyHelper.java that replaces my previous suggested patch and incorporates Wascally Wabbit's bug fix to the proposed patch
I think that "Nested property expansion" would be a better title because ${foo} should evaluate to "red green ${blue}" if it is the value of the foo property no matter if a property "blue" exists or not. Why is this issue still opened and no committer has reacted since nearly 3 years? Because this is a useful feature, WebTest (probably the project that makes the most intensive usage of Ant) now performs nested properties evaluation during test execution.
Partly because there is <scriptdef> that can do anything without even touching ANT core itself.
I think this has been superseeded by 1.8.x's PropertyHelpers and the props Antlib - I'd even close this issue if the props Antlib had been released ...
Hi Stefan ... Interesting to be discussing this 9.5 years later :) I will have to examine the props antlib ... thanks!
Hi Jack, true, I must admit it felt a bit strange to me as well.