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 <presetdef> 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 | <presetdef name="my.javac">
|
---|
61 | <javac debug="${debug}" deprecation="${deprecation}"
|
---|
62 | srcdir="${src.dir}" destdir="${classes.dir}">
|
---|
63 | <src path="${gen.dir}"/>
|
---|
64 | </javac>
|
---|
65 | </presetdef>
|
---|
66 | </pre>
|
---|
67 | </blockquote>
|
---|
68 | This can be used as a normal javac task - example:
|
---|
69 | <blockquote>
|
---|
70 | <pre class="code">
|
---|
71 | <my.javac/>
|
---|
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 | <my.javac srcdir="${test.src}" deprecation="no"/>
|
---|
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 | <antlib>
|
---|
87 | <taskdef resource="com/acme/antgoodies/tasks.properties"/>
|
---|
88 | <!-- Implement the common use of the javac command -->
|
---|
89 | <presetdef name="javac">
|
---|
90 | <javac deprecation="${deprecation}" debug="${debug}"
|
---|
91 | srcdir="src" destdir="classes"/>
|
---|
92 | </presetdef>
|
---|
93 | </antlib>
|
---|
94 | </pre>
|
---|
95 | </blockquote>
|
---|
96 | One may then use this in a build file as follows:
|
---|
97 | <blockquote>
|
---|
98 | <pre class="code">
|
---|
99 | <project default="example" xmlns:antgoodies="antlib:com.acme.antgoodies">
|
---|
100 | <target name="example">
|
---|
101 | <!-- Compile source -->
|
---|
102 | <antgoodies:javac srcdir="src/main"/>
|
---|
103 | <!-- Compile test code -->
|
---|
104 | <antgoodies:javac srcdir="src/test"/>
|
---|
105 | </target>
|
---|
106 | </project>
|
---|
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 | <target name="defineandcall">
|
---|
116 | <presetdef name="showmessage">
|
---|
117 | <echo>message is '${message}'</echo>
|
---|
118 | </presetdef>
|
---|
119 | <showmessage/>
|
---|
120 | <property name="message" value="Message 1"/>
|
---|
121 | <showmessage/>
|
---|
122 | <antcall target="called">
|
---|
123 | <param name="message" value="Message 2"/>
|
---|
124 | </antcall>
|
---|
125 | </target>
|
---|
126 | <target name="called">
|
---|
127 | <showmessage/>
|
---|
128 | </target>
|
---|
129 | </pre>
|
---|
130 | </blockquote>
|
---|
131 | <p>
|
---|
132 | The command ant defineandcall results in the output:
|
---|
133 | </p>
|
---|
134 | <blockquote>
|
---|
135 | <pre class="code">
|
---|
136 | defineandcall:
|
---|
137 | [showmessage] message is '${message}'
|
---|
138 | [showmessage] message is 'Message 1'
|
---|
139 |
|
---|
140 | called:
|
---|
141 | [showmessage] message is 'Message 2'
|
---|
142 | </pre>
|
---|
143 | </blockquote>
|
---|
144 | <hr></hr>
|
---|
145 | <p align="center">Copyright © 2003-2004 The Apache Software
|
---|
146 | Foundation. All rights Reserved.</p>
|
---|
147 |
|
---|
148 | </body>
|
---|
149 | </html>
|
---|
150 |
|
---|