The macro is used to exit an Ant script cleanly, without generating a build exception. It must be invoked in the top-level section of the script and be passed the name of the exit-target for the script.
forces an Ant script to exit by setting the script’s default target to the specified exit-target. An exit-target is an Ant script target with no processing and no prerequisites; the depends attribute is not specified or empty. Reseting the default target to an empty target at the top-level of the script causes the script to simply exit without processing any functional targets.
The macro can be used to control the processing flow of called Ant scripts. For example, an Ant script can be made optional by including at the top-level of the script and triggering its execution based on some condition.
The following table describes the macro specific attributes for the macro:
| Macro Specific Attributes | ||
| Attribute | Description | Required |
| target |
Name of the exit-target for the script. The default exit-target name is end.
|
No |
| message |
Message text to be logged when the macro is invoked and verbose logging is enabled. The default message text is: Exiting ${ant.project.name} by request.
|
No |
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed Materials - Property of IBM
(c) Copyright IBM Corporation 2020. All Rights Reserved.
Note to U.S. Government Users Restricted Rights:
Use, duplication or disclosure restricted by GSA ADP Schedule
Contract with IBM Corp.
-->
<project
basedir="."
default="all"
name="Example"
xmlns:ac="antlib:net.sf.antcontrib"
xmlns:xt="antlib:com.ibm.team.build.extensions.toolkit">
<description>Example</description>
<!-- Load build extensions -->
<xt:loadBuildExtensions/>
<xt:getJarLocation property="jarPath"/>
<!-- Load common resources -->
<import>
<javaresource name="scripts/smpe/imports/$common.xml">
<classpath location="${jarPath}"/>
</javaresource>
</import>
<!-- Exit if condition set -->
<property name="optional" value="true"/>
<ac:if>
<istrue value="${optional}"/>
<ac:then>
<AntExit/>
</ac:then>
</ac:if>
<!-- - - - - - - - - - - - - - - - - - - *
* Init *
*- - - - - - - - - - - - - - - - - - - -->
<target name="init" description="init">
...
</target>
<!-- - - - - - - - - - - - - - - - - - - *
* Main *
*- - - - - - - - - - - - - - - - - - - -->
<target name="main" description="main">
...
</target>
<!-- - - - - - - - - - - - - - - - - - - *
* Term *
*- - - - - - - - - - - - - - - - - - - -->
<target name="term" description="term">
...
</target>
<target name="all" description="all" depends="init,main,term"/>
<target name="end"/>
</project>
Result:
Buildfile: /Test.AntExit.xml
end:
BUILD SUCCESSFUL
Total time: 6 seconds