ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <>
Subject Re: Repeating a task x times
Date Wed, 16 Aug 2006 12:13:05 GMT
I wrote something like this a while back using ant contrib and math...  
Here ya go:

        name        = "for"
        description = "This implements a for loop with starting and 
ending values for the loop.">

        <attribute  name = "property"  description = "The name of the 
property that will contain the current value of the loop."/>
        <attribute  name = "start"  default = "1"  description = "The 
start value of the loop."/>
        <attribute  name = "end"    description = "The end value of the 
        <attribute  name = "inc"    default = "1"  description = "The 
value to increment (or decrement) when looping."/>

        <element  name = "loop"  implicit = "true" description = "The 
enclosing block - just like ant contrib's for/sequential."/>

            <var  name = "@{property}"  value = "@{start}"/>

                    <equals  arg1 = "${@{property}}"  arg2 = "@{end}"/>


                    <math  result = "@{property}"  datatype = "int" 
operation = "+"  operand1 = "${@{property}}"  operand2 = "@{inc}"/>

                    <for  property = "@{property}"  start = 
"${@{property}}" end = "@{end}"  inc = "@{inc}">

This shows how to use it:

        <for  property = "TEST_FOR"  start = "0"  end = "5">

The above would loop starting at 0 and ending at 5...each iteration 
being stored in the property named "TEST_FOR"

Hope that helps...


Its recursive and fails out after 400+ iterations.  But for most uses it 
should be sufficient...

There is also another project out there that has this 
functionality...jwaretechniques but I dont have the URL readily handy 
right now...

Daniel Smith wrote:
> 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:
> For additional commands, e-mail:

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate
Chief Architect JavaPIM

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

View raw message