Conditional Task on exec failure in Ant

前端 未结 2 594
温柔的废话
温柔的废话 2020-12-06 15:16

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

相关标签:
2条回答
  • 2020-12-06 15:39

    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>
    
    0 讨论(0)
  • 2020-12-06 15:56

    Ant contrib has the concept of a try-catch-finally. However this is a finally for a particular block, not for the entire script.

    0 讨论(0)
提交回复
热议问题