Here is a example (beanshell rocks!):

<project name="loop" xmlns:ac="antlib:net.sf.antcontrib">
   <script language="beanshell">
       import java.util.Iterator;
       public class Loop implements Iterator {
           private int begin = 0;
           private int end   = 10;
           private int curr = 0;
           public void setBegin(int b) {
              begin = b;
              curr = b;
           }
           public void setEnd(int e) {
              end = e;
           }
           public Iterator iterator() {
               return this;
           }
           public boolean hasNext() {
               return curr &lt; end;
           }
           public Object next() {
               Integer ret = new Integer(curr);
               curr = curr + 1;
               return ret;
           }
           public void remove() {
           }
       }
       project.addDataTypeDefinition("loop", Loop.class);
   </script>

   <ac:for param="val">
       <loop end="5"/>
       <sequential>
           <echo message = "val = @{val}"/>
       </sequential>
   </ac:for>
</project>

This outputs:
C:\work\test>ant -f for.xml
UserLib is C:\Documents and Settings\reilly\.ant\lib
Buildfile: for.xml
    [echo] val = 0
    [echo] val = 1
    [echo] val = 2
    [echo] val = 3
    [echo] val = 4

BUILD SUCCESSFUL

Peter
On 6/7/06, Dominique Devienne <[EMAIL PROTECTED]> wrote:

Ant-Contrib's <for> accepts any type which exposes an iterator()
method I believe, so you'd have to write a Java task or <scriptdef> to
create such an <integer-range> type.

You could also try a recursive <macro> or <antcall> (with proper
stopping condition ;-) that writes the numbers to a file, and then
<loadfile> it.

Using a little <script> to generate the series in a property would
probably be easier though. --DD

On 6/7/06, Guru Balse <[EMAIL PROTECTED]> wrote:
> I am sure this question has been asked before, and I could not see any
> reasonable answer in the archives.  How can I implement a loop in ANT
> without using scripts?  For example, if I want to call a certain target
> N times, how can I do it?
>
> Using ant-contrib is OK.  Of course, something like <for
> list="1,2,3,4,5,6,...,N"> would work but I want N to be a property that
> can be specified in the command line.
>
> Thanks in advance for your suggestions.
>
>  - Guru Balse
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to