Reputation: 321
I am trying to print some message in Ant depending on some condition as follow:
<if>
<equals arg1="${docs.present}" arg2="true"/>
<then>
</then>
<else>
<echo message="No docss found!"/>
</else>
</if>
But as you see, if docs.present property is set to 'true' then only I want to execute only else part. There is nothing to execute in if part. How can I achieve this?
Upvotes: 1
Views: 256
Reputation: 78011
A native Ant solution would be to use conditional task execution:
<project name="demo" default="run">
<available file="mydoc.txt" property="doc.present"/>
<target name="run" unless="doc.present">
<echo message="No docs found"/>
</target>
</project>
The "if" task is not part of standard Ant.
Upvotes: 0
Reputation: 10497
You can use echo
in your if
condition instead of else as below :
<if>
<equals arg1="${docs.present}" arg2="false"/>
<then>
<echo message="No docss found!"/>
</then>
</if>
Upvotes: 1
Reputation: 869
Below is the typical example of writing if, else if and else conditions in ant.
<if>
<equals arg1="${condition}" arg2="true"/>
<then>
<copy file="${some.dir}/file" todir="${another.dir}"/>
</then>
<elseif>
<equals arg1="${condition}" arg2="false"/>
<then>
<copy file="${some.dir}/differentFile" todir="${another.dir}"/>
</then>
</elseif>
<else>
<echo message="Condition was neither true nor false"/>
</else>
</if>
In your case you can have the task to be performed inside the then
tag itself and remove else
tag if you have nothing to be performed there.
<if>
<equals arg1="${docs.present}" arg2="false"/>
<then>
<echo message="No docss found!"/>
</then>
</if>
Upvotes: 0