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 make.se.war.

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"/>
        <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="make.se.war">            
        <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}.${project.maintenance.build}.${project.fix.build}"/>
            <war destfile="${war.destfile}"
                 webxml="${war.webxml}"
                 basedir="${war.basedir}">
                <additional/>
            </war>
        </sequential>
    </macrodef>                         


       <target name="make.admin.war"
               depends="make.precompilation"
           <make.se.war 
               work.dir="${dir.admin.ear}"
               war.webxml="${dir.build.precomp.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="${dir.build.war.precomp}"/>
                   </copy>
               </assemble>
           </make.se.war>
       </target>


Reply via email to