ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Thinking in Ant...
Date Wed, 06 Oct 2004 14:45:36 GMT
On Tue, 5 Oct 2004, Richard Russell <> wrote:

> You said: " want to express yourself in loops while Ant wants
> to work on collections."  This is most certainly true! But how do I
> express what I want to do in this particular case, as an operation
> on a collection?

Even if it isn't the right verb, a simple <copy> on your source
fileset would already do if it knew how to append - as would <concat>
with a nested <redirector>.  I'd probably prefer the <concat> approach
since an appending copy sounds strange.

> I'll explain the purpose behind what I'm doing here,


> I'm building test systems, and need to generate dataloads for a
> number of different configurations of nodes. Hence, I've written a
> template, which allows me to generate these with a few
> parameters. The dataload is compose of a bunch of files, one per
> table, which get loaded into the database by some other Ant target.

It looks as if you want to patch together the separate pieces needed
to build your data load via a combination of Ant tasks, while the "Ant
way" probably is to write a task that creates the data-loads.  Whether
you use Java to write the task or <script(def)> is up to you.

The "Ant way" as I understand it (which is just one opinion) boils
down to "if it needs some complex scripting, it is worth a task".

So instead of writing a task that you can use inside of your loop
performed by Ant, you would have written a task that gets a set of
templates and generates the data load from it.

> When deploying, I need to take a bunch of config templates from one
> place, and apply multiple configurations (mostly token filters) to
> them, and copy them to different directories on the server.


> I need, in this case, to loop through the following basic process:
> * Load properties for relevant node
> * Create filterset
> * Copy template with filters applied to destination directory

Why loop?  Once per node?  If so, a solution very similar to your
antcall within a loop solution might use <subant> with a build file
per node.  Not nice, I'll admit that.

> Of course, I could write a task that took my list of nodes as a
> collection, and iterated over it internally, but that just seems so
> wrong to me. It would mean that every time I wanted to do something
> new to a collection, I would have to write a new task, which
> basically wrapped a for loop around the task I want (which is what
> the for task does).

I'm glad you bring this up since I have the opportunity to clarify my
statement above.  I wouldn't consider a loop around a single task as
"complex scripting".  You first example, which may need to deal with
different types of nodes and templates is something which might need
to evaluate conditions in addition to loops and which may even
simplify the build file a lot (by moving logic into the task like
determining which type of node you are dealing with) with a task.

Running a single task in a loop is different.  If it is a limitation
of the task you want to run (like a task working on a single file,
that could as well work on a collection), then we should fix the task.

For the more uncommon cases there is <for>, which really isn't
anything evil.  If overused it may just lock people into a scripting
solution where a built-in set based solution exists, something like
people looping over their source files invoking <javac> on one file at
a time.  That's one of the reasons <for> is not a first class citizen
in Ant.



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

View raw message