Check if two are successful

I am extremely new to ant script and I want to know if my build is successful or not. my main goal has two anti-tekles, and I don't know how to check if they were successful or not to evaluate the main goal.

running everything is my main goal

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

      

I want to add a failure condition for the "run all" target. Each target checks individually if they succeed, but I want to know if the target calling ant has not reached if these two fail. Also, if someone fails, are others called?

+3


source to share


1 answer


Determining whether antcall succeeds requires a more thorough determination of how successful it is. This could mean:

  • The code is executed without exception.
  • The code did what you wanted.

In the first case, you can wrap the execution of its antcall unit trycatch , to catch an exception. The trycatch task is part of the ant -contrib, but this is often used in Ant encoding. You would 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 some state back to the caller 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 this can be an expensive operation. There are alternatives to using the antcall task:

  • Use the antcallback task (ant -contrib). The antcallback task specifically takes data transfer into account.
  • Use the dependent attribute when defining a target for invoking dependent tasks.
  • Use the runtarget task (ant -contrib). With runtarget, all of your properties are passed in, and any properties you set in your target are available to the caller.
  • Use the macrodef task . It avoids reusing the Ant file, attributes can be passed with default values, nested elements can be passed, and more. Thus, this is the preferred solution in most cases.

In each of the above cases, simply set return properties that you can check on the target network to determine if the called or dependent targets did what you expected them to do.

+2


source







All Articles