You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Harry_ <ha...@gmail.com> on 2009/12/01 14:37:16 UTC

Re: ForTask throwing exception for same value for begin and end

Thanks a ton for your reply Peter.

I did the following in the ForTask code to fix it:

            if (step == 0) {
                throw new BuildException("step cannot be 0");
            } else if (iEnd > begin && step < 0) {
                throw new BuildException("end > begin, step needs to be >
0");
            } else if (iEnd < begin && step > 0) {   //Changed <= condition
to <
                throw new BuildException("end <= begin, step needs to be <
0");
            }

Thanks and Regards


Peter Reilly-2 wrote:
> 
> Yes this is a bug in the ant-contrib 's for task
> (as usual I have forgot my password..)
> 
> work-around: use step="-1" if begin and end are the
> same, and ensure that end >= begin.
> 
> work-around-2: patch ant-conrib:
> svn co
> https://ant-contrib.svn.sourceforge.net/svnroot/ant-contrib/ant-contrib/trunk
> ant-contrib
> 
> Index: src/main/java/net/sf/antcontrib/logic/ForTask.java
> ===================================================================
> --- src/main/java/net/sf/antcontrib/logic/ForTask.java  (revision 177)
> +++ src/main/java/net/sf/antcontrib/logic/ForTask.java  (working copy)
> @@ -237,7 +237,7 @@
>                  throw new BuildException("step cannot be 0");
>              } else if (iEnd > begin && step < 0) {
>                  throw new BuildException("end > begin, step needs to be >
> 0");
> -            } else if (iEnd <= begin && step > 0) {
> +            } else if (iEnd < begin && step > 0) {
>                  throw new BuildException("end <= begin, step needs to be
> < 0");
>              }
>          }
> 
> Peter
> 
> On Mon, Nov 30, 2009 at 11:44 AM,  <Ja...@rzf.fin-nrw.de> wrote:
>> <project xmlns:ac="antlib:net.sf.antcontrib">
>>    <ac:for param="i" begin="0" end="1">
>>      <sequential>
>>        <echo>i is @{i}</echo>
>>      </sequential>
>>    </ac:for>
>> </project>
>>
>> With begin=end=1 you will get the error message
>>  build.xml:2: end <= begin, step needs to be < 0
>>
>> So I see two possibilities:
>> 1) the exceptional 1-jvm-case
>>   <macrodef name="doit">
>>     <attribute name="param"/>
>>   ...
>>   <ac:if>
>>     <equals arg1="${end}" "1"/>
>>     <ac:then> <doit param="1"/> </>
>>     <ac:else>
>>       <ac:for ...> <doit param="@{i}"/>
>>
>> 2) NullObject
>>   Maybe your <sequential> implementation could deal with the value '0'
>> (and do nothing)
>>
>>
>> Jan
>>
>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Harry_ [mailto:harjitworks@gmail.com]
>>> Gesendet: Montag, 30. November 2009 11:50
>>> An: user@ant.apache.org
>>> Betreff: ForTask throwing exception for same value for begin and end
>>>
>>>
>>> Hi,
>>>
>>> I am using ForTask for looping. The end attribute value comes
>>> from property.
>>> I am using it like
>>>
>>>  <property name="JVMInstances" value="2"/>
>>>
>>>  <for begin="1" end="${JVMInstances}"  param="JVMID">
>>>
>>> The above code works fine.
>>>
>>> But when I make the value of JVMInstances as 1, then
>>> exception comes during
>>> the execution of this Ant file.
>>>
>>> Can Any one tell me if it is a known defect that for loop
>>> does not work with
>>> same value of begin and end attribute. I am using
>>> ise.antelope.tasks.ForTask.
>>>
>>>
>>> If this is a defect can anyone tell me how to write a
>>> function block in ant.
>>> This will help me in not writing redundant lines in build
>>> file by testing
>>> above condition in if Block.
>>>
>>> Regards
>>> --
>>> View this message in context:
>>> http://old.nabble.com/ForTask-throwing-exception-for-same-valu
>> e-for-begin-and-end-tp26572661p26572661.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
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/ForTask-throwing-exception-for-same-value-for-begin-and-end-tp26572661p26591896.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