diff options
Diffstat (limited to 'docs/manual/tasks/variable_task.html')
-rw-r--r-- | docs/manual/tasks/variable_task.html | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/docs/manual/tasks/variable_task.html b/docs/manual/tasks/variable_task.html new file mode 100644 index 0000000..7e16ab9 --- /dev/null +++ b/docs/manual/tasks/variable_task.html @@ -0,0 +1,261 @@ +<html> +<head> +<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> +Variable Task</title> +<meta content="DocBook XSL Stylesheets V1.60.1" name="generator"> +<link rel="home" href="index.html" title="Antelope Users Guide"> +<link rel="up" href="bk03.html" title="Additional Ant Tasks"> +<link rel="previous" href="bk03ch07.html" title="Chapter 7. Try Task"> +<link rel="next" href="bk03ch09.html" title="Chapter 9. Stopwatch"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<div class="chapter" lang="en"> +<div class="titlepage"> +<div> +<div> +<h2 class="title"> +<a name="Variable"> +</a> +Chapter 8. Variable Task</h2> +</div> +</div> +<div> +</div> +</div> +<p> + +The Variable task provides a mutable property to Ant and works much like variable assignment in Java. This task is similar to the standard Ant Property task, except that THESE PROPERTIES ARE MUTABLE. While this goes against the standard Ant use of properties, occasionally it is useful to be able to change a property value within the build. <span class="bold"> +<b> +In general, use of this task is DISCOURAGED, and the standard Ant Property should be used if possible.</b> +</span> + Having said that, in real life I use this a lot. +</p> + +<p> + +Variables can be set individually or loaded from a standard properties file. A 'feature' of variables is that they can override properties, but properties cannot override variables. So if an already established property exists, its value can be reassigned by use of this task. +</p> +<p> + +<div class="table"> +<a name="N108CD"> +</a> +<p class="title"> +<b> +Table 8.1. Variable Task Attributes</b> +</p> +<table summary="Variable Task Attributes" border="1"> +<colgroup> +<col> +<col> +<col> +<col> +</colgroup> +<thead> +<tr> +<th> +Attribute</th> +<th> +Description</th> +<th> +Default</th> +<th> +Required</th> +</tr> +</thead> +<tbody> +<tr> +<td> +name</td> +<td> +The name of the property to set.</td> +<td> +None</td> +<td> +Yes, unless 'file' is used.</td> +</tr> +<tr> +<td> +value</td> +<td> +The value of the property.</td> +<td> +""</td> +<td> +No</td> +</tr> +<tr> +<td> +unset</td> +<td> +Removes the property from the project as if it had never been set.</td> +<td> +false +</td> +<td> +No +</td> +</tr> +<tr> +<td> +file</td> +<td> +The name of a standard properties file to load variables from.</td> +<td> +None</td> +<td> +No</td> +</tr> +</tbody> +</table> +</div> + +</p> +<p> + +In the following example, the property <tt class="computeroutput"> +x</tt> + is first set to "6", then evaluated by the <tt class="computeroutput"> +if</tt> +, and reassigned the value "12". The <tt class="computeroutput"> +echo</tt> + task will print out 12. +</p> +<p> + +<table border="0" bgcolor="#E0E0E0"> +<tr> +<td> +<pre class="programlisting"> + + + <var name="x" value="6"/> + <if> + <equals arg1="${x}" arg2="6" /> + <then> + <var name="x" value="12"/> + </then> + </if> + <echo>${x}</echo> <!-- will print 12 --> + +</pre> +</td> +</tr> +</table> + +</p> + +<p> +The next example shows a property being set, echoed, unset, then reset: +<table border="0" bgcolor="#E0E0E0"> +<tr> +<td> +<pre class="programlisting"> + + + <property name="x" value="6"/> + <echo>${x}</echo> <!-- will print 6 --> + <var name="x" unset="true"/> + <property name="x" value="12"/> + <echo>${x}</echo> <!-- will print 12 --> + + +</pre> +</td> +</tr> +</table> + +</p> + +<p> + +The following shows some more uses of the Variable task. It is especially handy for property appending. Notice a couple of things: the property task can't override a var value, in general, you should use var with the unset attribute to change the value of a property. +</p> +<p> + +<table border="0" bgcolor="#E0E0E0"> +<tr> +<td> +<pre class="programlisting"> + + + <var name="x" value="6"/> + <echo>x = ${x}</echo> <!-- print: 6 --> + + <var name="x" value="12"/> + <echo>x = ${x}</echo> <!-- print: 12 --> + + <var name="x" value="6 + ${x}"/> + <echo>x = ${x}</echo> <!-- print: 6 + 12 --> + + <var name="str" value="I "/> + <var name="str" value="${str} am "/> + <var name="str" value="${str} a "/> + <var name="str" value="${str} string."/> + <echo>${str}</echo> <!-- print: I am a string. --> + + <var name="x" value="6"/> + <echo>x = ${x}</echo> <!-- print: 6 --> + + <property name="x" value="12"/> + <echo>x = ${x}</echo> <!-- print: 6 (property can't override) --> + + <var name="x" value="blue"/> + <tstamp> + <format property="x" pattern="EEEE"/> + </tstamp> + <echo>Today is ${x}.</echo> <!-- print: Today is blue. --> + + <var name="x" value="" unset="true"/> + <tstamp> + <format property="x" pattern="EEEE"/> + </tstamp> + <echo>Today is ${x}.</echo> <!-- print: Today is Friday. --> + + +</pre> +</td> +</tr> +</table> + +</p> +<p> + +<!-- +The next example shows Variable, If, Assert, and Try working together to make sure e-mail is sent from the right address and that if the mail fails to be sent for any reason, the build will not fail. +</p> +<p> + +<table border="0" bgcolor="#E0E0E0"> +<tr> +<td> +<pre class="programlisting"> + + + <var name="valid_email" value="false"/> + <if name="email_from" value="[email protected]"> + <var name="valid_email" value="true"/> + </if> + <if name="email_from" value="[email protected]"> + <var name="valid_email" value="true"/> + </if> + <assert name="valid_email" value="true" failonerror="false"> + <try> + <mail from="${email_from}" tolist="${email_to}" + message="New release available"/> + </try> + </assert> + +</pre> +</td> +</tr> +</table> +--> +</p> +</div> + <hr> + <p align="center">Copyright © 2003-2004 Ant-Contrib Project. All + rights Reserved.</p> +</body> +</html> |