ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allwicher, Klaus" <Klaus.Allwic...@nuance.com>
Subject RE: Repeating a task x times
Date Wed, 16 Aug 2006 07:45:05 GMT
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:dlsmith@rice.edu] 
> 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: user-unsubscribe@ant.apache.org For 
> additional commands, e-mail: user-help@ant.apache.org
> 

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


Mime
View raw message