More Conditions

These conditions are suitable for use in the <bool> element. Unfortunately, they cannot be used in the <condition> task, although all conditions for the <condition> task can be used with the bool and the bool can be used anywhere that <condition> can be used.

IfPropertyTrue

Given a property name, tests whether the value for that property equals "true" (or "yes" or "on").

Table 5.2. IfPropertyTrue Attributes

AttributeDescriptionRequired
propertyThe name of a property to test the value of.Yes


<ispropertytrue property="myprop"/>
<ispropertytrue property="${someprop}"/>

IfPropertyFalse

Given a property name, tests whether the value for that property equals "false" (or "no" or "off").

Table 5.3. IfPropertyFalse Attributes

AttributeDescriptionRequired
propertyThe name of a property to test the value of.Yes


<ispropertyfalse property="myprop"/>
<ispropertyfalse property="${someprop}"/>

StartsWith

Given a property name, tests whether the value for that property starts with a specified string.

Table 5.4. StartsWith Attributes

AttributeDescriptionRequired
stringThe string to test.Yes
withCheck if 'string' starts with this value.Yes


<startswith string="abcdefg" with="abc"/>
<startswith string="${myprop}" with="foo"/>

EndsWith

Given a property name, tests whether the value for that ends with with a specified string.

Table 5.5. EndsWith Attributes

AttributeDescriptionRequired
stringThe string to test.Yes
withCheck if 'string' ends with this value.Yes


<endswith string="abcdefg" with="efg"/>
<endswith string="${myprop}" with="bar"/>

IsGreaterThan

Tests whether the first argument is greater than the second argument. Will automatically treat the arguments as numbers if both arguments consists of only the characters 0 through 9 and optionally a decimal point. Otherwise, a String comparison is used.

Table 5.6. IsGreaterThan Attributes

AttributeDescriptionRequired
arg1The first argument.Yes
arg2The second argument.Yes


<!-- evaluates to true -->
<isgreaterthan arg1="6.02" arg2="4"/>

<!-- evaluates to false -->
<isgreaterthan arg1="bar" arg2="foo"/>

IsLessThan

Tests whether the first argument is less than the second argument. Will automatically treat the arguments as numbers if both arguments consists of only the characters 0 through 9 and optionally a decimal point. Otherwise, a String comparison is used.

Table 5.7. IsLessThan Attributes

AttributeDescriptionRequired
arg1The first argument.Yes
arg2The second argument.Yes


<!-- evaluates to false -->
<islessthan arg1="6.02" arg2="4"/>

<!-- evaluates to true -->
<islessthan arg1="bar" arg2="foo"/>

DateBefore, TimeBefore

Tests whether the first date/time is before the second date/time.

Table 5.8. DateBefore, TimeBefore

AttributeDescriptionRequired
datetime1The first date/time.Yes
datetime2The second date/time.Yes
formatThe format of the date/time stamps.Yes
lenientWhether the datetime parser should use lenient parsing, defaults to true.No


   <target name="test1">
      <a:assert>
         <bool>
            <not>
            <datebefore datetime1="2005-09-09 14:58:36" datetime2="2005-07-11 14:58:36" format="yyyy-MM-dd HH:mm:ss"/>
            </not>
         </bool>
      </a:assert>
   </target>

   <target name="test2">
      <a:assert>
         <bool>
            <not>
            <timebefore datetime1="22:58:36" datetime2="10:58:36" format="HH:mm:ss"/>
            </not>
         </bool>
      </a:assert>
   </target>

   <target name="test3">
      <a:assert>
         <bool>
            <timebefore datetime1="2005" datetime2="2030" format="yyyy"/>
         </bool>
      </a:assert>
   </target>

   <target name="test4">
      <a:assert>
         <bool>
            <timebefore datetime1="01:00:00" datetime2="03:00:00" format="hh:mm:ss"/>
         </bool>
      </a:assert>
   </target>

DateDifference, TimeDifference

Tests that the difference between two dates or times is a certain value.

Table 5.9. DateDifference, TimeDifference

AttributeDescriptionRequired
datetime1The first date/time.Yes
datetime2The second date/time.Yes
formatThe format of the date/time stamps.Yes
lenientWhether the datetime parser should use lenient parsing, defaults to true.No
valueThe expected difference between the 2 datetimes.No, default is 0
unitSets the unit for the difference between the 2 datetimes. For example, if value is 12 and unit is "hours", then this condition checks that the difference between the 2 datetimes is 12 hours. Valid values are "millisecond", "second", "minute", "hour", "day", "week", "month", "year".Yes


   <target name="test1">
      <a:assert message="Difference between dates is not 60 days.">
         <bool>
            <datedifference datetime1="2005-09-09 14:58:36" datetime2="2005-07-11 14:58:36" format="yyyy-MM-dd HH:mm:ss" value="60" unit="day"/>
         </bool>
      </a:assert>
   </target>

   <target name="test2">
      <a:assert message="Difference between hours is not 12.">
         <bool>
            <timedifference datetime1="22:58:36" datetime2="10:58:36" format="HH:mm:ss" value="12" unit="hour"/>
         </bool>
      </a:assert>
   </target>

   <target name="test3">
      <a:assert message="Difference between years is not 25.">
         <bool>
            <timedifference datetime1="2005" datetime2="2030" format="yyyy" value="25" unit="year"/>
         </bool>
      </a:assert>
   </target>

   <target name="test4">
      <a:assert message="Difference between minutes is not 120.">
         <bool>
            <timedifference datetime1="01:00:00" datetime2="03:00:00" format="hh:mm:ss" value="120" unit="minute"/>
         </bool>
      </a:assert>
   </target>

   <target name="test5">
      <a:assert message="Difference between seconds is not 7200.">
         <bool>
            <timedifference datetime1="01:00:00" datetime2="03:00:00" format="hh:mm:ss" value="7200" unit="second"/>
         </bool>
      </a:assert>
   </target>