ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <>
Subject Re: 'The Ant Way' for iterations?
Date Mon, 14 Apr 2003 04:58:07 GMT
On Sun, 13 Apr 2003 10:40 am, Todd Ackman wrote:
> Hi ant gurus
> Is it to use the "foreach" task of ant-contrib?  I didn't think so since
> ant-contrib is not part of the core ant distribution.  Am i wrong about
> this?
> Is it to write a custom task that knows how to deal with the iteration
> itself?
> Is it something else?

The answer is to do whatever you find easiest :-)

Of course, easy means different things to different people - easy to develop, 
easy to test, easy to read, easy to maintain, etc. You have to decide the 

The <foreach> task is fine - I use it when I need it. Why isn't it in the Ant 
core? It is probably because it isn't always the best way to do things - Ant 
is not intended to provide a general purpose scripting language - it is 
supposed to be a description of your build process. Of course that's an 
overly idealistic goal but it guides, to some extent, what is in Ant. OTOH, 
the core has had facilities added over time to support tasks such as foreach, 
if, etc, try-catch. 

A custom task is worth it if you are going to use it in multiple places. Also, 
if you start to use a lot of the logic tasks such as above, you might ask 
yourself whether it is easier to maintain that logic in Java rather than XML. 
Again that is up to you. A custom task can make your build file cleaner, for 
sure, as you can hide the details in your task. You will find tasks in Ant's 
core that support iteration (apply) explicitly or just by the fact that they 
operate on collections (filesets, etc).

The middle ground might be to use the <script> task.


Conor MacNeill

View raw message