| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Ant-contrib Tasks: If</title> |
| 5 | </head> |
| 6 | |
| 7 | <body> |
| 8 | <h1>If</h1> |
| 9 | |
| 10 | <p>Perform some tasks based on whether a given condition holds |
| 11 | true or not.</p> |
| 12 | |
| 13 | <p>This task is heavily based on the Condition framework that can |
| 14 | be found in Ant 1.4 and later, therefore it cannot be used |
| 15 | inconjunction with versions of Ant prior to 1.4. Due to numeruos |
| 16 | bugs in Ant 1.4(.1) that affect this task, we recommend to use Ant |
| 17 | 1.5 or later.</p> |
| 18 | |
| 19 | <h2>Parameters</h2> |
| 20 | |
| 21 | <p>This task doesn't have any attributes, the condition to test is |
| 22 | specified by a nested element - see the documentation of your |
| 23 | <code><condition></code> task (see <a |
| 24 | href="http://ant.apache.org/manual/CoreTasks/condition.html">the |
| 25 | online documentation</a> for example) for a complete list of |
| 26 | nested elements.</p> |
| 27 | |
| 28 | <p>Just like the <code><condition></code> task, only a |
| 29 | single condition can be specified - you combine them using |
| 30 | <code><and></code> or <code><or></code> |
| 31 | conditions.</p> |
| 32 | |
| 33 | <p>In addition to the condition, you can specify three different |
| 34 | child elements, <code><elseif></code>, <code><then></code> and |
| 35 | <code><else></code>. All three subelements are optional. |
| 36 | |
| 37 | Both <code><then></code> and <code><else></code> must not be |
| 38 | used more than once inside the if task. Both are |
| 39 | containers for Ant tasks, just like Ant's |
| 40 | <code><parallel></code> and <code><sequential></code> |
| 41 | tasks - in fact they are implemented using the same class as Ant's |
| 42 | <code><sequential></code> task.</p> |
| 43 | |
| 44 | The <code><elseif></code> behaves exactly like an <code><if></code> |
| 45 | except that it cannot contain the <code><else></code> element |
| 46 | inside of it. You may specify as may of these as you like, and the |
| 47 | order they are specified is the order they are evaluated in. If the |
| 48 | condition on the <code><if></code> is false, then the first |
| 49 | <code><elseif></code> who's conditional evaluates to true |
| 50 | will be executed. The <code><else></code> will be executed |
| 51 | only if the <code><if></code> and all <code><elseif></code> |
| 52 | conditions are false. |
| 53 | |
| 54 | <h2>Example</h2> |
| 55 | |
| 56 | <pre><code> |
| 57 | <if> |
| 58 | <equals arg1="${foo}" arg2="bar" /> |
| 59 | <then> |
| 60 | <echo message="The value of property foo is bar" /> |
| 61 | </then> |
| 62 | <else> |
| 63 | <echo message="The value of property foo is not bar" /> |
| 64 | </else> |
| 65 | </if> |
| 66 | </code></pre> |
| 67 | |
| 68 | <pre><code> |
| 69 | <if> |
| 70 | <equals arg1="${foo}" arg2="bar" /> |
| 71 | <then> |
| 72 | <echo message="The value of property foo is 'bar'" /> |
| 73 | </then> |
| 74 | |
| 75 | <elseif> |
| 76 | <equals arg1="${foo}" arg2="foo" /> |
| 77 | <then> |
| 78 | <echo message="The value of property foo is 'foo'" /> |
| 79 | </then> |
| 80 | </elseif> |
| 81 | |
| 82 | |
| 83 | <else> |
| 84 | <echo message="The value of property foo is not 'foo' or 'bar'" /> |
| 85 | </else> |
| 86 | </if> |
| 87 | </code></pre> |
| 88 | |
| 89 | <hr> |
| 90 | <p align="center">Copyright © 2002-2003 Ant-Contrib Project. All |
| 91 | rights Reserved.</p> |
| 92 | |
| 93 | </body> |
| 94 | </html> |