Condition

Description

Sets a property if a certain condition holds true - this is a generalization of Available and Uptodate.

If the condition holds true, the property value is set to true by default; otherwise, the property is not set. You can set the value to something other than the default by specifying the value attribute.

Conditions are specified as nested elements, you must specify exactly one condition.

Parameters

Attribute Description Required
property The name of the property to set. Yes
value The value to set the property to. Defaults to "true". No

Parameters specified as nested elements

All conditions to test are specified as nested elements.

not

The <not> element expects exactly one other condition to be nested into this element, negating the result of the condition. It doesn't have any attributes and accepts all nested elements of the condition task as nested elements as well.

and

The <and> element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements - all nested elements of the condition task are supported. This condition is true if all of its contained conditions are, conditions will be evaluated in the order they have been specified in the build file.

The <and> condition has the same shortcut semantics as the Java && operator, as soon as one of the nested conditions is false, no other condition will be evaluated.

or

The <or> element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements - all nested elements of the condition task are supported. This condition is true if at least one of its contained conditions is, conditions will be evaluated in the order they have been specified in the build file.

The <or> condition has the same shortcut semantics as the Java || operator, as soon as one of the nested conditions is true, no other condition will be evaluated.

available

This condition is identical to the Available task, all attributes and nested elements of that task are supported, the property and value attributes are redundant and will be ignored.

uptodate

This condition is identical to the Uptodate task, all attributes and nested elements of that task are supported, the property and value attributes are redundant and will be ignored.

os

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

Attribute Description Required
family The name of the operating system family to expect. No

Supported values for the family attribute are:

equals

Tests whether the two given Strings are identical

Attribute Description Required
arg1 First string to test. Yes
arg2 Second string to test. Yes

Examples

  <condition property="javamail.complete">
    <and>
      <available classname="javax.activation.DataHandler" />
      <available classname="javax.mail.Transport" />
    </and>
  </condition>

sets the property javamail.complete if both the JavaBeans Activation Framework and JavaMail are available in the classpath.

  <condition property="isMacOsButNotMacOsX">
    <and>
      <os family="mac" />
      <not>
        <os family="unix" />
      </not>
    </and>
  </condition>

sets the property isMacOsButNotMacOsX if the current operating system is MacOS, but not MacOS X - which Ant considers to be in the Unix family as well.


Copyright © 2001 Apache Software Foundation. All rights Reserved.