在蚂蚁如何检查的条件,并根据其值打印的消息?(How check for a condition i

2019-06-24 15:24发布

这是一个小的代码,请给看看它,然后按照说明....

    <condition property="${param1}">
            <or>
                <istrue value="win-x86"/>
                <istrue value= "win-x86-client"/>
                <istrue value= "win-x64"/>
            </or>
     </condition>
    <target name="Mytarget" if="${param1}">
        <echo message="executing windows family build:::${param1}"/>
    </target>
<target name="print.name" >
    <antcall target="win-x86-build">
       <param name="param1" value="${platform.id}"/>
    </antcall>
</target>

我想,当过platform.id包含任何Windows家族的名字应该打印邮件EXECUTING WINDOWS FAMILY BUILD但问题是,它是打印,即使家人是UNIX此消息。

我想无论是我没有正确地检查条件,否则我正在做一些其他的错误。
有人可以帮我这个好吗?

Answer 1:

彼得试图解释,你必须明确指定属性名称。 请尝试以下方法让你的代码工作:

<project name="demo" default="Mytarget">

    <condition property="windoze">
        <or>
            <equals arg1="${param1}" arg2="win-x86"/>
            <equals arg1="${param1}" arg2="win-x86-client"/>
            <equals arg1="${param1}" arg2="win-x64"/>
        </or>
    </condition>

    <target name="Mytarget" if="windoze">
        <echo message="executing windows family build:::${param1}"/>
    </target>

</project>

一个更好的解决办法是利用内置ANT操作系统的测试条件的任务。

<project name="demo" default="Mytarget">

    <condition property="windoze">
        <os family="windows"/>
    </condition>

    <target name="Mytarget" if="windoze">
        <echo message="executing windows family build:::${os.name}-${os.arch}-${os.version}"/>
    </target>

</project>


Answer 2:

看起来你误会了条件任务 :

property :属性的名称进行设置。

尝试使用条件os

测试当前的操作系统是否是给定类型的。



Answer 3:

由于蚂蚁1.9.1,你可以这样做:

<project name="tryit" xmlns:if="ant:if" xmlns:unless="ant:unless">
   <exec executable="java">
     <arg line="-X" if:true="${showextendedparams}"/>
     <arg line="-version" unless:true="${showextendedparams}"/>
   </exec>
   <condition property="onmac">
     <os family="mac"/>
   </condition>
   <echo if:set="onmac">running on MacOS</echo>
   <echo unless:set="onmac">not running on MacOS</echo>
</project>


文章来源: How check for a condition in ant and depending on its value print a message?
标签: ant