当您在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/