This is almost certainly a duplicate, but just to reduce it to its most basic form:
I want to write a pair of macros which will be used as:
<defined-environment>
<task-in-environment>
<task-in-environment>
...
</defined-environment>
.. and ideally I'd like to be able mix the macro-defined contained tasks tasks with normal Ant tasks.
Alas, I can't seem to make this work. Even if I make the <defined-environment>'s child wrapper explicit rather than implicit, I get complaints that <task-in-environment> is not expected as a child of the element I'm trying to wrap around it. This is behaving as if Ant 1.8 simply does not understand the concept of nested macro usage.
Is that actually true -- is Ant's macro expansion strictly one-pass and nonrecursive, and would I actually have to write new Ant implementation code to support this usage? Or is there some detail I'm missing which will make this possible? I really would expect a modern macro processor to be able to handle this nesting...
(Yes, I know macrosdefs can call other macros. That doesn't allow the syntax I need. Nor does adding parameters to the <defined-environment> since the number of contained tasks will vary from one usage to another.)
Addendum
Ok, looks like folks want an explicit example. This isn't exactly what I'm doing -- mine is more complicated, which is why I want to hide the details in macros -- but it has the same general structure and demonstrates the issue...
<macrodef name="collection">
<attribute name="id"/>
<element name="contents" implicit="yes"/>
<sequential>
<union id="@{id}">
<contents/>
</union>
</sequential >
</macrodef>
<macrodef name="mappedfile">
<attribute name="fromdir"/>
<attribute name="todir"/>
<attribute name="whichfile"/>
<sequential>
<mappedresources>
<globmapper from="*" to="@{todir}/*"/>
<fileset dir="@{fromdir}" includes="@{whichfile}"/>
</mappedresources>
</sequential >
</macrodef>
<collection id="myfiles">
<mappedfile fromdir="/actual/directory" whichfile="a.a" todir="/imaginary/directory"/>
<mappedfile fromdir="/another/directory" whichfile="b.b" todir="/imaginary/directory"/>
</collection>
Produces a resource collection named myfiles which references files from two different directories but pretends they both came from the imaginary directory.
Or should. As far as I can tell, there is no good reason it shouldn't work. But it does seem that Ant 1.8 can't handle this, and that I'd have to code up plug-in task definitions to get the syntax abstraction I'm looking for. Or use a more intelligent xml processing tool as a preprocessor.
Found the explanation for my version of this, anyway...
Macros in ant are defined as creating tasks, even if the tags they expand to are resources. (Fixed phrasing. Note that Ant doesn't complain about such macro bodies; they just don't work.)
Union can take other resources/resource collections as children. Not tasks
Blammo. I don't even need nested macro calls to keep me from doing what I want; I simply can't use the inner macro -- which s the more important one for simplifying the logic I'm trying to support.
Ya can't get there from here.
Thanks anyway, folks.