Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if and unless in ant

Tags:

xml

ant

I would like to clarify the if and unless statements in ANT script

I have the following code:

<condition property="hasExtensions">
    <contains string="${Product_version}" substring="Extensions">
</condition>

<exec executable="${TrueCM_App}\ssremove.exe" unless="hasExtensions">
    ...
</exec>

Does that mean the above <exec> would execute ssremove.exe if Product_version does not contain the string "Extensions"?

Then how about the opposite case: if it contains the string "Extensions"? Will my code look like this:

<condition property="hasExtensions">
    <contains string="${Product_version}" substring="Extensions">
</condition>
<!-- here below it does not have the string "Extensions" -->
<exec executable="${TrueCM_App}\ssremove.exe" unless="hasExtensions">
    ...
</exec>

<!-- below is for if it has the string "Extensions" -->
<exec executable="${TrueCM_App}\ssremove.exe" if="hasExtensions">
    ...
</exec>
like image 769
jeremychan Avatar asked Apr 13 '11 03:04

jeremychan


People also ask

What is Macrodef in ant?

This is used to specify the treatment of text contents of the macro invocation. If this element is not present, then any nested text in the macro invocation will be an error. If the text element is present, then the name becomes an attribute that gets set to the nested text of the macro invocation. Since Ant 1.6.

What is target in Ant build?

A target is a container of tasks and datatypes that cooperate to reach a desired state during the build process. Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target.

What is Ant task?

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.


1 Answers

You've got the logic right, but I'm not sure that the <exec> task accepts the if and unless attributes. See the docs for more info.

You will probably need to wrap the <exec> tasks in a target that checks the condition. For example:

<condition property="hasExtensions">
    <contains string="${Product_version}" substring="Extensions">
</condition>

<target name="ssremove" unless="hasExtensions">
    <exec executable="${TrueCM_App}\ssremove.exe">
        ...
    </exec>
</target>

Then if you run ant ssremove I think you will get what you want.

like image 185
ChrisH Avatar answered Sep 28 '22 00:09

ChrisH