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

泪湿孤枕 提交于 2019-12-07 01:35:23

问题


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" >
    <echo>Dinner time. Chicken is served!</echo>
</target>

Would ant evaluate the chicken property first? Or the egg property?


回答1:


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.



来源:https://stackoverflow.com/questions/4084014/ant-conditions-which-comes-first-if-or-unless

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!