ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: If in MacroDef?
Date Wed, 05 May 2004 07:31:45 GMT
Is that what you want (using AntContrib)?

Jan


<?xml version="1.0" encoding="ISO-8859-1"?>
<project>

  <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>  

  <macrodef name="callCommondo">
    <attribute name="param"/>
    <sequential>
      <if>
        <isset property="@{param}.present"/>
        <then>
          <echo>doing @{param}</echo>
        </then>
      </if>
    </sequential>
  </macrodef>

  <for list="do1,do2" param="kind">
    <sequential>
      <callCommondo param="@{kind}"/>
    </sequential>
  </for>

</project>


C:\TEMP>ant -Ddo2.present=true
Buildfile: build.xml
     [echo] doing do2

BUILD SUCCESSFUL
Total time: 0 seconds
C:\TEMP>ant -Ddo2.present=true -Ddo1.present=true
Buildfile: build.xml
     [echo] doing do1
     [echo] doing do2

BUILD SUCCESSFUL
Total time: 0 seconds



> -----Original Message-----
> From: Pawanraj Sadhwani [mailto:pawanraj@elitecore.com]
> Sent: Wednesday, May 05, 2004 9:21 AM
> To: 'Ant Users List'
> Subject: If in MacroDef?
> 
> 
> Hi,
> 
> I have a set of tasks repeating in the build file. uptil ant 
> 1.5 i was using
> the antcall with a parameter passed to a common task i had written.
> 
> In case of that target, i was using a if="foo" to allow for 
> conditional
> execution.
> 
> can similar thing be achieved using a macro? I refactored the 
> common task
> into a macro. now, when i call the macro, i would like an 'if' for the
> execution. how to do it?
> 
> code snippet is:
> 
> <target name="do-all">
>   <antcall target="do1" />
>   <antcall target="do2" />
> </target>
> 
> <target name="do1" if="do1.present">
>   <antcall target="commondo">
>     <param name="foo" value="1" />
>   </antcall>
> </target>
> 
> <target name="do2" if="do2.present">
>   <antcall target="commondo">
>     <param name="foo" value="2" />
>   </antcall>
> </target>
> 
> I could achieve what i want to by keeping antcalls in do-all 
> and using macro
> in do1 and do2.
> 
> However, I have a lot of antcalls in do-all which i dont like. Is it
> possible to use if in the macro so i could replace ant-calls in do-all
> target?
> 
> Thanx
> 
> Pawan
> 
> 

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