ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guru Balse <guru.ba...@oracle.com>
Subject Re: Implementing a loop in ANT
Date Thu, 08 Jun 2006 00:47:52 GMT
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: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message