Bug 29347 - Recursive property expansion
Summary: Recursive property expansion
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.7.0
Hardware: Sun Solaris
: P3 enhancement with 4 votes (vote)
Target Milestone: 1.9.0
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks: 52621
  Show dependency tree
 
Reported: 2004-06-02 18:44 UTC by Jack J. Woehr
Modified: 2014-01-07 05:41 UTC (History)
1 user (show)



Attachments
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. (32.74 KB, patch)
2004-06-03 19:06 UTC, Jack J. Woehr
Details | Diff
This new file accompanies the PropertyHandler.java patch and goes in ..ant/util (3.55 KB, text/plain)
2004-06-03 19:07 UTC, Jack J. Woehr
Details
Test case to illustrate recursive property expansion (514 bytes, text/plain)
2004-06-03 19:08 UTC, Jack J. Woehr
Details
Patch for file PropertyHelper.java that replaces my previous suggested patch and incorporates Wascally Wabbit's bug fix to the proposed patch (32.85 KB, patch)
2004-06-27 04:30 UTC, Jack J. Woehr
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jack J. Woehr 2004-06-02 18:44:22 UTC
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.
Comment 1 Jose Alberto Fernandez 2004-06-03 10:32:58 UTC
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.


Comment 2 Jack J. Woehr 2004-06-03 19:03:57 UTC
I've done a sample enhancement to allow recursive property expansion. See
attachments.
Comment 3 Jack J. Woehr 2004-06-03 19:06:21 UTC
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.
Comment 4 Jack J. Woehr 2004-06-03 19:07:19 UTC
Created attachment 11754 [details]
This new file accompanies the PropertyHandler.java patch and goes in ..ant/util
Comment 5 Jack J. Woehr 2004-06-03 19:08:08 UTC
Created attachment 11755 [details]
Test case to illustrate recursive property expansion
Comment 6 peter reilly 2004-06-09 08:33:45 UTC
Changing title to reflect the recursive patch
and making this an enhancement
Comment 7 Jack J. Woehr 2004-06-27 04:28:51 UTC
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.
Comment 8 Jack J. Woehr 2004-06-27 04:30:31 UTC
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
Comment 9 Marc Guillemot 2007-06-05 04:59:39 UTC
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.
Comment 10 Alexey Solofnenko 2007-06-05 18:49:42 UTC
Partly because there is <scriptdef> that can do anything without even touching
ANT core itself.
Comment 11 Stefan Bodewig 2014-01-06 20:15:35 UTC
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 ...
Comment 12 Jack J. Woehr 2014-01-06 20:23:17 UTC
Hi Stefan ... Interesting to be discussing this 9.5 years later :) I will have to examine the props antlib ... thanks!
Comment 13 Stefan Bodewig 2014-01-07 05:41:34 UTC
Hi Jack, true, I must admit it felt a bit strange to me as well.