source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/manual/CoreTasks/presetdef.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 4.5 KB
Line 
1<html>
2
3 <head>
4 <meta http-equiv="Content-Language" content="en-us"></meta>
5 <title>PreSetDef Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7 </head>
8
9 <body>
10
11 <a name="presetdef"></a><h2>PreSetDef</h2>
12 <h3>Description</h3>
13 <p>
14 The preset definition generates a new definition
15 based on a current definition with some attributes
16 or elements preset.
17 </p>
18 <p>
19 <em>since Ant 1.6</em>
20 </p>
21 <p>
22 The resolution of properties in any of the attributes or
23 nested text takes place with the definition is used and <em>not</em>
24 when the preset definition is defined.
25 </p>
26 <h3>Parameters</h3>
27 <table border="1" cellpadding="2" cellspacing="0">
28 <tr>
29 <td valign="top"><b>Attribute</b></td>
30 <td valign="top"><b>Description</b></td>
31 <td align="center" valign="top"><b>Required</b></td>
32 </tr>
33 <tr>
34 <td valign="top">name</td>
35 <td valign="top">the name of the new definition</td>
36 <td valign="top" align="center">Yes</td>
37 </tr>
38 <tr>
39 <td valign="top">uri</td>
40 <td valign="top">
41 The uri that this definition should live in.
42 </td>
43 <td valign="top" align="center">No</td>
44 </tr>
45 </table>
46 <h3>Parameters specified as nested elements</h3>
47 <h4>another type with attributes or elements set</h4>
48 <p>The &lt;presetdef&gt; task takes one nested element as a parameter.
49 This nested element can be any other type or task. The attributes
50 and elements that need to be preset are placed here.
51 </p>
52
53 <h3>Examples</h3>
54 The following fragment defines a javac task with the debug, deprecation
55 srcdir and destdir
56 attributes set. It also has a src element to source files from a generated
57 directory.
58 <blockquote>
59<pre class="code">
60&lt;presetdef name="my.javac"&gt;
61 &lt;javac debug="${debug}" deprecation="${deprecation}"
62 srcdir="${src.dir}" destdir="${classes.dir}"&gt;
63 &lt;src path="${gen.dir}"/&gt;
64 &lt;/javac&gt;
65&lt;/presetdef&gt;
66</pre>
67 </blockquote>
68 This can be used as a normal javac task - example:
69 <blockquote>
70<pre class="code">
71&lt;my.javac/&gt;
72</pre>
73 </blockquote>
74 The attributes specified in the preset task may be overridden - i.e.
75 they may be seen as optional attributes - example:
76 <blockquote>
77<pre class="code">
78&lt;my.javac srcdir="${test.src}" deprecation="no"/&gt;
79</pre>
80 </blockquote>
81 One may put a presetdef definition in an antlib.
82 For example suppose the jar file antgoodies.jar has
83 the antlib.xml as follows:
84 <blockquote>
85<pre class="code">
86&lt;antlib&gt;
87 &lt;taskdef resource="com/acme/antgoodies/tasks.properties"/&gt;
88 &lt;!-- Implement the common use of the javac command --&gt;
89 &lt;presetdef name="javac"&gt;
90 &lt;javac deprecation="${deprecation}" debug="${debug}"
91 srcdir="src" destdir="classes"/&gt;
92 &lt;/presetdef&gt;
93&lt;/antlib&gt;
94</pre>
95 </blockquote>
96 One may then use this in a build file as follows:
97 <blockquote>
98<pre class="code">
99&lt;project default="example" xmlns:antgoodies="antlib:com.acme.antgoodies"&gt;
100 &lt;target name="example"&gt;
101 &lt;!-- Compile source --&gt;
102 &lt;antgoodies:javac srcdir="src/main"/&gt;
103 &lt;!-- Compile test code --&gt;
104 &lt;antgoodies:javac srcdir="src/test"/&gt;
105 &lt;/target&gt;
106&lt;/project&gt;
107</pre>
108 </blockquote>
109 <p>
110 The following is an example of evaluation of properties when the
111 definition is used:
112 </p>
113 <blockquote>
114<pre class="code">
115&lt;target name="defineandcall"&gt;
116 &lt;presetdef name="showmessage"&gt;
117 &lt;echo&gt;message is '${message}'&lt;/echo&gt;
118 &lt;/presetdef&gt;
119 &lt;showmessage/&gt;
120 &lt;property name="message" value="Message 1"/&gt;
121 &lt;showmessage/&gt;
122 &lt;antcall target="called"&gt;
123 &lt;param name="message" value="Message 2"/&gt;
124 &lt;/antcall&gt;
125&lt;/target&gt;
126&lt;target name="called"&gt;
127 &lt;showmessage/&gt;
128&lt;/target&gt;
129</pre>
130 </blockquote>
131 <p>
132 The command ant defineandcall results in the output:
133 </p>
134 <blockquote>
135<pre class="code">
136defineandcall:
137[showmessage] message is '${message}'
138[showmessage] message is 'Message 1'
139
140called:
141[showmessage] message is 'Message 2'
142</pre>
143 </blockquote>
144 <hr></hr>
145 <p align="center">Copyright &copy; 2003-2004 The Apache Software
146 Foundation. All rights Reserved.</p>
147
148 </body>
149</html>
150
Note: See TracBrowser for help on using the repository browser.