ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EetieD <...@leanapps.com>
Subject Re: for statement possibilities
Date Tue, 13 Oct 2009 12:00:41 GMT

Thanks, very useful!




Francis Galiegue-4 wrote:
> 
> On Tue, Oct 13, 2009 at 12:11, EetieD <khn@leanapps.com> wrote:
>>
>> Hi all,
>>
>> I am using the 'for-statement' from Ant-Contrib. I have two questions
>> about
>> it:
>>
>> 1. Is it possible to stop within the for statement while it isn't ended
>> yet?
> 
> Yes it is, with a "catch" - quite literally so:
> 
> <trycatch>
>     <try>
>         <for>
>             <!-- whatever --->
>             <!-- when condition is met to exit loop, do: -->
>             <fail/>
>         </for>
>     </try>
>     <catch>
>         <!-- End of loop - catch statement possibly empty -->
>     </catch>
> </trycatch>
> 
> 
>> 2. Is it possible to use integers within a for statement?
>>
>> For example:
>>
>> <!-- starts for statement with number = 0, increasing 1 after each
>> iteration
>> -->
>> <for>
>>    <if><equals arg1="${number}" arg2="3" /><then>
>>        <!-- stop -->
>>    </then><else>
>>        <!-- continue -->
>>    </else></if>
>> </for>
>>
> 
> Yessir. Use ant-contrib's <math> statement, with ant-contrib's <var>.
> And use ant's <macrodef> for even more convenience. Demonstration:
> 
> ----
> build@build ~ $ cat t.xml
> <project name="t" default="doit" basedir=".">
>         <taskdef resource="net/sf/antcontrib/antlib.xml"/>
> 
>         <macrodef name="inc">
>                 <attribute name="victim"/>
>                 <sequential>
>                         <math result="@{victim}"
> operand1="${@{victim}}" operation="+"
>                                 operand2="1" datatype="int"/>
>                 </sequential>
>         </macrodef>
> 
>         <var name="t" value="1"/>
> 
>         <target name="doit">
>                 <inc victim="t"/>
>                 <echo message="${t}"/>
>         </target>
> 
> </project>
> 
> build@build ~ $ ant -f t.xml
> Buildfile: t.xml
> 
> doit:
>      [echo] 2
> ----
> 
> You have to wonder why ant-contrib isn't integrated within ant yet...
> Plain ant just cannot do this without <script>.
> 
> -- 
> 
> Francis Galiegue
> ONE2TEAM
> Ingénieur système
> Mob : +33 (0) 683 877 875
> Tel : +33 (0) 178 945 552
> fge@one2team.com
> 40 avenue Raymond Poincaré
> 75116 Paris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/for-statement-possibilities-tp25870237p25871591.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message