Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a property exists?

Tags:

ant

How do I check the existence of a property using Ant?

I am open to the use of ant-contrib, if Ant doesn't provide a similar thing.

Also, ant-contrib has an assert task, which provides exists, but the assertion is not what I need here since I would prefer a boolean return value.

like image 852
Abhijeet Kashnia Avatar asked Nov 10 '11 12:11

Abhijeet Kashnia


1 Answers

You can use the Condition task with an isset condition.

<project default="test">    <property name="a" value="a"/>    <target name="test">      <condition property="a.set" else="false">       <isset property="a"/>     </condition>      <condition property="b.set" else="false">       <isset property="b"/>     </condition>      <echo message="a set ? ${a.set}"/>     <echo message="b set ? ${b.set}"/>    </target> </project> 

Output:

test:      [echo] a set ? true      [echo] b set ? false 
like image 168
sudocode Avatar answered Oct 08 '22 06:10

sudocode