中的条件并根据其值打印一条消息

中的条件并根据其值打印一条消息

本文介绍了如何检查 ant 中的条件并根据其值打印一条消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一小段代码,请看一下然后按照说明....

This is a small piece of code please give a look at it then follow the description....

    <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,它也会打印此消息.

I want that when ever platform.id contains any of the windows family name it should print the message EXECUTING WINDOWS FAMILY BUILD but the problem is that it is printing this message even when the family is unix.

我想要么我没有正确检查条件,要么我犯了其他错误.
有人可以帮我解决这个问题吗?

I think either I am not checking the condition properly or else i am doing some other mistake.
Can someone help me out with this please?

推荐答案

Peter 试图解释您必须明确指定属性名称.尝试以下操作使您的代码正常工作:

Peter is trying to explain that you must explicitly specify the property name. Try the following to make your code work:

<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 的 condition 中内置的操作系统测试a> 任务.

A better solution would be to make use of operating system tests built into ANT's condition task.

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

这篇关于如何检查 ant 中的条件并根据其值打印一条消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:49