How check for a condition in ant and depending on its value print a message?

前端 未结 3 1707
一个人的身影
一个人的身影 2020-12-22 11:35

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

    
            
           


        
相关标签:
3条回答
  • 2020-12-22 11:52

    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>
    

    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>
    
    0 讨论(0)
  • 2020-12-22 12:09

    Since ant 1.9.1 you can do this:

    <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>
    
    0 讨论(0)
  • 2020-12-22 12:11

    Looks like you misunderstood the Condition Task:

    property: The name of the property to set.

    Try using the Conditionos:

    Test whether the current operating system is of a given type.

    0 讨论(0)
提交回复
热议问题