Write you own iterator for the <for> loop
<for param="i" >
<numbergen start="1" end="15" />
<sequential>
<echo level="info" message="@{i}" />
</sequential>
</for>
produces:
1
2
...
13
14
15
And here a simple implementation (of course you must add an antlib.xml to
your jar)
public class NumberGenerator implements Iterator {
long start = 0;
long incr = 1;
long end = -1;
long current = start;
public void setStart(String start) {
this.start = Long.parseLong(start);
current = this.start;
}
public void setIncrement(String incr) {
this.incr = Long.parseLong(incr);
}
public void setEnd(String end) {
this.end = Long.parseLong(end);
current = this.start;
}
public Iterator iterator() {
return this;
}
public boolean hasNext() {
return (end==-1 || current<=end);
}
public Object next() {
if (hasNext()) {
Long next = new Long(current);
current+=incr;
return next;
}
return null;
}
public void remove() {
}
}
Kind regards
Klaus Allwicher
> -----Original Message-----
> From: Daniel Smith [mailto:[EMAIL PROTECTED]
> Sent: 15 August, 2006 20:27
> To: Ant Users List
> Subject: Repeating a task x times
>
> I'm interested in writing a script that repeats some task a
> user- specified number of times. This is useful where the
> behavior of JUnit tests is randomized (explicitly or, in this
> case, due to concurrency irregularities), and a test sample
> of size larger than 1 is needed.
>
> The best solution we've been able to come up with is the
> "for" task from ant-contrib. Unfortunately, "for" iterates
> over lists (or tokenized strings), not numbers. So we can do
> something like this:
>
> > ant -Drepeat="1,2,3" sometarget
>
> <target name="sometarget">
> <for list="${repeat}>
> (do something)
> </for>
> </target>
>
> Clearly, this isn't ideal. I might explore doing something
> with the "math" task in ant-contrib. What other
> recommendations do you have?
>
> -Dan
>
>
> ---------------------------------------------------------------------
> 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]