title: Conditional Task on exec failure in Ant
body: <p>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 had no luck finding one. I've tried using errorproperty and if statements on tasks, but ant only accepts "true", "on" and "yes" as true properties. A successfully executed task (on unix at least) returns 0, so I've had to construct a ridiculously elaborate apparatus:</p>
  
  <pre><code>&lt;project name="TestBuild" default="build" basedir="."&gt;
  &lt;target name="build" depends="truth,checkresult,cleanup" /&gt;
  
  &lt;target name="truth"&gt;
      &lt;echo message="Running Truth" /&gt;
      &lt;exec executable="false" errorproperty="testfailure"/&gt;
  &lt;/target&gt;
  &lt;target name="checkresult"&gt;
      &lt;condition property="testfailed"&gt;
          &lt;not&gt;
              &lt;equals arg1="${testfailure}" arg2="0" /&gt;
          &lt;/not&gt;
      &lt;/condition&gt;
  &lt;/target&gt;
  &lt;target name="cleanup" if="testfailed"&gt;
      &lt;echo message="cleanup" /&gt;
      &lt;fail /&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p></p>
  
  <p>Is there any simpler way to do this? For one, this requires to tasks to complete, which seems ridiculous. It also means I'd have to call both of them after every block of unit tests, because I obviously can't set failonerror as I normally would. In all, it's a hacky, inelegant solution, and I'm hoping someone has better one.</p>