ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Moriarty" <>
Subject RE: [PATCH] PropertyCopy and Foreach (NEW OPTIONAL TASKS)
Date Fri, 21 Sep 2001 19:22:40 GMT

I was also wishing for a "foreach", but decided it might not be a good
idea and didn't ask for it because it is a programming construct.

The docs say ant is not a scripting language, and I like that it's not.
It describes how to build something task by task, but it's my feeling
that if any scripting like a "foreach" is needed, one should probably
create a Task to do it.  If they start adding programming construct
functionality to the ant core, then build files will start looking like
a script, in which case why not use bash or tcsh or something. (and
don't say cross platform, because it's as easy to make those cross
platform anymore w/ cygwin, etc...).

It turned out in my case that writing my own Tasks was actually much
more versatile and it kept the build.xml file clean and straight
forward.  In general, I just extend the Task I would otherwise put in a
foreach loop.  I add any specialized parameters, and call
"super.execute()" method inside my subclass.  The advantage is that you
can do anything you want with the parameters before calling execute()
(in most cases, sometimes the core API keeps the super class attributes
private and doesn't provide full access by other means, which is very
limiting if you need that kind of access).  

I'm not totally sold on excluding "foreach" since I could just opt not
to use it, but I do think it would set the stage for making build.xml
files pretty ugly and script like, and deter people from writing their
own specialized Tasks (which, imho, is one of the highlights of using

Brian Moriarty
Polexis, Inc.
2815 Camino del Rio South
San Diego, CA 92108
transforming data into knowledge

-----Original Message-----
From: Alejandro Abdelnur []
Sent: Friday, September 21, 2001 11:21 AM
Subject: Re: [PATCH] PropertyCopy and Foreach (NEW OPTIONAL TASKS)


i've been there already, submitted code doing that, it has been

it is not the first time, or second time, that these features are
proposed. i
think the the folks driving the evolution of ant should start
these features again, they should listen a little more of what


for embedded properties i modified the project helper, so you can use
variables "a.${b}.c" everywhere.

for looping i've implemented the "xantcall" target, extending the
target that supports iterations:

    <xantcall target="TARGET" iterate="LIST" iterator="VAR"/>

where VAR is the name of the variable taht will have the element of the
current iteration.

you can find the code in the archives.



Matthew Inger wrote:

> attached are two useful tasks i have written, that would
> be helpful to be put into the next release:
> PropertyCopy - double dereferencing (ie. ${a.${b}.c})
>   this essentially takes the "from" attribute and treats
>   it as a property name.  It gets the value of that property
>   and puts it in the property given by the "name" attribute.
>   It's useful when you have property names that follow a certain
>   pattern with some identifier in it (ie. org.TEST.server)
>   ex. <propertycopy name="NewVar" from="a.${b}.c" />
> Foreach - relatively self explanatory
>   ex. <foreach list="${items}" target="callMe"
>                param="item" delimiter="," />
> I'm sure there are foreach tasks floating around, but
> while i'm posting propertycopy i might as well post
> the foreach task as well.
> --
> Matt Inger (
> Sedona Corporation
> 455 S. Gulph Road, Suite 300
> King of Prussia, PA 19406
> (484) 679-2213
> "Self-respect - the secure feeling that no one,
>  as yet, is suspicious." -H.L. Mencken
>                         Name:
>    Type: text/x-java
>                     Encoding: 7bit
>                    Name:
>    Type: text/x-java
>                Encoding: 7bit

View raw message