summaryrefslogtreecommitdiffstats
path: root/docs/manual/tasks/if.html
blob: e080d220c9e2c6d3ae03a69213c3db9edad94c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Ant-contrib Tasks: If</title>
  </head>

  <body>
    <h1>If</h1>

    <p>Perform some tasks based on whether a given condition holds
    true or not.</p>

    <p>This task is heavily based on the Condition framework that can
    be found in Ant 1.4 and later, therefore it cannot be used
    inconjunction with versions of Ant prior to 1.4.  Due to numeruos
    bugs in Ant 1.4(.1) that affect this task, we recommend to use Ant
    1.5 or later.</p>

    <h2>Parameters</h2>

    <p>This task doesn't have any attributes, the condition to test is
    specified by a nested element - see the documentation of your
    <code>&lt;condition&gt;</code> task (see <a
    href="http://ant.apache.org/manual/CoreTasks/condition.html">the
    online documentation</a> for example) for a complete list of
    nested elements.</p>

    <p>Just like the <code>&lt;condition&gt;</code> task, only a
    single condition can be specified - you combine them using
    <code>&lt;and&gt;</code> or <code>&lt;or&gt;</code>
    conditions.</p>

    <p>In addition to the condition, you can specify three different
    child elements, <code>&lt;elseif&gt;</code>, <code>&lt;then&gt;</code> and
    <code>&lt;else&gt;</code>.  All three subelements are optional.

    Both <code>&lt;then&gt;</code> and <code>&lt;else&gt;</code> must not be
    used more than once inside the if task.  Both are
    containers for Ant tasks, just like Ant's
    <code>&lt;parallel&gt;</code> and <code>&lt;sequential&gt;</code>
    tasks - in fact they are implemented using the same class as Ant's
    <code>&lt;sequential&gt;</code> task.</p>

    The <code>&lt;elseif&gt;</code> behaves exactly like an <code>&lt;if&gt;</code>
    except that it cannot contain the <code>&lt;else&gt;</code> element
    inside of it.  You may specify as may of these as you like, and the
    order they are specified is the order they are evaluated in.  If the
    condition on the <code>&lt;if&gt;</code> is false, then the first
    <code>&lt;elseif&gt;</code> who's conditional evaluates to true
    will be executed.  The <code>&lt;else&gt;</code> will be executed
    only if the <code>&lt;if&gt;</code> and all <code>&lt;elseif&gt;</code>
    conditions are false.

    <h2>Example</h2>

<pre><code>
&lt;if&gt;
 &lt;equals arg1=&quot;${foo}&quot; arg2=&quot;bar&quot; /&gt;
 &lt;then&gt;
   &lt;echo message=&quot;The value of property foo is bar&quot; /&gt;
 &lt;/then&gt;
 &lt;else&gt;
   &lt;echo message=&quot;The value of property foo is not bar&quot; /&gt;
 &lt;/else&gt;
&lt;/if&gt;
</code></pre>

<pre><code>
&lt;if&gt;
 &lt;equals arg1=&quot;${foo}&quot; arg2=&quot;bar&quot; /&gt;
 &lt;then&gt;
   &lt;echo message=&quot;The value of property foo is 'bar'&quot; /&gt;
 &lt;/then&gt;

 &lt;elseif&gt;
  &lt;equals arg1=&quot;${foo}&quot; arg2=&quot;foo&quot; /&gt;
  &lt;then&gt;
   &lt;echo message=&quot;The value of property foo is 'foo'&quot; /&gt;
  &lt;/then&gt;
 &lt;/elseif&gt;


 &lt;else&gt;
   &lt;echo message=&quot;The value of property foo is not 'foo' or 'bar'&quot; /&gt;
 &lt;/else&gt;
&lt;/if&gt;
</code></pre>

    <hr>
    <p align="center">Copyright &copy; 2002-2003 Ant-Contrib Project. All
    rights Reserved.</p>

  </body>
</html>