ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bailey, Darragh" <>
Subject RE: Better alternative than using foreach, for and if/then/else?
Date Wed, 05 May 2010 16:10:41 GMT

> -----Original Message-----
> From: Peter Reilly [] 
> Sent: 05 May 2010 14:46
> To: Ant Users List
> Subject: Re: Better alternative than using foreach, for and 
> if/then/else?
> You need to use ant 1.8 and the <local> task.
> <local> declares that a property is local to the current scope,
> as defined by the enclosing <target> or <seqential>
> see:
>   <for list="${kernel.currver.variants}" param="kernel.variant"
> delimiter=" " trim="true">
>       <sequential>
>         <local name=""/>
>         <local name=""/>
>         <if>
>           <equals arg1="@{kernel.variant}" arg2='""' />
>          <then>
>             <property name=""
> location="/lib/modules/${kernel.version}/build" />
>             <property name=""
> location="${}/output/${kernel.version}" />
>           </then>
>           <else>
>             <property name=""
> location="/lib/modules/${kernel.version}@{kernel.variant}/build" />
>             <property name=""
> location="${}/output/${kernel.version}@{kernel.variant}" />
>           </else>
> ...
> Peter

Was aware of the local task, but haven't tried switching to Ant 1.8 to be able to use it just

My main concerns at the moment are the following:
1) Is for/foreach the only real option for what I'm attempting to accomplish here in building
multiple end targets based on the contents of properties? Is looping over the property contents
using those two tasks the only way in Ant, or is there another way to allow Ant to see a variable
list of sub-targets to be run depending on property contents? In make I had rule patterns
and eval to be able to expand to give a list of targets, in Ant I have ???

I spotted a mail from yesterday to another person using for/foreach suggesting using xslt
to generate a build file and execute it, "A trick which I have learned and used myself is
to generate on the fly a small build file using xslt and invoke it using <ant/>". I've
yet to look at this closely.

2) Is there a better way to pass an empty string in and append it to the properties above,
rather than requiring an if/then/else construct to set properties? Right now, if I don't use
the if/then/else, the directory path that gets resolved to is /lib/modules/2.6.18-194.el5""/build,
which is clearly wrong.

Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 

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

View raw message