## Conditions

Conditions are nested elements of the `<condition>` and `<waitfor>` tasks. There are core conditions and custom conditions. Custom conditions are described in Custom Conditions. Core Conditions are described below.

### Core Conditions

These are the nested elements that can be used as conditions in the `<condition>` and `<waitfor>` tasks.

#### 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.

#### xor

The `<xor>` element performs an exclusive or on all nested elements, similar to the `^` operator in Java. It only evaluates to true if an odd number of nested conditions are true. There is no shortcutting of evaluation, unlike the `<and>` and `<or>` tests. It doesn't have any attributes and accepts all nested elements of the condition task as nested elements as well.

#### 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. Each defined attribute is tested and the result is true only if all the tests succeed.

Attribute | Description | Required
family | The name of the operating system family to expect. | No
name | The name of the operating system to expect. | No
arch | The architecture of the operating system to expect. | No
version | The version of the operating system to expect. | No

Supported values for the family attribute are:

- windows (for all versions of Microsoft Windows)
- dos (for all Microsoft DOS based operating systems including Microsoft Windows and OS/2)
- mac (for all Apple Macintosh systems)
- unix (for all Unix and Unix-like operating systems)
- netware (for Novell NetWare)
- os/2 (for OS/2)
- tandem (for HP's NonStop Kernel - formerly Tandem)
- win9x for Microsoft Windows 95 and 98
- z/os for z/OS and OS/390
- os/400 for OS/400
- openvms for OpenVMS

#### equals

Tests whether the two given Strings are identical

Attribute | Description | Required
arg1 | First string to test. | Yes
arg2 | Second string to test. | Yes
casesensitive | Perform a case sensitive comparision. Default is true. | No
trim | Trim whitespace from arguments before comparing them. Default is false. | No

#### isset

Test whether a given property has been set in this project.

Attribute | Description | Required
property | The name of the property to test. | Yes

#### checksum

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

#### http

The `http` condition checks for a valid response from a web server of the specified url. By default, HTTP responses errors of 400 or greater are viewed as invalid.

Attribute | Description | Required
url | The full URL of the page to request. The web server must return a status code below the value of `errorsBeginAt` | Yes.
errorsBeginAt | The lowest HTTP response code that signals an error; by default '400'; server errors, not-authorized, not-found and the like are detected | No

#### socket

The `socket` condition checks for the existence of a TCP/IP listener at the specified host and port.

Attribute | Description | Required
server | The DNS name or IP address of the server. | Yes.
port | The port number to connect to. | Yes.

#### filesmatch

Test two files for matching. Nonexistence of either file results in "false". This test does a byte for byte comparision, so test time scales with byte size. NB: if the files are different sizes , one of them is missing or the filenames match the answer is so obvious the detailed test is omitted.

Attribute | Description | Required
file1 | First file to test | Yes.
file2 | Second file to test | Yes.

#### contains

Tests whether a string contains another one.

Attribute | Description | Required
string | The string to search in. | Yes
substring | The string to search for. | Yes
casesensitive | Perform a case sensitive comparision. Default is true. | No

#### istrue

Tests whether a string equals any of the ant definitions of true, that is "true","yes", or "on"

Attribute | Description | Required
value | value to test | Yes

        <istrue value="${someproperty}"/>
        <istrue value="false"/>

#### isfalse

Tests whether a string is not true, the negation of <istrue>

Attribute | Description | Required
value | value to test | Yes

        <isfalse value="${someproperty}"/>
        <isfalse value="false"/>

#### isreference

Test whether a given reference has been defined in this project and - optionally - is of an expected type.

This condition has been added in Apache Ant 1.6.

Attribute | Description | Required
refid | The id of the reference to test. | Yes
type | Name of the data type or task this reference is expected to be. | No

#### issigned

Test whether a jarfile is signed. If the name of the signature is passed, the file is checked for presence of that particular signature; otherwise the file is checked for the existence of any signature

This condition was added in Apache Ant 1.7.

Attribute | Description | Required
file | The jarfile that is to be tested for the presence of a signature. | Yes
name | The signature name to check for. | No

#### isfileselected

Test whether a file passes an embedded selector.

This condition was added in Apache Ant 1.7.

Attribute | Description | Required
file | The file to check if is passes the embedded selector. | Yes
basedir | The base directory to use for name based selectors. It this is not set, the project's basedirectory will be used. | No

Example usage:

>         <isfileselected file="a.xml">
>           <date datetime="06/28/2000 2:02 pm" when="equal"/>
>         </isfileselected>

#### typefound

Test whether a given type is defined, and that its implementation class can be loaded. Types include tasks, datatypes, scriptdefs, macrodefs and presetdefs.

This condition was added in Apache Ant 1.7.

Attribute | Description | Required
name | name of the type | Yes

#### scriptcondition

Evaluate a condition based on a script in any Apache BSF supported language.

See the Script task for an explanation of scripts and dependencies.

This condition was added in Apache Ant 1.7.

Attribute | Description | Required
language | script language | Yes
value | default boolean value | No -default is "false"
src | filename of script source | No

The script supports script language inline, this script has access to the same beans as the `<script>` task, and to the `self` bean, which refers back to the condition itself. The `value` property of this bean sets the return value:

Example:

        <scriptcondition language="javascript"
                value="true">
            self.setValue(false);
        </scriptcondition>

Sets the default value of the condition to true, then in the script, sets the value to false. This condition always evaluates to "false"

Copyright © 2001-2005 Apache Software Foundation. All rights Reserved.