蚂蚁条件-首先出现“如果"或“除非"

问题描述:

问题

如果一个蚂蚁目标同时使用了 if 除非,那么哪个会被首先评估?

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;
}

因此,除非if通过,否则unless无关紧要.但是请记住,这些与评估属性没有任何关系.只是查找它们以查看是否已设置.

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.