ant - Ant的扩展点if/unless属性的用途是什么?

标签 ant

当您在Ant构建文件中定义扩展点时,可以通过使用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

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

最佳答案

我猜测它们没有实际用途,因为扩展点扩展了目标(相关的Java类确实如此),所以它们可能显示为属性。

关于ant - Ant的扩展点if/unless属性的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458553/

相关文章:

java - Ant 执行: pausing build to accept user input required by executed program

ant - 如何使 concat 任务因错误而失败?

java - 在从 Ant 运行的 javascript 中,如何获取参数值?

java - jar 文件可以在 eclipse 文件夹中使用,但不能在其中使用。未找到主类

ant - 只需要获取没有扩展名和整个路径的文件名

java - 如何为 Ant 构建配置 Ivy

android - 在 Linux 机器上使用 Ant FAILED 为 Android 构建失败,但在 Mac 机器上成功

java - 使用 Ant 的 Jacoco 覆盖和报告任务

java - 构建 Cordova Android 项目时出错

java - 为什么 Ant Exec 任务返回代码与 ERRORLEVEL 值不匹配?