首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不使用Ant-contrib的情况下在Ant中模拟if-else if-else?

如何在不使用Ant-contrib的情况下在Ant中模拟if-else if-else?
EN

Stack Overflow用户
提问于 2013-04-10 05:33:33
回答 1查看 3.6K关注 0票数 2

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

我不想使用Ant-contrib。

我尝试了解决方案here

代码语言:javascript
复制
    <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目标中设置属性,这些属性在调用目标中是不可见的。

有没有其他使用条件的方法?

EN

回答 1

Stack Overflow用户

发布于 2013-04-11 03:56:17

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

代码语言:javascript
复制
<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>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15912976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档