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 18:16:22 UTC

Testing multiple values?

How do I handle three different possible values from an 'exec' task when I 
want one value to be ignored and each of the other two values to invoke 
different targets?

I have an exec task that has the parameter resultproperty="script1.result". 
The value of script1.result can be: 0 (indicates that the script worked fine 
without errors); 1 (indicates that the script ran but had errors); 
or -1073741819 (indicates that the WinSCP3 environment was not initialized 
properly; basically, the passphrase hadn't yet been entered so that WinSCP3 
could verify the login).

When script.result is 0, I want to move on to the next target within my 
build. When script.result is 1, I want to fail with the error message 
("Script1 failed. See Script1.out."). When script1.result is
-1073741819, I want to fail with the error message ("WinSCP3 environment not 
initialized. Please click on the keyfile and supply the passphrase.")

My script currently handles the 0 and 1 conditions just fine but I don't 
know how to change my code to handle the third value for script1.result. 
Here is what I have so far:

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

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

<!--echoproperties prefix="server"/-->

<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>



</target>

<target name="check-Script1" depends="upload-Tonge" description="See if 
Script1 worked.">

<echo message="Check script1 result"/>

<condition property="script1.failed">

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

</condition>

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

<antcall target="upload-Tonge-Script1-errors"/>

</target>

<target name="upload-Tonge-Script1-errors" if="script1.failed">

<fail message="Oops, script ${script1.name} failed on Tonge server. See 
${script1.out} and ${script1.err}."/>

</target>



<target name="upload-Tonge-Script2-errors" if="script2.failed">

<fail message="Oops, script ${script2.name} failed on Tonge server. See 
${script2.out} and/or ${script2.err}."/>

</target>


Do I need a different condition task to handle the -1073741819 value for 
script1.result? If yes, don't I have to worry about the 'upload-Bongo' task 
executing twice? Or can I modify the existing condition task to invoke two 
different targets based on the non-zero value of script.result, one target 
for script1.result = 1 and a different target for script1.result 
= -1073741819?

Or do I need to change the script more radically and do things a whole 
different way?

I'd prefer to stay with core tasks if at all possible.

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: Testing multiple values?

Posted by Rhino <rh...@sympatico.ca>.
Wow, that's remarkably easy and straightforward, which is not what I expect 
from Ant when it comes to conditions :-)

I'll give this a try and post back if it doesn't work properly.

Thank you!!

Rhino

----- Original Message ----- 
From: "Ondrej Svetlik" <on...@svetlik.info>
To: "Ant Users List" <us...@ant.apache.org>
Sent: Tuesday, December 20, 2005 4:52 PM
Subject: Re: Testing multiple values?


