You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rhino <rh...@sympatico.ca> on 2005/12/20 17:34:52 UTC

Bug in istrue condition?

I'm not sure if I've found a bug or am just not understanding the 
documentation correctly. I'm using Ant 1.6.5 in Eclipse 3.1.1.

Given this target:

------------------------------------------------------------------------------------
<target name="check-Script2" depends="upload-Bongo" description="See if 
Script2 worked.">

<echo message="Check script2 result"/>

<condition property="script2.failed">

<istrue value="${script2.result}"/>

</condition>

<echo message="script2.result=${script2.result}"/>

<antcall target="upload-Bongo-Script2-works"/>

<antcall target="upload-Bongo-Script2-errors"/>

</target>

------------------------------------------------------------------------------------

I expected that property 'script2.failed' would be set if property 
'script2.result' had a value of 1. Then, I expected that the 
'upload-Bongo-Script2-errors' target would get executed.

However, running Ant with -debug and -verbose, the Ant output showed that 
'script2.result' had a value of 1 but 'script2.failed' was _not_ set; the 
trace showed the message 'Condition false; not setting script2.failed'. 
Also, the 'upload-Bongo-Script2-works' target was executed, not 
'upload-Bongo-Script2-errors' target.

Why??? Am I completely misunderstanding the way 'istrue' is supposed to 
work? Or have I found a bug?


However, this revised form of the same target using the 'equals' condition 
works exactly as I want:

------------------------------------------------------------------------------------
<target name="check-Script2" depends="upload-Bongo" description="See if 
Script2 worked.">

<echo message="Check script2 result"/>

<condition property="script2.failed">

<equals arg1="${script2.result}" arg2="1"/>

</condition>

<echo message="script2.result=${script2.result}"/>

<antcall target="upload-Bongo-Script2-works"/>

<antcall target="upload-Bongo-Script2-errors"/>

</target>

------------------------------------------------------------------------------------
This time, with 'script2.result' still having a value of 1, the 
'script2.failed' property _was_ set with the message 'Setting project 
property: script2.failed -> true' and the 'upload-Bongo-Script2-errors' 
target executed, exactly as I wanted.

So, the bottom line is that I can make my script do what I want it to do but 
only with 'equals' not with 'istrue'.

I _assume_ that I am simply misunderstanding the correct use of 'istrue'. 
That wouldn't surprise me in the slightest!

<rant>
The documentation of the conditions is very poor in my opinion: the examples 
in the 'Condition' article in the manual don't even hint at the possibility 
of using 'antcall' in the true/false branches of the condition, nor do they 
show how the condition set by the condition task is even being used 
elsewhere in the build. The article in 'Supported conditions' is even worse 
since most of the conditions there have no examples at all. Now, some people 
may claim that conditions are so obvious that they don't need examples but I 
strongly disagree with that. If anything in Ant is non-intuitive, it is 
condition processing. I find myself cringing every time I try to use 
conditions: the convoluted practice of using a value to set a property so 
that it can control whether another target executes is very poor design in 
my opinion.

By the way, I'm not saying this to be unduly negative. If I felt that I 
really understood the use of the 'condition' task properly, I'd write new 
documentation with a lot of examples and offer it to the Ant community to 
solve the problem. But even that would just be a bandaid given the 
convoluted nature of the processing in Ant in the first place.

Is there any realistic prospect of rethinking Ant so that the _tasks 
themselves_ can properly react to errors? For instance, in my 'upload-Bongo' 
target, which runs a couple of scripts via 'exec' tasks, I'd like to have 
the 'exec' tasks themselves be able to display a user-specified message if 
they fail (or, ideally, play a user-selected sound file) where the 
user-specified message _differs_ for each of the scripts that are being 
exec'd. Therefore, if Script1 fails, the Ant build would show the message 
"Script1 failed. See Script1.out for more info." and if Script2 fails, the 
Ant build would show the message "Script2 failed. See Script2.out for more 
info.". That's not an unreasonable request is it? Instead, I have to use the 
exec task to create a property, then use a condition in another target to 
create a second property if the first property has a certain value, then 
have yet another target to display the desired message based on the value of 
the second property.

I'm sure all or most of the other tasks would benefit from similar 
capabilities of handling their own errors instead of creating umpteen error 
checking targets for each conceivable problem.
</rant>

Rhino



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.1/207 - Release Date: 19/12/2005


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


Re: Bug in istrue condition?

Posted by Ondrej Svetlik <on...@svetlik.info>.
Hello,

the documentation of <istrue> condition says:
istrue

Tests whether a string equals any of the ant definitions of true, that 
is "true","yes", or "on"

See http://ant.apache.org/manual/CoreTasks/conditions.html for more 
information.

Best regards,

Ondrej Svetlik

