Ant之Target 和Properity:

原创 2011年01月12日 11:45:00

 

1 Target

Target可以理解为task的容器,Target之间运行存在依赖关系,即所谓的“depends on”.存在depend on关系的两个trage之间,必须被依赖的target先执行。

<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>

Ant默认会根据depends后面所列的值从左到右的排列关系进行执行,如果target D,先执行C,B,A。
但是由于CBA之间又存在依赖关系,所以最后的执行顺序为 A --> B --> C --> D,每一个target只执行一次。

在target中也可以进行条件设置:
    <target name="build-module-A" if="module-A-present"/>

    <target name="build-own-fake-module-A" unless="module-A-present"/>

在第一个例子中,如果设置了module-A-present属性,不管其值如何,比如false,target都将被执行。
而在第二个例子中,如果module-A-present属性被设置,target则不将执行。


    <target name="myTarget.check" depends="init">
         <condition property="myTarget.run">
                    <and></and>
                    </condition>
    </target>
 
    <target name="myTarget" depends="myTarget.check" if="myTarget.run">
        <echo>Files foo.txt and bar.txt are present.</echo>
    </target>

结合前面一节的例子:

myTarget.check:

myTarget:
     [echo] Files foo.txt and bar.txt are present.

all:

BUILD SUCCESSFUL
Total time: 0 seconds

 

Important: the if and unless attributes only enable or disable the target to which they are attached. They do not control whether or not targets that a conditional target depends upon get executed. In fact, they do not even get evaluated until the target is about to be executed, and all its predecessors have already run.

 

说的什么意思呢,就是说仅仅对他们attach的target有效,而不管这个target依赖的target有没有执行。而这些条件在本target将要执行的时候才验证。

 

 

A target has the following attributes:

Attribute Description Required
name the name of the target. Yes
depends a comma-separated list of names of targets on which this target depends. No
if the name of the property that must be set in order for this target to execute, or something evaluating to true . No
unless the name of the property that must not be set in order for this target to execute, or something evaluating to false . No
description a short description of this target's function. No
extensionOf Adds the current target to the depends list of the named extension-point . since Ant 1.8.0. No
onMissingExtensionPoint What to do if this target tries to extend a missing extension-point . ("fail", "warn", "ignore"). since Ant 1.8.2. No. Not allowed unless extensionOf is present. Defaults to fail .

 

 

关于extension point:

since Ant 1.8.0.

Extension-Points are similar to targets in that they have a name and a depends list and can be executed from the command line. Just like targets they represent a state during the build process.

 

Unlike targets they don't contain any tasks, their main purpose is to collect targets that contribute to the desired state in their depends list.

 

Targets can add themselves to an extension-points's depends list via their extensionOf attribute. The targets that add themselves will be added after the targets of the explicit depends-attribute of the extension-point, if multiple targets add themselves, their relative order is not defined.

 

The main purpose of an extension-point is to act as an extension point for build files designed to be imported . In the imported file an extension-point defines a state that must be reached and targets from other build files can join the depends list of said extension-point in order to contribute to that state.

 

For example your imported build file may need to compile code, it might look like:

<target name="create-directory-layout">
...
</target>
<extension-point name="ready-to-compile"
depends="create-directory-layout"/>
<target name="compile" depends="ready-to-compile">
...
</target>
Call-Graph:
  create-directory-layout --> 'empty slot' --> compile

And you need to generate some source before compilation, then in your main build file you may use something like

<target name="generate-sources"
extensionOf="ready-to-compile">
...
</target>
Call-Graph:
  create-directory-layout --> generate-sources  --> compile

This will ensure that the generate-sources target is executed before the compile target.

Don't rely on the order of the depends list, if generate-sources depends on create-directory-layout then it must explicitly depend on it via its own depends attribute.

 

 

相关文章推荐

Ant build.xml中应该只包含一个target标签

今天在配置工程环境时,遇到一个Ant问题,之前一直都是由同事来管理这类环境问题的,但是他离职了,只能自己来研究。 下面是旧版本工程的build.xml内容: Builds, tests...
  • alanzyy
  • alanzyy
  • 2016年03月03日 18:55
  • 1540

Ant之Target

Target的属性及其使用

ant之<target/>标签(1)

Target 是一系列任务的集合。 一个target可以依赖其他的target。Apache Ant确保在执行当前target之前,其他被依赖的target已经执行完毕。 Ant 尽可能的执行targ...

stm32-mat_target4.40

  • 2017年11月07日 13:49
  • 14.82MB
  • 下载

js或者angular获取img图片的src($event.target和this的使用)

iOS一个工程实现多个Target

我们公司的项目需要涉及多地市,大部分功能是一样的,但是每个地市又有自己的特色,最基本的就是App的icon和LaunchImage的不同,这样讲大家应该会明白··· 用到多个target其实还有很多场...

stm32-mat_target.zip

  • 2017年09月12日 22:16
  • 62.01MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Ant之Target 和Properity:
举报原因:
原因补充:

(最多只允许输入30个字)