> Well, how about
>
> <exec />
> <fail message="Script1 failed. See Script1.out.">
> <condition>
> <equals arg1="${script1.result}" arg2="1" />
> </condition>
> </fail>
>
> <fail message="WinSCP3 environment not initialized. Please click on the 
> keyfile and supply the passphrase.">
> <condition>
> <equals arg1="${script1.result}" arg2="-1073741819" />
> </condition>
> </fail>
>
> Best regards,
>
> Ondrej Svetlik
>
> Rhino wrote:
>> How do I handle three different possible values from an 'exec' task when 
>> I want one value to be ignored and each of the other two values to invoke 
>> different targets?
>>
>> I have an exec task that has the parameter 
>> resultproperty="script1.result". The value of script1.result can be: 0 
>> (indicates that the script worked fine without errors); 1 (indicates that 
>> the script ran but had errors); or -1073741819 (indicates that the 
>> WinSCP3 environment was not initialized properly; basically, the 
>> passphrase hadn't yet been entered so that WinSCP3 could verify the 
>> login).
>>
>> When script.result is 0, I want to move on to the next target within my 
>> build. When script.result is 1, I want to fail with the error message 
>> ("Script1 failed. See Script1.out."). When script1.result is
>> -1073741819, I want to fail with the error message ("WinSCP3 environment 
>> not initialized. Please click on the keyfile and supply the passphrase.")
>>
>> My script currently handles the 0 and 1 conditions just fine but I don't 
>> know how to change my code to handle the third value for script1.result. 
>> Here is what I have so far:
>>
>> <target name="upload-Tonge" description="Upload to the Tonge server.">
>>
>> <echo message="Uploading to Tonge...."/>
>>
>> <!--echoproperties prefix="server"/-->
>>
>> <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>
>>
>>
>>
>> </target>
>>
>> <target name="check-Script1" depends="upload-Tonge" description="See if 
>> Script1 worked.">
>>
>> <echo message="Check script1 result"/>
>>
>> <condition property="script1.failed">
>>
>> <equals arg1="${script1.result}" arg2="1"/>
>>
>> </condition>
>>
>> <echo message="script1.result=${script1.result}"/>
>>
>> <antcall target="upload-Tonge-Script1-errors"/>
>>
>> </target>
>>
>> <target name="upload-Tonge-Script1-errors" if="script1.failed">
>>
>> <fail message="Oops, script ${script1.name} failed on Tonge server. See 
>> ${script1.out} and ${script1.err}."/>
>>
>> </target>
>>
>>
>>
>> <target name="upload-Tonge-Script2-errors" if="script2.failed">
>>
>> <fail message="Oops, script ${script2.name} failed on Tonge server. See 
>> ${script2.out} and/or ${script2.err}."/>
>>
>> </target>
>>
>>
>> Do I need a different condition task to handle the -1073741819 value for 
>> script1.result? If yes, don't I have to worry about the 'upload-Bongo' 
>> task executing twice? Or can I modify the existing condition task to 
>> invoke two different targets based on the non-zero value of 
>> script.result, one target for script1.result = 1 and a different target 
>> for script1.result = -1073741819?
>>
>> Or do I need to change the script more radically and do things a whole 
>> different way?
>>
>> I'd prefer to stay with core tasks if at all possible.
>>
>> Rhino
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.14.1/207 - Release Date: 19/12/2005
>
> 



-- 
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: Testing multiple values?

Posted by Ondrej Svetlik <on...@svetlik.info>.
Well, how about

<exec />
<fail message="Script1 failed. See Script1.out.">
	<condition>
		<equals arg1="${script1.result}" arg2="1" />
	</condition>
</fail>

<fail message="WinSCP3 environment not initialized. Please click on the 
keyfile and supply the passphrase.">
	<condition>
		<equals arg1="${script1.result}" arg2="-1073741819" />
	</condition>
</fail>

Best regards,

Ondrej Svetlik

Rhino wrote:
> How do I handle three different possible values from an 'exec' task when 
> I want one value to be ignored and each of the other two values to 
> invoke different targets?
> 
> I have an exec task that has the parameter 
> resultproperty="script1.result". The value of script1.result can be: 0 
> (indicates that the script worked fine without errors); 1 (indicates 
> that the script ran but had errors); or -1073741819 (indicates that the 
> WinSCP3 environment was not initialized properly; basically, the 
> passphrase hadn't yet been entered so that WinSCP3 could verify the login).
> 
> When script.result is 0, I want to move on to the next target within my 
> build. When script.result is 1, I want to fail with the error message 
> ("Script1 failed. See Script1.out."). When script1.result is
> -1073741819, I want to fail with the error message ("WinSCP3 environment 
> not initialized. Please click on the keyfile and supply the passphrase.")
> 
> My script currently handles the 0 and 1 conditions just fine but I don't 
> know how to change my code to handle the third value for script1.result. 
> Here is what I have so far:
> 
> <target name="upload-Tonge" description="Upload to the Tonge server.">
> 
> <echo message="Uploading to Tonge...."/>
> 
> <!--echoproperties prefix="server"/-->
> 
> <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>
> 
> 
> 
> </target>
> 
> <target name="check-Script1" depends="upload-Tonge" description="See if 
> Script1 worked.">
> 
> <echo message="Check script1 result"/>
> 
> <condition property="script1.failed">
> 
> <equals arg1="${script1.result}" arg2="1"/>
> 
> </condition>
> 
> <echo message="script1.result=${script1.result}"/>
> 
> <antcall target="upload-Tonge-Script1-errors"/>
> 
> </target>
> 
> <target name="upload-Tonge-Script1-errors" if="script1.failed">
> 
> <fail message="Oops, script ${script1.name} failed on Tonge server. See 
> ${script1.out} and ${script1.err}."/>
> 
> </target>
> 
> 
> 
> <target name="upload-Tonge-Script2-errors" if="script2.failed">
> 
> <fail message="Oops, script ${script2.name} failed on Tonge server. See 
> ${script2.out} and/or ${script2.err}."/>
> 
> </target>
> 
> 
> Do I need a different condition task to handle the -1073741819 value for 
> script1.result? If yes, don't I have to worry about the 'upload-Bongo' 
> task executing twice? Or can I modify the existing condition task to 
> invoke two different targets based on the non-zero value of 
> script.result, one target for script1.result = 1 and a different target 
> for script1.result = -1073741819?
> 
> Or do I need to change the script more radically and do things a whole 
> different way?
> 
> I'd prefer to stay with core tasks if at all possible.
> 
> Rhino
> 
> 
> 

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