ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geoff Meakin" <geo...@isocra.com>
Subject alternative [foreach] task with no memory problems.
Date Thu, 12 Sep 2002 16:38:14 GMT
[This message went out to ant-contrib-developers. Because of Public license
restrictions Im obliged to send this
to you as well, since it involved ant.jar]

Cheers
-Geoff

{message begins}
Hi all, I wrote a couple of days back with a request for information about
<foreach>, but have had no replies. I've gone ahead and wrote a version of
<foreach2> which doesnt use antcall, but has tasks nested in it instead. It
has turned out to be a lot quicker.
I am of course aware that ant-contrib is copyright and protected and stuff
like that, and I've no intention of cutting in on anyone's ride or however
the saying goes, especially the original author of <foreach>, so please
dont think Im interfering at all. I've attached the source and .jar file to
this email in case anyone's interested, and listed some of the problems I
came across below. If anybody particularly wants me to finish this off, and
resolve the problems then I'm happy to do it- but otherwise I wont, because
I've done what I needed to get my own project working (also I'm not really a
developer, just a lousy tester :) ) The good news is there doesnt seem to be
any memory problems, and it runs very smoothly.

I asked if there were any foreseen problems as to why the existing <foreach>
was done the way it was. Turns out there's a very good reason and that is
that tasks can't be executed twice with different property settings as
org.apache.tools.ant.RuntimeConfigurable's setProxy() method is not public.
Personally I think it should be as this allows "RepeatableTasks". In actual
fact I think its security is package, so if foreach2 was to become part of
the same package as ant core then this problem wouldnt really arise.

Unfortunately also, when ProjectHelper configures a tasks environment (aka
property settings), it actually overwrites the attribute strings, so you
lose the information about which property the user specified in their XML.
I've therefore added a rememberAttributes() and resetAttributes() to
org.apache.tools.ant.taskdefs.Sequential in order that I am able to reset
them each time <foreach2> iterates, which is a necessary step. Ideally these
methods should be on Task (or even RuntimeConfigurable), and NOT on
Sequential, however I dont need to do this at this stage.

**Because of the way the unix and windows batch scripts for ant work, they
form ANTs classpath alphabetically, hence by calling the jar file attached
"antcontrib.jar" (without the slash), I've ensured that the overridden forms
of Sequential and RuntimeConfigurable appear in the classpath before the
actual ANT ones. This is a hack I know ;) however it provides you with a
simple JAR file which alters parts of ANT as it requires.

Obviously this foreach task is no good unless some changes are made in
ANTcore.

Here is some sample code:

<foreach2 param="foo">
  <fileset dir="c:\ant">
    <include name="**/*.*"/>
  </fileset>
  <do>
    <echo message="Found: ${foo}"/>
  </do>
</foreach2>

Problems:

Not really problems, but considerations:
Currently, resetting Attributes happens recursively only through
Sequentials. Thus for all Tasks which are not TaskContainers (except
Sequential), the nested Tasks will not be reset. I haven't done this cos I
haven't needed to for my situation but I think this could be done easily.

I will post a similar email to the ANT developers list, since it involves
their code as well, and I should do under license requirements.

Cheers
-Geoff

Mime
View raw message