如何在不使用 Ant-contrib 的情况下在 Ant 中模拟 if-elseif-else? [英] How to emulate if-elseif-else in Ant without using Ant-contrib?

查看:25
本文介绍了如何在不使用 Ant-contrib 的情况下在 Ant 中模拟 if-elseif-else?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Ant 中使用 if-elseif-else 条件语句.

I need an if-elseif-else conditional statement in Ant.

我不想使用 Ant-contrib.

I do not want to use Ant-contrib.

我尝试了解决方案 这里

    <target name="condition.check">
    <input message="Please enter something: " addproperty="somethingProp"/>
    <condition property="allIsWellBool">
        <not>
            <equals arg1="${somethingProp}" arg2="" trim="true"/>
        </not>
    </condition>
</target>
<target name="if" depends="condition.check, else" if="allIsWellBool">
    <echo message="if condition executes here"/>
</target>
<target name="else" depends="condition.check" unless="allIsWellBool">
    <echo message="else condition executes here"/>
</target>

但是我必须在 if 和 else 目标中设置属性,这些属性在调用目标中是不可见的.

But I will have to set properties inside the if and else targets which will not be visible in the calling target.

使用条件还有其他出路吗?

Is there any other way out using conditions?

推荐答案

将依赖项从 ifelse 移到依赖所有其他项的新目标中目标:

Move the dependencies out of if and else into a new target that depends on all of the other targets:

<project name="ant-if-else" default="newTarget">
    <target name="newTarget" depends="condition.check, if, else"/>

    <target name="condition.check">
        <input message="Please enter something: " addproperty="somethingProp"/>
        <condition property="allIsWellBool">
            <not>
                <equals arg1="${somethingProp}" arg2="" trim="true"/>
            </not>
        </condition>
    </target>

    <target name="if" if="allIsWellBool">
        <echo message="if condition executes here"/>
    </target>
    <target name="else" unless="allIsWellBool">
        <echo message="else condition executes here"/>
    </target>
</project>

这篇关于如何在不使用 Ant-contrib 的情况下在 Ant 中模拟 if-elseif-else?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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