检查两次蚂蚁呼叫是否成功 [英] Check if two antcalls are successfull

查看:29
本文介绍了检查两次蚂蚁呼叫是否成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 ant 脚本非常陌生,我想知道我的构建是否成功.我的主要目标有两个 antcall,我不知道如何检查它们是否成功,以评估主要目标.

I'm extremely new to ant script and i want to find out if my build is successful or not. my main target has two antcalls and i don't know how to check if they were successful or not, in order to evaluate the main target.

run all 是我的主要目标

run all is my main target

<target name="run all">
<antcall target="Run basic configuration" />
<antcall target="Run custom configuration"/>

我想为全部运行"目标添加失败条件.每个目标都会单独检查它们是否成功,但我想知道调用蚂蚁的目标是否不成功,以防这两个失败.另外,如果一个失败,另一个会被调用吗?

i want to add a fail condition for the "run all" target. Each target does check individually if they are successful, but I want to know if the target that calls the ant is unsuccessful in case those two fail. Also, if one fails does the other one get called?

推荐答案

要确定 antcall 是否成功,需要更仔细地定义成功是什么.它可能意味着:

To determine if an antcall is successful requires a more careful definition of what success is. It can mean:

  1. 执行的代码没有抛出异常.
  2. 代码做了你想要它做的事情.

在第一种情况下,您可以使用 trycatch 块来包装 antcall 的执行以捕获异常.trycatch 任务是 ant-contrib 的一部分,但它经常被使用在 Ant 编码中.你会这样做:

In the first case, you can wrap the execution of your antcall with a trycatch block to catch exceptions. The trycatch task is part of ant-contrib, but that is frequently used in Ant coding. You'd do:

<trycatch property="exception.message" reference="exception.object">
<try>
   <antcall target="targetName"/>
</try>
<catch>
   <!-- handle exception logic here -->
</catch>
<finally>
   <!-- do any final cleanup -->
</finally>
</trycatch>

在第二种情况下,您需要将一些状态传回给调用者,以表明代码执行了您希望它执行的操作.

In the second case, you need to pass back to the caller some state that indicates that the code did what you wanted it to do.

请注意,antcall 任务会重新加载 ant 文件(例如 build.xml),因此它可能是一项开销很大的操作.有使用 antcall 任务的替代方法:

Note that the antcall task reloads the ant file (e.g., build.xml), so it can be an expensive operation. There are alternatives to using the antcall task:

  • 使用 antcallback 任务 (ant-contrib).antcallback 任务专门解决了传回数据的需要.
  • 在定义目标以调用依赖任务时使用 depends 属性.
  • 使用 runtarget 任务 (ant-contrib).使用 runtarget,您的所有属性都会被传递,并且您在目标中设置的任何属性都可供调用者使用.
  • 使用 ma​​crodef 任务.它避免重新解析 ant 文件,可以传递具有默认值的属性,可以传递嵌套元素等等.因此,这是大多数情况下的首选解决方案.
  • Use the antcallback task (ant-contrib). The antcallback task specifically addresses the need to pass back data.
  • Use the depends attribute when defining a target to call dependent tasks.
  • Use the runtarget task (ant-contrib). With runtarget, all of your properties are passed and any properties you set in your target are available to the caller.
  • Use the macrodef task. It avoids reparsing of the ant file, can be passed attributes with default values, can be passed nested elements, and more. As such, this is the preferred solution in most cases.

在上述每种情况下,只需设置您可以在调用目标中检查的返回属性,以确定被调用或依赖的目标是否按照您的预期执行.

In each of the cases above, just set return properties that you can inspect in the calling target to determine whether the called or dependent targets did what you expected them to do.

这篇关于检查两次蚂蚁呼叫是否成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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