ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Russell" <>
Subject Re: Thinking in Ant...
Date Tue, 05 Oct 2004 11:11:11 GMT
Hi Stefan, ant-users,

Thanks for your response. 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? I'll explain the 
purpose behind what I'm doing here, as it may just be that the way I've 
framed the problem is fundamentally loopy (pun intended). Mind you, some 
of the loopiness may be legacy that I can't avoid...

Our system is tree-like, in that it has a parent node, and a number of 
child nodes, each of which can have child nodes. Each node has a number of 
users, and the child nodes are seen as a particular class of users. Users 
are represented by some records in a number of tables in the database. 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.

A (significantly) simplified view of my template is that there are two 
node            -- templates for any node
parent          -- templates for data to be added to parent node for each 
child node

An example usage might look conceptually like this:

root            = node(root)+parent(childA)+parent(childB)
childA          = node(childA)
childB          = node(childB)

I currently do this by firstly doing the root, then looping through each 
child, doing itself followed by adding the data to that childs' parent.

In more detail, I might have a USERS table, and hence, two files:

node/USERS      -- one line per user (@nodename@001-@nodename@999)
parent/USERS    -- one template line (@childname@)

Obviously, the root node gets users called root001-root999, as well as 
childA and childB, whereas childA gets users called childA000-childA999...

The situation is made more complicated because there are a number of 
different types of dataloads, some with more files than others, and I'd 
really rather generalise and use parameters than have different targets 
for each possible dataload, listing the files one by one (that sounds 
error-prone, not to mention tedious).

Now, I'm quite happy to change my templates, though I can't change the 
structure of the data I need to generate. Is there a more Ant-friendly way 
to do this without using loops? Perhaps one might say that this isn't 
really in Ant's problem domain, and I really am trying to drive in nails 
with a screwdriver... However, I still need to be able to generate these 
on both Unix and Windows, and it really needs to be able to be at least 
driven from Ant, as it's part of our build/deploy process.

A second example, which is (to my mind, at least) more clearly in Ant's 
problem domain is that of configuring the actual nodes themselves (ie the 
code and config files). 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. 
It's similar to the above, but simpler, as there is no appending.

Templates look like this:

node            -- templates for any node

And example usage may look like this:

root            = node(root)
childA          = node(childA)
childB          = node(childB)

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

Here again, I come across the lack of looping and the problem of immutable 
variables. I do this, by the way, by using a single loop with an antcall 
inside it. I can think of better ways, but none that involve thinking in 
terms of "collections". 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). This approach simply can't be right -- it goes against all 
principles of re-use, modularity, and discards what is surely one of the 
main strengths of a computer (the ability to do repetitive tasks with 
little effort on the part of the user). Surely, when you have the 
primitives already, there should be a way to combine them relatively 

If someone could point me in the right direction here, I'd be very 


Richard Russell 
Deutsche Bank AG London 
Global Markets Customer Solutions
Office: +44 (0)20 7545 8060
Mobile: +44 (0)79 0661 2237

Stefan Bodewig <>
10/04/2004 09:11 PM
Please respond to "Ant Users List"

        Subject:        Re: Thinking in Ant...

On Mon, 4 Oct 2004, Richard Russell <> wrote:

> I run into these issues so regularly that I cannot help but assume
> that I am simply not 'thinking in Ant', and am therefore fighting
> against its design rather than working with it.

Sounds like it.

One of the major points seems to be that you want to drive the
execution instead of having ant make the decisions.  You usually don't
code loops in Ant but use a task that will implicitly perform the

> for file in `ls ${dir1}/*.DAT`; do 
>   cat ${dir1}/${file} | sed -e 's/@parameter@/value/' >>
>   ${dir2}/${file}
> done

translates into a single <copy> with a nested <replactokens> if it
wasn't for the second ">".  There isn't any append mode in <copy>.  Is
this a real world requirement?  Must be, otherwise you wouldn't have
written a task for it.

If you can express it as a shell script, you can always use <exec> or
<apply>, but then your platform independence has gone.

Ant really isn't the best fit if your process is extremely procedural,
it usually isn't even though your experience says it is in you case.

The main mismatch I really see is that you want to express yourself in
loops while Ant wants to work on collections.


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

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

View raw message