You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Guru Balse <gu...@oracle.com> on 2006/06/07 20:17:47 UTC
Implementing a loop in ANT
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
Re: Implementing a loop in ANT
Posted by Steve Loughran <st...@apache.org>.
Dominique Devienne wrote:
> Ant-Contrib's <for> accepts any type which exposes an iterator()
oh, you have just given me an idea for a devious little java1.5 class.
something that implements Iterable, for use in the fancy for loops, but
which reflects onto a class passed in and calls the iterator() method
even if it aint from an Iterable interface. That I shall have to do..
for(Resource r:new IterableBridge<Resource>(fileset)) {
log(r.toString());
}
Can't put it in the ant source tree, of course, as it would only compile
on java1.5.
-Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by Guru Balse <gu...@oracle.com>.
Thanks to Dominique Devienne, Peter Reilly, Ninju Bohra, Scot P. Floess,
Ben Stringer, and Steve Lughran for giving me such good ideas on
achieving the loop functionality. I will get back to individuals if I
need further help.
The Ant Users List rocks!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by Peter Reilly <pe...@gmail.com>.
Here is a example (beanshell rocks!):
<project name="loop" xmlns:ac="antlib:net.sf.antcontrib">
<script language="beanshell">
import java.util.Iterator;
public class Loop implements Iterator {
private int begin = 0;
private int end = 10;
private int curr = 0;
public void setBegin(int b) {
begin = b;
curr = b;
}
public void setEnd(int e) {
end = e;
}
public Iterator iterator() {
return this;
}
public boolean hasNext() {
return curr < end;
}
public Object next() {
Integer ret = new Integer(curr);
curr = curr + 1;
return ret;
}
public void remove() {
}
}
project.addDataTypeDefinition("loop", Loop.class);
</script>
<ac:for param="val">
<loop end="5"/>
<sequential>
<echo message = "val = @{val}"/>
</sequential>
</ac:for>
</project>
This outputs:
C:\work\test>ant -f for.xml
UserLib is C:\Documents and Settings\reilly\.ant\lib
Buildfile: for.xml
[echo] val = 0
[echo] val = 1
[echo] val = 2
[echo] val = 3
[echo] val = 4
BUILD SUCCESSFUL
Peter
On 6/7/06, Dominique Devienne <dd...@gmail.com> wrote:
>
> Ant-Contrib's <for> accepts any type which exposes an iterator()
> method I believe, so you'd have to write a Java task or <scriptdef> to
> create such an <integer-range> type.
>
> You could also try a recursive <macro> or <antcall> (with proper
> stopping condition ;-) that writes the numbers to a file, and then
> <loadfile> it.
>
> Using a little <script> to generate the series in a property would
> probably be easier though. --DD
>
> On 6/7/06, Guru Balse <gu...@oracle.com> 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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Re: Implementing a loop in ANT
Posted by Dominique Devienne <dd...@gmail.com>.
Ant-Contrib's <for> accepts any type which exposes an iterator()
method I believe, so you'd have to write a Java task or <scriptdef> to
create such an <integer-range> type.
You could also try a recursive <macro> or <antcall> (with proper
stopping condition ;-) that writes the numbers to a file, and then
<loadfile> it.
Using a little <script> to generate the series in a property would
probably be easier though. --DD
On 6/7/06, Guru Balse <gu...@oracle.com> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by "Scot P. Floess" <fl...@mindspring.com>.
They do, but unfortunately not exactly what Guru needs. They support
for-loops over lists or file sets. Really, he needs something like:
<for lower = "1" upper = "100">
...
</for>
I'm trying to figure out a way to do this using ant/ant-contrib but its
not readily apparent to me (I though it'd be trivial) to make it happen.
What I really need is some form of while loop. I considered using
recursion...but I could see some possible issues with arbitrarily large
iterations (not sure why one would do so...but nonetheless).
Anyway, really I don't think he wants to pre-compute some large list
with a delimiter and then use <for> over the list... At least I don't
want to do that as a solution ;) Yes, I know one could possibly use a
<script>. I am trying to not do that anyway (for reasons related to my
open source project - long story)...
Scot
dbrosius@baybroadband.net wrote:
> ant-contrib.sourceforge.net has some tasks to do this.
>
>
>
>
> -----Original Message-----
> From: "Guru Balse" <gu...@oracle.com>
> Sent: Wed, June 7, 2006 2:17 pm
> To: "Ant Users List" <us...@ant.apache.org>
> Subject: Implementing a loop in ANT
>
> 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
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
--
Scot P. Floess
27 Lake Royale
Louisburg, NC 27549
252-478-8087 (Home)
919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Implementing a loop in ANT
Posted by db...@baybroadband.net.
ant-contrib.sourceforge.net has some tasks to do this.
-----Original Message-----
From: "Guru Balse" <gu...@oracle.com>
Sent: Wed, June 7, 2006 2:17 pm
To: "Ant Users List" <us...@ant.apache.org>
Subject: Implementing a loop in ANT
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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by "Scot P. Floess" <fl...@mindspring.com>.
Guru:
Ah, I see your point and what you wish to do... Hmmm - have you
considered doing your own macro def to accomplish this?
I wasn't aware of the <math> task - I appreciate you pointing it out.
This functionality sorta inspires me, so I think I am going to
investigate writing my own macrodef to accomplish this type of
functionality. If you want, I'd be happy to send you what I create.
Take care,
Scot
Guru Balse wrote:
> 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
>>>>
>
>
--
Scot P. Floess
27 Lake Royale
Louisburg, NC 27549
252-478-8087 (Home)
919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by Ninju Bohra <ni...@yahoo.com>.
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 <gu...@oracle.com>
To: Ant Users List <us...@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: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
Re: Implementing a loop in ANT
Posted by Guru Balse <gu...@oracle.com>.
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
>>>
Re: Implementing a loop in ANT
Posted by "Scot P. Floess" <fl...@mindspring.com>.
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
>>
>>
>
--
Scot P. Floess
27 Lake Royale
Louisburg, NC 27549
252-478-8087 (Home)
919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by "Scot P. Floess" <fl...@mindspring.com>.
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
>
>
--
Scot P. Floess
27 Lake Royale
Louisburg, NC 27549
252-478-8087 (Home)
919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
Re: Implementing a loop in ANT
Posted by "Scot P. Floess" <fl...@mindspring.com>.
Ben:
Wow...thats sorta neat ;) I like what you did here with build.number -
cool :)
Ben Stringer wrote:
> On Wed, 2006-06-07 at 11:17 -0700, 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.
>>
>
> Here is a rather contrived solution using <buildnumber/> for state and
> <ant> for recursion. Not sure how much use it will be in real world use,
> but it was fun to write :)
>
> <project default="increment" name="Increment Test" basedir=".">
>
> <target name="check.condition" unless="increment.stop">
> <ant antfile="build.xml" target="increment" inheritAll="no"/>
> </target>
>
> <target name="remove.statefile" if="increment.stop">
> <delete file="build.number"/>
> </target>
>
> <target name="increment">
> <buildnumber/>
> <echo>N = ${N} BN=${build.number}</echo>
> <condition property="increment.stop">
> <equals arg1="${N}" arg2="${build.number}"/>
> </condition>
> <antcall target="remove.statefile"/>
> <antcall target="check.condition"/>
> </target>
>
> </project>
>
>
> ant -f increment.xml -DN=3
> Buildfile: increment.xml
>
> increment:
> [echo] N = 3 BN=0
>
> remove.statefile:
>
> check.condition:
>
> increment:
> [echo] N = 3 BN=1
>
> check.condition:
>
> increment:
> [echo] N = 3 BN=2
>
> check.condition:
>
> increment:
> [echo] N = 3 BN=3
>
> check.condition:
>
> BUILD SUCCESSFUL
> Total time: 1 second
>
> There is a bug - the removal of the "build.number" file only works in
> cases where N=0, and I have not yet worked out why. So remove
> build.number manually each time if you are playing with this buildfile.
>
> Cheers, Ben
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
--
Scot P. Floess
27 Lake Royale
Louisburg, NC 27549
252-478-8087 (Home)
919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
Re: Implementing a loop in ANT
Posted by Ben Stringer <be...@burbong.com>.
On Wed, 2006-06-07 at 11:17 -0700, 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.
Here is a rather contrived solution using <buildnumber/> for state and
<ant> for recursion. Not sure how much use it will be in real world use,
but it was fun to write :)
<project default="increment" name="Increment Test" basedir=".">
<target name="check.condition" unless="increment.stop">
<ant antfile="build.xml" target="increment" inheritAll="no"/>
</target>
<target name="remove.statefile" if="increment.stop">
<delete file="build.number"/>
</target>
<target name="increment">
<buildnumber/>
<echo>N = ${N} BN=${build.number}</echo>
<condition property="increment.stop">
<equals arg1="${N}" arg2="${build.number}"/>
</condition>
<antcall target="remove.statefile"/>
<antcall target="check.condition"/>
</target>
</project>
ant -f increment.xml -DN=3
Buildfile: increment.xml
increment:
[echo] N = 3 BN=0
remove.statefile:
check.condition:
increment:
[echo] N = 3 BN=1
check.condition:
increment:
[echo] N = 3 BN=2
check.condition:
increment:
[echo] N = 3 BN=3
check.condition:
BUILD SUCCESSFUL
Total time: 1 second
There is a bug - the removal of the "build.number" file only works in
cases where N=0, and I have not yet worked out why. So remove
build.number manually each time if you are playing with this buildfile.
Cheers, Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Implementing a loop in ANT
Posted by Jeffrey E Care <ca...@us.ibm.com>.
google antcontrib
____________________________________________________________________________________________
Jeffrey E. (Jeff) Care
carej@us.ibm.com
IBM WebSphere Application Server Development
WAS Pyxis Lead Release Engineer
Guru Balse <gu...@oracle.com> wrote on 06/07/2006 02:17:47 PM:
> 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
>