ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <qazw...@gmail.com>
Subject Re: Having problem using property to in macrodef if invoke for more than one time
Date Fri, 28 Mar 2008 03:09:53 GMT
As you've discovered: Once a property is set, it is set forever. You
can use the "var" task, but it isn't safe for parallel use. The other
way is to append the module's name onto the end of the property name.

Another solution is to use <antcall> instead of macrodef. The
<antcall> task gives you the similar power to <macrodef> but allows
you to reset property values:

Example:
<project name="myapp" default="test" basedir=".">
     <target name="test">
         <!-- Call Target <foo> twice with different parameters -->
         <antcall target="foo">
             <param name="first" value="foo_first"/>
             <param name="second" value="foo_second"/>
         </antcall>
         <antcall target="foo">
             <param name="first" value="bar_first"/>
             <param name="second" value="bar_second"/>
         </antcall>
     </target>

     <target name="foo">
         <!-- Set property "testme" and see if it changes between the
two <antcall> calls -->
         <property name="testme" value="${first}"/>
         <echo message="testme = ${testme} first = ${first} second =
${second}"/>
     </target>
</project>


Output:

test:

foo:
     [echo] testme = foo_first first = foo_first second = foo_second

foo:
     [echo] testme = bar_first first = bar_first second = bar_second

Note that the value of the property testme changed between the two
calls to <antcall>.

On Thu, Mar 27, 2008 at 1:51 AM, CheeYang Chau <cychau@gmail.com> wrote:
> Hi,
>
>  I love the macrodef task. However, it has a weakness.  We must be very
>  careful if using property within the macrodef.  I face problem with a
>  macrodef that is more complicated than the following example.  I have
>  to use dirname and condition in my macrodef, but it cause problem if I
>  invoke macrodef for more than one time as the property has been set
>  for the first time.  Here is an example that trying to replay the
>  situation I face:
>
>         <macrodef name="a">
>                 <attribute name="module"/>
>                 <sequential>
>                         <property name="myvalue" value="@{module}"/>
>                         <echo>${myvalue}</echo>
>                 </sequential>
>         </macrodef>
>
>         <target name="build">
>                 <a module="venus"/>
>                 <a module="mars"/>
>         </target>
>
>  I expect the output should be
>
>  [echo] venus
>  [echo] mars
>
>  but it turn out:
>
>  [echo] venus
>  [echo] venus
>
>  I think this is a common issue using macrodef and there are some
>  temporary solution to pass a temporary property name to the macrodef.
>  This is not feasible in my situation as I need to pass more than 5 to
>  10 properties to my macrodef.
>
>  Some other solution is using local property but I couldn't find this
>  task.  I am using ANT 1.7.0.
>
>  Any solution?  Please advice.  Thank you very much.
>
>  --
>  Best regards,
>  Chau Chee Yang
>
>  E Stream Software Sdn Bhd
>  URL: www.sql.com.my
>  SQL Financial Accounting
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message