Ant的扩展点if / unless属性有什么用?

时间:2010-03-16 22:15:06

标签: ant

在Ant构建文件中定义扩展点时,可以使用if或unless属性使其具有条件性。在目标上if /除了防止它的任务被运行。但是一个扩展点没有任何条件运行的任务,那么条件是做什么的呢?我的想法(在Ant 1.8.0中证明是不正确的)是它会阻止任何扩展扩展点的任务被运行。以下是显示问题的示例构建脚本:

<project name = "ext-test"
    default   = "main">

  <property name = "do.it" value = "false" />

  <extension-point name = "init"/>
  <extension-point name = "doit" depends = "init" if = "${do.it}" />

  <target name = "extend-init" extensionOf = "init">
    <echo message = "Doing extend-init." />
  </target>

  <target name = "extend-doit" extensionOf = "doit">
    <echo message = "Do It! (${do.it})" />
  </target>

  <target name = "main" depends = "doit">
    <echo message = "Doing main." />
  </target>

</project>

使用命令:

ant -v

信赖:

Apache Ant version 1.8.0 compiled on February 1 2010
Trying the default build file: build.xml
Buildfile: /Users/bob/build.xml
Detected Java version: 1.6 in: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Detected OS: Mac OS X
parsing buildfile /Users/bob/build.xml with URI = file:/Users/bob/build.xml
Project base dir set to: /Users/bob
parsing buildfile jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `main' is [extend-init, init, extend-doit, doit, main]
Complete build sequence is [extend-init, init, extend-doit, doit, main, ]

extend-init:
     [echo] Doing extend-init.

init:

extend-doit:
     [echo] Do It! (false)

doit:
Skipped because property 'false' not set.

main:
     [echo] Doing main.

BUILD SUCCESSFUL
Total time: 0 seconds

您将注意到目标extend-doit已执行但跳过了延伸点本身。由于扩展点没有任何完全被跳过的任务?由于跳过的目标是成功的目标,因此依赖于扩展点的任何目标仍然会被执行。扩展点上if / unless属性的值是什么?

1 个答案:

答案 0 :(得分:0)

我猜他们没有实际的使用,它们可能作为属性出现,因为扩展点扩展了目标(关联的java类)。