ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Cohen" <>
Subject RE: Tale from the front: macrodef nesting
Date Mon, 27 Oct 2003 15:15:32 GMT
You're correct about working around this problem.  However, I think it's
still a problem that the same
${identifier} notation can either indicate a macrodef attribute or an
ant property with completely different times of resolution.

In other words, the line of warning in the ant manual --

"This attribute is placed in the body of the templated task using the
ant property notation - ${attribute name}. Note that is not an actual
ant property"

--will certainly confuse users and may therefore indicate a problem in

-----Original Message-----
From: Jose Alberto Fernandez [] 
Sent: Monday, October 27, 2003 5:37 AM
To: Ant Developers List
Subject: RE: Tale from the front: macrodef nesting

> From: Steve Cohen []
> I am now trying to experiment with some of the new features
> of ant 1.6.  Here's a real-world example of the difficulties 
> of trying to replace antcalls with macrodefs.
> Given the following definitions, notice that I am trying to
> nest a call to the macrodef make.precompiled.web.xml inside a 
> call to the macrodef
> This is failing because I am trying to use the ATTRIBUTE
> war.webxml inside the ELEMENT precompile which contains a 
> call to the nested macrodef make.precompiled.web.xml.

The issue is not that you are calling make.precompile.web.xml,
the issue is that you are using ${war.webxml} at a point where
there is no property (nor attribute) called war.webxml defined.
If you look at your target make.admin.war there is no property
or defined called war.webxml at that point, so you cannot just
look inside the task implementation and assume that it may exist
be the time is half way executing (that is too late, you need it
at the point of the call to

> I could easily fix this by substituting the actual value of 
> the war.webxml attribute for the ${war.webxml} token.  But 
> then I lose the advantage of defining this in a single place.
> Or I can create properties in the macrodef and pass them 
> around, but that feels wrong too.  

What you should do is define this in a property on the target
and they use that property to expand the value in all the
places that is needed.

> Maybe there should be some mechanism for allowing inner 
> macrodefs for inheriting attributes from an outer macrodef.  
> Maybe elements should be able to be defined with nested 
> attributes.  Or something.

This will not solve your problem. Your problem is that you
are using ${war.webxml} on target make.admin.war and there
is no property defined at that point in time.

Jose Alberto

> But this experience with trying to use this feature leads me 
> to the feeling that using the same notation for macrodef 
> attributes and ant properties is not a good thing.  It will 
> definitely cause confusion.  At a minimum more documentation 
> of this is required.
>     <macrodef name="make.precompiled.web.xml">
>         <attribute name="src.web.xml"/>
>         <attribute name="dest.web.xml"/>
>         <sequential>            
>             <ant antfile="${basedir}/se/build-precomp.xml"
>                  target="create.precompiled.web.xml">
>                 <property name="src.web.xml" value="${src.web.xml}"/>
>                 <property name="dest.web.xml" 
> value="${dest.web.xml}"/>
>             </ant>
>         </sequential>
>     </macrodef>
>     <macrodef name="">            
>         <attribute name="work.dir"/>
>         <attribute name="war.webxml"/>
>         <attribute name="war.basedir"/>
>         <attribute name="war.destfile"/>
>         <element name="precompile" optional="true"/>
>         <element name="assemble" optional="false"/>
>         <element name="additional" optional="true"/>
>         <sequential>
>             <delete dir="${work.dir}"/>     
>             <mkdir dir="${work.dir}/temp"/> 
>             <mkdir dir="${work.dir}/war"/> 
>             <precompile/>
>             <assemble/>
>             <replace file="${war.webxml}" 
>                      token="#build#"               
> value="${project.version}.${}.${proje}"/>
>             <war destfile="${war.destfile}"
>                  webxml="${war.webxml}"
>                  basedir="${war.basedir}">
>                 <additional/>
>             </war>
>         </sequential>
>     </macrodef>                         
>        <target name="make.admin.war"
>                depends="make.precompilation"
>            < 
>                work.dir="${dir.admin.ear}"
> war.webxml="${}/${admin.web.xml}"
>                war.basedir="${dir.admin.ear}/temp"
>                war.destfile="${dir.admin.ear}/war/${admin.war}">
>                <precompile>
>                    <make.precompiled.web.xml
> src.web.xml="${dir.src.web.xmls}/${admin.web.xml}"
>                        dest.web.xml="${war.webxml}"
>                    />
>                </precompile>
>                <assemble>
>                    <copy todir="${war.basedir}">
>                        <fileset dir="${}"/>
>                    </copy>
>                </assemble>
>            </>
>        </target>

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message