【问题标题】:Ant conditions - which comes first 'if' or 'unless'蚂蚁条件 - 首先出现“如果”或“除非”
【发布时间】:2010-11-03 03:32:24
【问题描述】:
问题
如果一个蚂蚁目标同时使用if和unless,那么先评估哪个?
示例
先有鸡还是先有蛋? . . .
<target name="prepare" if="chicken" unless="egg" >
<echo>Dinner time. Chicken is served!</echo>
</target>
蚂蚁会先评估鸡的属性吗?还是 egg 属性?
【问题讨论】:
标签:
ant
conditional
target
conditional-statements
【解决方案1】:
这实际上不是评估问题,因为在调用目标之前设置或未设置属性。
编辑:我看了1.8.1的源码,逻辑如下:
if (!testIfAllows()) {
project.log(this, "Skipped because property '" + project.replaceProperties(ifCondition)
+ "' not set.", Project.MSG_VERBOSE);
return;
}
if (!testUnlessAllows()) {
project.log(this, "Skipped because property '"
+ project.replaceProperties(unlessCondition) + "' set.", Project.MSG_VERBOSE);
return;
}
因此,除非 if 通过,否则 unless 将无关紧要。但请记住,这些与评估属性没有任何关系。它只是查找它们以查看它们是否已设置。