I have some unit tests running through Ant, and I\'d like to be able to run some cleanup code if the unit tests fail. I was looking for some sort of \"finally\" block, but I
Two possiblities
-1-
use some try/catch/finally construct for specific parts of your script
you need some Ant Plugin that provides those features, f.e. =
Flaka
Antcontrib / Antelope
<trycatch>
<try>
<exec .../>
</try>
<catch>
do your cleanup here
and afterwards don't forget to fail
</fail message="......."/>
</catch>
optionally you may use a finally section also
<finally>
..
</finally>
</trycatch>
-2-
use a buildlistener for the whole script ( BUILD SUCCESSFUL, BUILD FAILED )
Kev Jackson has a nice example of an exec-listener in his presentation, = http://people.apache.org/~kevj/ossummit/extending-ant.html (the sources of the exec-listener are included in the slides)
You're able to kick off specific tasks depending on the build result after your build has finished
<!-- taskcontainer -->
<exec-listener onSuccess="true|false">
..
your stuff goes here
..
</exec-listener>
Ant contrib has the concept of a try-catch-finally. However this is a finally for a particular block, not for the entire script.