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

This is a small piece of code, please take 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> 

I want ever the platform.id file to contain any Windows family name, it should print the message EXECUTING WINDOWS FAMILY BUILD , but the problem is that it prints this message, even if it is a unix family.

I think that either I am not checking the state properly, or I am making some other mistake.
Can someone help me with this please?

0
source share
3 answers

Peter is trying to explain that you must explicitly specify a property name. Try the following:

 <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 use operating system tests built into the ANT 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> 
+2
source

It looks like you misunderstood the Problem Condition :

property : the name of the property set.

Try using the os Condition :

Check if the current operating system is the specified type.

+4
source

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> 
+2
source

Source: https://habr.com/ru/post/919168/


All Articles