You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Daniel Nehren <ne...@earthlink.net> on 2003/08/15 02:12:00 UTC

runtime task attributes modification

Hi guys.
 
I am writing a task that will iterate thorough all the sub-directories
in a directory and executing a certain number of tasks. I could not find
any task out there that does that. There are a few complication with
this task and wanted to get some input and/or advice.
 
I want to be able to support a certain number of tasks like javac, ant,
jar, etc. Since Properties are immutable I cannot use them to identify
the current dir so I use an identifier for relative paths in my task
assignable as an attribute,  for example relpathid="@@@". So, if I have
a javac task where srcDir="@@@/src", during the execute of my task  I
will replace the @@@ with the subdirectory name in the current
iteration. I will do that for every attribute in the task that
identifies paths. 
 
The problem I am having is that for, example in javac there is no way (
that I could find) to completely replace the srcDir, but only to add to
it. What I ended up doing was create a brand new javac task and copying
all the attributes, with the path modification over and then performing
the new task. I have only done javac right now but I suspect that I will
find other tasks like that and will end up writing a bunch of code for
each task I want to support. 
 
It started dawning on me that maybe, the modification of tasks
attributes at runtime is something that might not really be encouraged.
Is that so? Is there a way around this problem? I see that for destDir
javac uses files so that can be replaced but this is not the case for
paths.
 
What do you think about the idea overall? I have a simpler version that
only supports the ant task, and we use it in various places. Isn't this
something that could be useful to everybody?
 
Please, anybody who cares to comment, please do so.
 
Thanks a lot,
 
 
Daniel Nehren

Re: runtime task attributes modification

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 14 Aug 2003, Daniel Nehren <ne...@earthlink.net> wrote:

> I am writing a task that will iterate thorough all the
> sub-directories in a directory and executing a certain number of
> tasks. I could not find any task out there that does that.

To a certain degree <apply> does, as does the new (only in CVS)
<subant/>.  But both are specialized to do <exec/> and <ant/>
respectively.

ant-contrib's <foreach/> does what you want by invoking a <target>
that can contain arbitrary tasks passing the directory as parameter.

The brand new <macrodef/> may be an inspiration to see how you can do
what you want in Ant 1.6 - and certainly Peter Reilly's in-house,
yet-to-be-published new <foreach/> will be exactly what you want.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org