ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ninju Bohra <>
Subject Re: "post failure tasks" for failing targets
Date Tue, 13 Mar 2007 01:50:02 GMT
With the standard ANT tasks you can not handle a 'failing' build.

Of course that's why the authors of the <exec> task provided the 'failonerror' attribute.
 Instead of setting it to 'true' (which results in the buildscript stopping) how about setting
it to 'false' and doing the following

<target name="foo" depends="do_exec, success_only, failure_only, after_exec">

<target name="do_exec">
    <property name="success_code" value="0"/>
    <exec dir="..." executable="..." resultproperty="result_code"/>
    <condition property="exec_succeeded">
        <equals arg1="${result_code}" arg2="${success_code}"/>

   <target name="success_only" if="exec_succeeded">

    <target name="failure_only" unless="exec_succeeded">

    <target name="after_exec">
        <text2xml src="..." destfile="..."/>

Now...I have nothing against <trycatch>, I have used it before and it has its place...but
you may want to try using the 'resultproperty' attribute since it is available


----- Original Message ---- 
From: martin sweitzer <> 
Sent: Monday, March 12, 2007 6:29:31 PM 
Subject: "post failure tasks" for failing targets 

For a cruisecontrol set up we have a task called text2xml. So for 
text2xml to do its magic it needs to run :-) 

This is problematic for something like: 

<target name="foo" depends=""> 

<exec dir="${binaries.dir}" 
<arg line="${commandLineParams}"/> 

<text2xml srcfile = "${compileOptions.logDir}/${exampleGame.log}.log" 
destfile = "${compileOptions.logDir}/${exampleGame.log}_log.xml" 
element = "${compileOptions.projectName}" 
attribute = "name" 
value = "${exampleGame.log}" 


So the exec fires off and then it has an error so the failonerror 
aborts the target and returns! 

This is more generally formed as: How do you do "post failure tasks" 
for failing targets when the various exec type tasks return from a 
failonerror="true" ? 

Is there some way to register a "do after this fails" delegate that I 
am missing? 

From another thread I saw the trycatch 
( Is 
that the standard way of doing the above? 

so if you have: 

<target name="a" depends="b,c,d,e,f,g,h,i,j,k,l, taskToRunLast"> 

You would do something like: 

<target name="aDoIt" depends="b,c,d,e,f,g,h,i,j,k,l"> 

<target name="a"> 

<trycatch property="foo" reference="bar"> 
<antcall target="aDoIt" /> 


<antcall target="taskToRunLast" /> 


And then for each depends that also has some "post failure task" then 
slap in a trycatch there also? 

Seems to work pretty well in my quick test case. Is this the way to go? :-) 

To unsubscribe, e-mail: 
For additional commands, e-mail:

Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos. 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message