开发者

Ant conditions - which comes first 'if' or 'unless'

开发者 https://www.devze.com 2023-01-23 19:44 出处:网络
Question If an ant target uses both if and unless, which is evaluated first? Example What comes first, the chicken or the egg? . . .

Question

If an ant target uses both if and unless, which is evaluated first?

Example

What comes first, the chicken or the egg? . . .

<target name="prepare" if="chicken" unless="egg" >
    开发者_JAVA百科<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.

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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消