如何模拟IF-ELSEIF-ELSE在Ant中不使用蚂蚁的contrib? [英] How to emulate if-elseif-else in Ant without using Ant-contrib?

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

问题描述

我需要一个蚂蚁IF-ELSEIF-ELSE条件语句。

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

我不想使用Ant-的contrib。

I do not want to use Ant-contrib.

我试过的解决方案<一个href=\"http://jaysonlorenzen.word$p$pss.com/2010/03/10/apache-ant-if-else-condition-without-ant-contrib/\"相对=nofollow>这里

    <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?

推荐答案

将依赖了,如果其他成依赖于所有其他目标的一个新的目标:

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>

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

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