ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pawanraj Sadhwani" <pawan...@elitecore.com>
Subject RE: If in MacroDef?
Date Wed, 05 May 2004 08:21:13 GMT
thanx jan

i think i will go with antcontrib and use the if in the macrodef. :-).

The reason i wanted to avoid using it that way is because, what if the
directory name changes? i am passing the directory name as the parameter to
the macro. corresponding property setting will have to be changed as well.

Anyway... I guess i will make a note of it, and remember to do that.. i dont
think source package directory names are going to change so late in the
projcet anyway :-)

BTW.. wouldnt it be nice to have an if and unless attribute during
macro-calls also? what say?

Pawan

-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
Sent: Wednesday, May 05, 2004 1:40 PM
To: user@ant.apache.org
Subject: RE: If in MacroDef?


If you always have
  <callCommondo param="FOO" if="FOO.present" />
  <callCommondo param="BAR" if="BAR.present" />
it would be cleaner only to pass the FOO/BAR and let the macrodef do the
tests.
Of course the macrodef can do the availability checks - but be aware that
properties are immutable! For some checks it would be useful to store an
interim value.
That can´t be done with properties.

There is a patch on bugzilla according to "local variables" inside macrodef.
(or is that part of the regular source tree, Peter?)

Or you can use the <variable> task from AntContrib - especially if you
already use AC.


For a more "complex" use of macrodef see Ant´s own buildfile.
A lot of selectors are defined to be used if special environment settings
are present
(most of them depend on a 3rd party library). On line 834 a macrodef defines
the <optional-jar> which
is used to build most of the ant-*.jar´s in the lib directory.


Jan


> -----Original Message-----
> From: Pawanraj Sadhwani [mailto:pawanraj@elitecore.com]
> Sent: Wednesday, May 05, 2004 9:47 AM
> To: 'Ant Users List'
> Subject: RE: If in MacroDef?
>
>
> 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
>
> Pawan
>
>
> -----Original Message-----
> From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
> Sent: Wednesday, May 05, 2004 1:02 PM
> To: user@ant.apache.org
> Subject: RE: If in MacroDef?
>
>
> 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
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


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


Mime
View raw message