source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual/manual/CoreTasks/typedef.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 8.4 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>Typedef Task</title>
23</head>
24
25<body>
26
27<h2><a name="typedef">Typedef</a></h2>
28<h3>Description</h3>
29 <p>
30 Adds a task or a data type definition to the current project
31 such that this new type or task can be used in the current project.
32 </p>
33 <p>
34 A Task is any class that extends org.apache.tools.ant.Task or
35 can be adapted as a Task using an adapter class.
36 </p>
37 <p>
38 Data types are things like <a href="../using.html#path">paths</a> or
39 <a href="../CoreTypes/fileset.html">filesets</a> that can be defined at
40 the project level and referenced via their ID attribute.
41 Custom data types usually need custom tasks to put them to good use.
42 </p>
43 <p>
44 Two attributes are needed to make a definition: the name that
45 identifies this data type uniquely, and the full name of the class
46 (including its package name) that implements this type.
47 </p>
48 <p>
49 You can also define a group of definitions at once using the file or
50 resource attributes. These attributes point to files in the format of
51 Java property files or an xml format.
52 </p>
53 <p>
54 For property files each line defines a single data type in the
55 format:</p>
56 <pre>
57 typename=fully.qualified.java.classname
58 </pre>
59
60 <p>
61 The xml format is described in the
62 <a href="../CoreTypes/antlib.html">Antlib</a> section.
63 </p>
64
65<h3>Parameters</h3>
66<table border="1" cellpadding="2" cellspacing="0">
67 <tr>
68 <td valign="top"><b>Attribute</b></td>
69 <td valign="top"><b>Description</b></td>
70 <td align="center" valign="top"><b>Required</b></td>
71 </tr>
72 <tr>
73 <td valign="top">name</td>
74 <td valign="top">the name of the data type</td>
75 <td valign="top" align="center">Yes, unless the file or resource type
76 attributes have been specified.</td>
77 </tr>
78 <tr>
79 <td valign="top">classname</td>
80 <td valign="top">the full class name implementing the data type</td>
81 <td valign="top" align="center">Yes, unless file or resource
82 have been specified.</td>
83 </tr>
84 <tr>
85 <td valign="top">file</td>
86 <td valign="top">Name of the file to load definitions from.</td>
87 <td valign="top" align="center">No</td>
88 </tr>
89 <tr>
90 <td valign="top">resource</td>
91 <td valign="top">
92 Name of the resource to load definitions from.
93 If multiple resources by this name are found along the classpath,
94 and the format is "properties", the first resource will be loaded;
95 otherwise all such resources will be loaded.
96 </td>
97 <td valign="top" align="center">No</td>
98 </tr>
99 <tr>
100 <td valign="top">format</td>
101 <td valign="top">The format of the file or resource. The values
102 are "properties" or "xml". If the value is "properties" the file/resource
103 is a property file contains name to classname pairs. If the value
104 is "xml", the file/resource is an xml file/resource structured according
105 to <a href="../CoreTypes/antlib.html">Antlib</a>.
106 The default is "properties" unless the file/resource name ends with
107 ".xml", in which case the format attribute will have the value "xml".
108 <b>since Ant 1.6</b>
109 </td>
110 <td valign="top" align="center">No</td>
111 </tr>
112 <tr>
113 <td valign="top">classpath</td> <td valign="top">the classpath to
114 use when looking up <code>classname</code>.</td>
115 <td align="center" valign="top">No</td>
116 </tr>
117 <tr>
118 <td valign="top">classpathref</td>
119 <td valign="top">
120 a reference to a classpath to use when looking up <code>classname</code>.
121 </td>
122 <td align="center" valign="top">No</td>
123 </tr>
124 <tr>
125 <td valign="top">loaderRef</td>
126 <td valign="top">the name of the loader that is
127 used to load the class, constructed from the specified classpath. Use
128 this to allow multiple tasks/types to be loaded with the same loader,
129 so they can call each other. <b>since Ant 1.5</b> </td>
130 <td align="center" valign="top">No</td>
131 </tr>
132 <tr>
133 <td valign="top">onerror</td>
134 <td valign="top">The action to take if there was a failure in defining the
135 type. The values are <i>fail</i>: cause a build exception; <i>report</i>:
136 output a warning, but continue; <i>ignore</i>: do nothing.
137 <b>since Ant 1.6</b>
138 An additional value is <i>failall</i>: cause all behavior of fail,
139 as well as a build exception for the resource or file attribute
140 if the resource or file is not found. <b>since Ant 1.7</b>
141 The default is <i>fail</i>.
142 </td>
143 <td valign="top" align="center">No</td>
144 </tr>
145 <tr>
146 <td valign="top">adapter</td>
147 <td valign="top">A class that is used to adapt the defined class to
148 another interface/class. The adapter class must implement the interface
149 "org.apache.tools.ant.TypeAdapter". The adapter class will be used
150 to wrap the defined class unless the defined class implements/extends
151 the class defined by the attribute "adaptto".
152 If "adaptto" is not set, the defined class will always be wrapped.
153 <b>since Ant 1.6</b>
154 </td>
155 <td valign="top" align="center">No</td>
156 </tr>
157 <tr>
158 <td valign="top">adaptto</td>
159 <td valign="top">This attribute is used in conjunction with the
160 adapter attribute.
161 If the defined class does not implement/extend the interface/class
162 specified by this attribute, the adaptor class will be used
163 to wrap the class. <b>since Ant 1.6</b>
164 </td>
165 <td valign="top" align="center">No</td>
166 </tr>
167 <tr>
168 <td valign="top">uri</td>
169 <td valign="top">
170 The uri that this definition should live in.
171 <b>since Ant 1.6</b>
172 </td>
173 <td valign="top" align="center">No</td>
174 </tr>
175</table>
176 <h3>Parameters specified as nested elements</h3>
177 <h4>classpath</h4>
178 <p><code>Typedef</code>'s <i>classpath</i> attribute is a
179 <a href="../using.html#path">path-like structure</a> and can also be set
180 via a nested <i>classpath</i> element.</p>
181
182<h3>Examples</h3>
183 The following fragment defines define a type called <i>urlset</i>.
184 <pre>
185 &lt;typedef name="urlset" classname="com.mydomain.URLSet"/&gt; </pre>
186 The data type is now available to Ant. The
187 class <code>com.mydomain.URLSet</code> implements this type.</p>
188
189
190 <p>
191 Assuming a class <i>org.acme.ant.RunnableAdapter</i> that
192 extends Task and implements <i>org.apache.tools.ant.TypeAdapter</i>,
193 and in the execute method invokes <i>run</i> on the proxied object,
194 one may use a Runnable class as an Ant task. The following fragment
195 defines a task called <i>runclock</i>.
196 </p>
197 <pre>
198 &lt;typedef name="runclock"
199 classname="com.acme.ant.RunClock"
200 adapter="org.acme.ant.RunnableAdapter"/&gt;
201 </pre>
202
203
204 <p>
205 The following fragment shows the use of the classpathref and
206 loaderref to load up two definitions.
207 </p>
208 <pre>
209 &lt;path id="lib.path"&gt;
210 &lt;fileset dir="lib" includes="lib/*.jar"/&gt;
211 &lt;/path&gt;
212
213 &lt;typedef name="filter1"
214 classname="org.acme.filters.Filter1"
215 classpathref="lib.path"
216 loaderref="lib.path.loader"
217 /&gt;
218 &lt;typedef name="filter2"
219 classname="org.acme.filters.Filter2"
220 loaderref="lib.path.loader"
221 /&gt;
222 </pre>
223
224
225 <p>
226 If you want to load an antlib into a special xml-namespace, the <tt>uri</tt> attribute
227 is important:
228 </p>
229 <pre>
230 &lt;project xmlns:antcontrib="antlib:net.sf.antcontrib"&gt;
231 &lt;taskdef uri="antlib:net.sf.antcontrib"
232 resource="net/sf/antcontrib/antlib.xml"
233 classpath="path/to/ant-contrib.jar"/&gt;
234 </pre>
235
236
237
238
239</body>
240</html>
241
Note: See TracBrowser for help on using the repository browser.