Check if two antcalls are successfull

十年热恋 提交于 2019-12-23 19:45:39

问题


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 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?


回答1:


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

  1. The code executed without throwing an exception.
  2. The code did what you wanted it to do.

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.

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:

  • 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.



来源:https://stackoverflow.com/questions/14835000/check-if-two-antcalls-are-successfull

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!