ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: Anything like a "<foreach>" task ?
Date Tue, 15 Apr 2003 15:06:14 GMT
Instead of going the <foreach> route, would you care to elaborate what this
process of calling MyMainClass on every subdir does? Looks quite unusual
from my perspective, and I somehow suspect another approach could be used...

Also, you should check out <apply type="dir"/>. This does an implicit loop
on a fileset (a pseudo-<dirset> in this case, thanks to type="dir"), which
quite often is better than using <foreach> (which many people jump to
incorrectly. It's useful in some cases, but not that often IMHO).

Regards, --DD

-----Original Message-----
From: Rich Wagner [] 
Sent: Monday, April 14, 2003 1:50 PM
Subject: Anything like a "<foreach>" task ?

Hi Folks,

I've been converting several Windows batch and UNIX shell scripts to Ant 
build files (quite successfully, I might add: platform independence is a 
good thing).  But the last script includes a "for" loop that I don't know 
how to convert: it's basically doing something like this pseudo-code:

    $parentDir := "C:\x\y\z"
    foreach $subdir in $parent\*
        java -classpath ... MyMainClass $subdir

I know I could write my own custom "foreach" task, and I know I could write 
a simple Java "main" wrapper which invokes "MyMainClass#main" for each 
subdirectory in a given parent, but...

I was hoping Ant provides an "off-the-shelf" way of expressing what I need 
to do.  Any help ?  I've searched the Ant manual and haven't found what I'm 
looking for: have I missed something ?

Many thanks,
Rich Wagner

P.S.  I've only been using Ant for a few weeks, but I've quickly become 
quite a fan.  It's WAAAYYY better than "make".

But beyond being a great replacement for "make", I've been able to replace 
lots of redundant script pairs, i.e. (1) I used to have functionally 
equivalent pairs of Windows 98 and Windows NT scripts with stupid little 
variations like "deltree" vs "rmdir": converting those pairs to single Ant 
files solves that, and (2) likewise for functionally equivalent Windows and 
UNIX script pairs...  Many thanks to all those involved in providing this 
great tool...

View raw message