Ant 条件 - 首先出现“如果"或“除非" [英] Ant conditions - which comes first 'if' or 'unless'
问题描述
问题
如果一个蚂蚁目标同时使用if和unless,哪个先求值?
If an ant target uses both if and unless, which is evaluated first?
示例
先有鸡还是先有蛋?...
What comes first, the chicken or the egg? . . .
<target name="prepare" if="chicken" unless="egg" >
<echo>Dinner time. Chicken is served!</echo>
</target>
蚂蚁会先评估鸡的属性吗?还是蛋属性?
Would ant evaluate the chicken property first? Or the egg property?
推荐答案
这不是一个真正的评估问题,因为在调用目标之前属性要么已经设置,要么没有设置.
It isn't really a question of evaluation, since the properties either are or are not set before the target gets called.
我查看了 1.8.1 源代码,逻辑如下:
I looked at the 1.8.1 source and the logic is as follows:
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;
}
所以 unless
将无关紧要,除非 if
通过.但请记住,这些与评估属性没有任何关系.它只是查找它们以查看它们是否已设置.
So the unless
won't matter unless the if
passes. But keep in mind, these don't have anything to do with evaluating properties. It just looks them up to see if they are set.
这篇关于Ant 条件 - 首先出现“如果"或“除非"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!