ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pawanraj Sadhwani" <>
Subject RE: If in MacroDef?
Date Wed, 05 May 2004 07:46:50 GMT
Hi jan

Thanx for the fast reply.

i considered using antcontrib. I will be able to do it using that way.

I was wondering if it would be possible to have something cleaner like
  <callCommondo param="foo" if="foo.present" />

The macro performs certain actions on some directories... and fails in case
the directory is not present.. during build init i set properties using the
<available> task.

the idea is that developers might not have all directories on the local
machine. (hence the initial antcalls and if's)

rather than having the "checking for property" in the macro itself, i want
to call the macro only if the property is set.

This means that if i am using <if>, there will be a lot of if's. Using
foreach is something i can look into.. cuz i dont want to write 10 <if>s..
also, i putting the if. in the macro is a good idea.  thanx again


-----Original Message-----
From: []
Sent: Wednesday, May 05, 2004 1:02 PM
Subject: RE: If in MacroDef?

Is that what you want (using AntContrib)?


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

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

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

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


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

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

Total time: 0 seconds

> -----Original Message-----
> From: Pawanraj Sadhwani []
> 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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message