source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/typedef.html@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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