We had the same requirement at my client site and so I created a slighly 
modified version of the ant-contrib <for> (or was it <foreach>) that accepts 
two optional attributes a listBegin and listEnd and then it constructs a string 
"list" that is uses for the iteration.
 
I can send you a copy of it (and test cases) just send me an email,
 
Ninju
 




----- Original Message ----
From: Guru Balse <[EMAIL PROTECTED]>
To: Ant Users List <user@ant.apache.org>
Sent: Wednesday, June 7, 2006 7:47:52 PM
Subject: Re: Implementing a loop in ANT


Thanks, Scot.  You illustrate the problem quite well.  The problem is 
that N is defined as 9, but the loop only goes through 5 iterations :-(

Therefore unless we create a string on the fly using ${N} i.e. we create 
${list} as "1,2,3,4,5,6,7,8,9" using java script (or other means) and 
then use <for list="${list}">, this will not work.

(Sigh!) I suppose something could be hacked together using <var> and 
<math> (see 
http://ant-contrib.sourceforge.net/tasks/tasks/math_task.html) ... I was 
hoping for a more elegant solution :-)

Scot P. Floess wrote:
> Sorry, my boldfaced was turned into *YYY*
>
> Let me repost:
>
> <project  name = "test">
>  <taskdef  resource = "net/sf/antcontrib/antlib.xml"/>
>
>  <for list="1,2,3,4,${N}" param = "val">
>      <sequential>
>          <echo message = "val = @{val}"/>
>      </sequential>
>  </for>
> </project>
>
> Command line:
>
> ant -DN=9
>
> Buildfile: build.xml
>     [echo] val = 1
>     [echo] val = 2
>     [echo] val = 3
>     [echo] val = 4
>     [echo] val = 9
>
> BUILD SUCCESSFUL
> Total time: 2 seconds
>
>
> Scot P. Floess wrote:
>> Guru:
>>
>> You should be able to do this like:
>>
>> <for list="1,2,3,4,${N}">
>>
>> Of course, assuming u do something like:
>>
>> ant -DN=5 -f <your build.xml>
>>
>> So, I wrote a simple test script as follows:
>>
>> <project  name = "test">
>>  <taskdef  resource = "net/sf/antcontrib/antlib.xml"/>
>>
>>  <for list="1,2,3,4,$*{N}*" param = "val">
>>      <sequential>
>>          <echo message = "val = @{val}"/>
>>      </sequential>
>>  </for>
>> </project>
>>
>> When running I did/got this:
>>
>> /home/sfloess/development/help/ant/guru> ant *-DN=9*
>> Buildfile: build.xml
>>     [echo] val = 1
>>     [echo] val = 2
>>     [echo] val = 3
>>     [echo] val = 4
>>     [echo] val = 9
>>
>> BUILD SUCCESSFUL
>> Total time: 2 seconds
>>
>> Hope that helps...
>>
>> Scot
>>
>>
>>
>>
>>
>> Guru Balse 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]
>>>

Reply via email to