ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Cohen" <>
Subject Tale from the front: macrodef nesting
Date Sun, 26 Oct 2003 22:55:38 GMT
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.

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.

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.

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"/>
            <ant antfile="${basedir}/se/build-precomp.xml"
                <property name="src.web.xml" value="${src.web.xml}"/>
                <property name="dest.web.xml" value="${dest.web.xml}"/>

    <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"/>
            <delete dir="${work.dir}"/>     
            <mkdir dir="${work.dir}/temp"/> 
            <mkdir dir="${work.dir}/war"/> 
            <replace file="${war.webxml}" 
                     token="#build#"               value="${project.version}.${}.${}"/>
            <war destfile="${war.destfile}"

       <target name="make.admin.war"
                   <copy todir="${war.basedir}">
                       <fileset dir="${}"/>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message