ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Taylor <>
Subject Re: Making Jumps or doing Loops!!
Date Thu, 23 Aug 2001 16:12:48 GMT

--- Edgar Sánchez <> wrote:
>   Hi everyone is Vincent again...
>     now I've 2 questions, well those are for the same
> reason..
>   I was wondering if here in Ant could I make some
> jumps in order to repeat the same procedure with other
> caracteristics, 

Yes, check out the antcall task. This allows you to execute the
same target multiple times with different sets of "inputs".

or if I can use loops like For or
> While to do the same, keeping a counter in order to
> make conditions to execute the same procedure or same
> target with diferent actions.
>   Is it possible?

When looping, you have to create a "kick-out" condition. I used the
target's unless attribute. The idea is to loop until the property is
set. However, because a target can't antcall itself, you have to
replicate the target and have them cross-call each other:

<target name="worker">
  <!-- This does the actual work. May depend on other workers. -->

<target name="looper_1" depends="worker" unless="some.condition">
  <antcall target="looper_2"/>

<target name="looper_2" depends="worker" unless="some.condition">
  <antcall target="looper_1"/>

This takes care of while loops. I've never tried implementing a for
loop in Ant. I suppose you could do something like the following
in the worker target:

<property name="counter" value="counter" />

<target name="worker">
  <property name="${counter}." value="whatever" />

Then if you wanted to loop 3 times:

<target name="looper_1" depends="worker" unless="counter...">
  <antcall target="looper_2"/>

<target name="looper_2" depends="worker" unless="counter...">
  <antcall target="looper_1"/>

-- Don

>   thank you
> =====
> _________________________________________________________________
> "Puedes sentirte desilusionado si fallas, pero estás condenado si no
> lo intentas."
> "You can get disappointed if you fail down, but you are doomed if you
> do not try it."
> ICQ #  22338121
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo!
> Messenger

Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger

View raw message