ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <rhi...@sympatico.ca>
Subject Bug in istrue condition?
Date Tue, 20 Dec 2005 16:34:52 GMT
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


Mime
View raw message