ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Anson <dan...@germane-software.com>
Subject Re: Conditional Statement Again
Date Fri, 01 Aug 2003 23:42:39 GMT
Both the Antelope tasks and ant-contrib have try/catch, which looks like 
it would be just right for what you're trying to do. Using the Antelope 
try/catch it would look like this:

<target name="CvsImport" unless="ifNewJars" description="CVS Import"
depends="suzCvsLogin">	
	<try>
			<cvs cvsroot="${cvsRoot}" passfile="${pass.file}">
			<commandline>
				<argument value="import"/>
				<argument value="-m"/>
				<argument value="${cvs.msg}"/>
			</commandline>	
		   </cvs>		   
	 <manifest file="${manifest.file}">	    
     <attribute name="Manifest-Version" value="${Manifest-Version}"/>

	</manifest>	
	<!-- optional catch, not required, but maybe you want a special message. -->
	<catch>
		<fail>Your message goes here.</fail>
	</catch>
	</try>   
	</target>	

The default setting for 'try' will only print out the equivalent of Exception.getMessage(),
which is usually a one-liner.

Docs for 'try' are at http://antelope.sourceforge.net/manual/bk03ch07.html

Dale




Vikas Phonsa wrote:

>I have to perform two tasks ( <cvs> and <manifest>) in one target as
>follows:
>
><target name="CvsImport" unless="ifNewJars" description="CVS Import"
>depends="suzCvsLogin">	
>			<cvs cvsroot="${cvsRoot}" passfile="${pass.file}">
>			<commandline>
>				<argument value="import"/>
>				<argument value="-m"/>
>				<argument value="${cvs.msg}"/>
>			</commandline>	
>		   </cvs>		   
>	 <manifest file="${manifest.file}">	    
>     <attribute name="Manifest-Version" value="${Manifest-Version}"/>
>
>	</manifest>	   
>	</target>	
>
>
>
>
>Now I want that if the <cvs> task fails due to any reason the build should
>be stopped and <manifest> task should not be executed. I have tried to use
><cvs failonerror="true">, it does stop the build on error but gives all
>sorts of error codes in many lines ( hundreds of red colored lines in my
>IDE).I just want it to stop the build and maybe give a single line of error
>code and exit.
>
>
>Any ideas.
>
>Vikas
>
>
>
>-----Original Message-----
>From: Stefan Bodewig [mailto:bodewig@apache.org] 
>Sent: Wednesday, July 30, 2003 11:39 PM
>To: user@ant.apache.org
>Subject: Re: Conditional Statement
>
>On Wed, 30 Jul 2003, Matt <mathews_julien@hotmail.com> wrote:
>
>  
>
>>How do we add "if-else" statements in Ant. I need to compare two
>>variables and execute a task if they are not equal and abort with an
>>error message if they are equal.
>>    
>>
>
><condition property="they-are-equal">
>  <equals arg1="${property1}" arg2="${property2}"/>
></condition>
><fail if="they-are-equal">property1 and property2 must not be equal.</fail>
><perform-your-task/>
>
>Stefan
>
>---------------------------------------------------------------------
>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


Mime
View raw message