ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geoff Meakin" <>
Subject RE: If anybody is interested.. [foreach] task which doesnt run out of memory.
Date Fri, 13 Sep 2002 15:03:39 GMT
> <foreach2 param="srcfile">
>   <fileset dir="base">
>     <include name="**/*.txt"/>
>   </fileset>
>   <do>
>     <echo message="Found the following text file:
> ${srcfile}"/>
>   </do>
> </foreach2>

In the example here, the value of the property ${srcfile} will be changed
everytime the loop iterates. It isn't reset at the end of the loop (I
thought about doing that) as the property might still be useful outside the
foreach2 task, and there is no real reason to reset it, as that would give
the property scope, and properties generally dont have scope in ANT. The ANT
API still allows you to easily modify property values, even if this
functionality has been taken away from <property> and <condition>, so it
uses that mechanism to change the value of the property. Also- there really
isnt a concept of "params" as such, as there was before (i.e. passing
multiple properties to the called anttask)- because no target is being
AntCalled.. The nested tasks have the same environment as the foreach task
so they can access anything which is available.

As an alternative example, the code:
<foreach2 param="letter" list="a,b,c,d,e">
  <do><echo message="Letter ${letter}"/></do>

Will produce the following output:
Letter a
Letter b
Letter c
Letter d
Letter e

And is in effect the same as doing:
<property name="letter" value="a"><echo message="Letter ${letter}"/>
<property name="letter" value="b"><echo message="Letter ${letter}"/>
<property name="letter" value="c"><echo message="Letter ${letter}"/>
<property name="letter" value="d"><echo message="Letter ${letter}"/>
<property name="letter" value="e"><echo message="Letter ${letter}"/>

(if <property> allowed you to override the previous value that is (like in

This is because each time the <echo> task is run, (one for each letter in
the list), the value of the property
${letter} is equal to whichever letter in the list is being dealt with.

Does this help at all?

>This sounds good, but how do you handle params?  Are
>you changing properties to do this and then unsetting
>them at the end of the loop, or what?

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

View raw message