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/19 18:12:13 UTC

Confusion with condition

I'm getting a bit confused about a simple condition in one of my build 
scripts. Can anyone help?

One of my targets is trying to run a couple of WinSCP3 scripts. Both scripts 
are rather trivial - for the moment - and simply connect to a server and 
list the contents of a directory. The first script contains no errors but 
the second one contains a deliberate error: the directory name that it is 
supposed to list is misspelled. My target executes both scripts in separate 
tasks; for each task, a distinct resultproperty is set if the script 
encounters an error. According to Ant (running with -debug and
-verbose), the script2.result property is set to 1 when the second script 
encounters my deliberate error. So far so good.

However, the target that I set up to do a simple echo of a message when that 
property is set, fails to execute. I'm baffled why this target, 
upload-Bongo-Script1-errors, fails to execute. The dependency on 
'upload-Bongo' is stated and the 'if' spells the property name correctly. I 
can't think of anything else that could be wrong here. (Mind you, I only 
work on Ant a few hours at a time every few months so I forget a lot between 
Ant sessions.) Can anyone enlighten me?

Here's the relevant code:

<target name="upload-Bongo" description="Upload to the Bongo server.">

<echo message="Uploading to Bongo...."/>

<exec executable="${WinSCP3.com}" os="Windows XP" output="${script1.out}" 
error="${script1.err}"

resultproperty="script1.result"

description="Run a trivial script that doesn't change anything, just to show 
that everything works.">

<arg line="/console /script=${script1.in}"/>

</exec>

<exec executable="${WinSCP3.com}" os="Windows XP" output="${script2.out}" 
error="${script2.err}"

resultproperty="script2.result"

description="Upload the real files.">

<arg line="/console /script=${script2.in}"/>

</exec>

</target>

<target name="upload-Bongo-Script1-errors" depends="upload-Bongo" 
if="script1.result">

<echo message="Oops, upload to Bongo failed. See ${script1.out} and/or 
${script1.err}."/>

</target>

<target name="upload-Bongo-Script2-errors" depends="upload-Bongo" 
if="script2.result">

<echo message="Oops, upload to Bongo failed. See ${script2.out} and/or 
${script2.err}."/>

</target>


Rhino



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


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


Re: Confusion with condition

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

> However, the target that I set up to do a simple echo of a message
> when that property is set, fails to execute.

I would have guessed the target for the not-failing one would be
executed.  The if/unless on target only checks for the existance of a
property, not its value - and if the script doesn't fail the property
still gets set (to 0 on Windows).

Stefan

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