I have had a quick look at this.

It appears that the attributes as local properties
patch

http://issues.apache.org/bugzilla/show_bug.cgi?id=23942

causes macrodef to behave in the way you expect.

A cut-down version shows this.

<project>
  <macrodef name="inner">
    <attribute name="a"/>
    <attribute name="b"/>
    <sequential>            
      <echo> name="a" value="${a}"</echo>
      <echo> name="b" value="${b}"</echo>
    </sequential>
  </macrodef>

  <macrodef name="outer">            
    <attribute name="work"/>
    <attribute name="play"/>

    <element name="precompile" optional="true"/>
    <element name="additional" optional="true"/>
    
    <sequential>
      <precompile/>
      <additional/>
    </sequential>
  </macrodef>
     
  <target name="test.outer">
    <outer work="this is work" play="this is play">
      <precompile>
        <inner a="${work}" b="${play}" />
      </precompile>
    </outer>
  </target>
</project>


Ant 1.6  currently outputs:
test.outer:
     [echo]  name="a" value="${work}"
     [echo]  name="b" value="${play}" 

With the patch
this gets output:

test.outer:
     [echo]  name="a" value="this is work"
     [echo]  name="b" value="this is play" 

Peter

On Sunday 26 October 2003 22:55, Steve Cohen wrote:
> 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>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to