在蚂蚁EXEC失败有条件的任务 [英] Conditional Task on exec failure in Ant

查看:118
本文介绍了在蚂蚁EXEC失败有条件的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过蚂蚁运行一些单元测试,我想能够运行一些清理code。如果单元测试失败。我一直在寻找某种终于块,但我没有运气找到一个。我已经使用errorproperty试过,如果在任务的语句,但蚂蚁只接受真实的,开和是为真实属性。一个成功执行任务(至少在Unix上)返回0,所以我不得不建立一个可笑的精密仪器:

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:

<project name="TestBuild" default="build" basedir=".">
<target name="build" depends="truth,checkresult,cleanup" />

<target name="truth">
    <echo message="Running Truth" />
    <exec executable="false" errorproperty="testfailure"/>
</target>
<target name="checkresult">
    <condition property="testfailed">
        <not>
            <equals arg1="${testfailure}" arg2="0" />
        </not>
    </condition>
</target>
<target name="cleanup" if="testfailed">
    <echo message="cleanup" />
    <fail />
</target>

有没有更简单的方法来做到这一点?首先,这需要任务来完成,这似乎是荒谬的。这也意味着我有单元测试每个块后打电话到他们两个,因为我显然不能设置failonerror我通常会。总之,这是一个哈克,不雅的解决方案,而我希望有人有更好的。

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.

推荐答案

二possiblities

Two possiblities

-1-结果
使用一些的try / catch /终于构建脚本结果的特定部分
你需要一些蚂蚁插件,提供这些功能,F.E. =搜索结果
Flaka 结果
Antcontrib /的羚羊

-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-结果
使用buildlistener整个脚本(BUILD SUCCESSFUL,建立失效)搜索结果

-2-
use a buildlistener for the whole script ( BUILD SUCCESSFUL, BUILD FAILED )

千电子伏杰克逊在他的presentation一个exec侦听的很好的例子,=的 http://people.apache.org/~kevj/ossummit/extending-ant.html (中将exec听者的来源包括在幻灯片)

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>

这篇关于在蚂蚁EXEC失败有条件的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