Rhino wrote:
> I'm not sure if I've found a bug or am just not understanding the 
> documentation correctly. I'm using Ant 1.6.5 in Eclipse 3.1.1.
> 
> Given this target:
> 
> ------------------------------------------------------------------------------------ 
> 
> <target name="check-Script2" depends="upload-Bongo" description="See if 
> Script2 worked.">
> 
> <echo message="Check script2 result"/>
> 
> <condition property="script2.failed">
> 
> <istrue value="${script2.result}"/>
> 
> </condition>
> 
> <echo message="script2.result=${script2.result}"/>
> 
> <antcall target="upload-Bongo-Script2-works"/>
> 
> <antcall target="upload-Bongo-Script2-errors"/>
> 
> </target>
> 
> ------------------------------------------------------------------------------------ 
> 
> 
> I expected that property 'script2.failed' would be set if property 
> 'script2.result' had a value of 1. Then, I expected that the 
> 'upload-Bongo-Script2-errors' target would get executed.
> 
> However, running Ant with -debug and -verbose, the Ant output showed 
> that 'script2.result' had a value of 1 but 'script2.failed' was _not_ 
> set; the trace showed the message 'Condition false; not setting 
> script2.failed'. Also, the 'upload-Bongo-Script2-works' target was 
> executed, not 'upload-Bongo-Script2-errors' target.
> 
> Why??? Am I completely misunderstanding the way 'istrue' is supposed to 
> work? Or have I found a bug?
> 
> 
> However, this revised form of the same target using the 'equals' 
> condition works exactly as I want:
> 
> ------------------------------------------------------------------------------------ 
> 
> <target name="check-Script2" depends="upload-Bongo" description="See if 
> Script2 worked.">
> 
> <echo message="Check script2 result"/>
> 
> <condition property="script2.failed">
> 
> <equals arg1="${script2.result}" arg2="1"/>
> 
> </condition>
> 
> <echo message="script2.result=${script2.result}"/>
> 
> <antcall target="upload-Bongo-Script2-works"/>
> 
> <antcall target="upload-Bongo-Script2-errors"/>
> 
> </target>
> 
> ------------------------------------------------------------------------------------ 
> 
> This time, with 'script2.result' still having a value of 1, the 
> 'script2.failed' property _was_ set with the message 'Setting project 
> property: script2.failed -> true' and the 'upload-Bongo-Script2-errors' 
> target executed, exactly as I wanted.
> 
> So, the bottom line is that I can make my script do what I want it to do 
> but only with 'equals' not with 'istrue'.
> 
> I _assume_ that I am simply misunderstanding the correct use of 
> 'istrue'. That wouldn't surprise me in the slightest!
> 
> <rant>
> The documentation of the conditions is very poor in my opinion: the 
> examples in the 'Condition' article in the manual don't even hint at the 
> possibility of using 'antcall' in the true/false branches of the 
> condition, nor do they show how the condition set by the condition task 
> is even being used elsewhere in the build. The article in 'Supported 
> conditions' is even worse since most of the conditions there have no 
> examples at all. Now, some people may claim that conditions are so 
> obvious that they don't need examples but I strongly disagree with that. 
> If anything in Ant is non-intuitive, it is condition processing. I find 
> myself cringing every time I try to use conditions: the convoluted 
> practice of using a value to set a property so that it can control 
> whether another target executes is very poor design in my opinion.
> 
> By the way, I'm not saying this to be unduly negative. If I felt that I 
> really understood the use of the 'condition' task properly, I'd write 
> new documentation with a lot of examples and offer it to the Ant 
> community to solve the problem. But even that would just be a bandaid 
> given the convoluted nature of the processing in Ant in the first place.
> 
> Is there any realistic prospect of rethinking Ant so that the _tasks 
> themselves_ can properly react to errors? For instance, in my 
> 'upload-Bongo' target, which runs a couple of scripts via 'exec' tasks, 
> I'd like to have the 'exec' tasks themselves be able to display a 
> user-specified message if they fail (or, ideally, play a user-selected 
> sound file) where the user-specified message _differs_ for each of the 
> scripts that are being exec'd. Therefore, if Script1 fails, the Ant 
> build would show the message "Script1 failed. See Script1.out for more 
> info." and if Script2 fails, the Ant build would show the message 
> "Script2 failed. See Script2.out for more info.". That's not an 
> unreasonable request is it? Instead, I have to use the exec task to 
> create a property, then use a condition in another target to create a 
> second property if the first property has a certain value, then have yet 
> another target to display the desired message based on the value of the 
> second property.
> 
> I'm sure all or most of the other tasks would benefit from similar 
> capabilities of handling their own errors instead of creating umpteen 
> error checking targets for each conceivable problem.
> </rant>
> 
> Rhino
> 
> 
> 

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


Re: Bug in istrue condition?

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 20 Dec 2005, Rhino <rh...@sympatico.ca> wrote:

> I expected that property 'script2.failed' would be set if property
> 'script2.result' had a value of 1.

No.  <istrue> compares against all values that are considered true for
boolean attributes in Ant and 1 is not one of them.  You want to use
the <equals> condition.

Stefan

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