蚂蚁条件-首先出现“如果"或“除非" [英] Ant conditions - which comes first 'if' or 'unless'

查看:123
本文介绍了蚂蚁条件-首先出现“如果"或“除非"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

如果一个蚂蚁目标同时使用了 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.

这篇关于蚂蚁条件-首先出现“如果"或“除非"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