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

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

initial import of LiRK3

File size: 6.4 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/resorce 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">loaderRef</td> <td valign="top">the name of the loader that is
105 used to load the class, constructed from the specified classpath. Use this to
106 allow multiple tasks/types to be loaded with the same loader, so they can call
107 each other. ( introduced in ant1.5 )</td>
108 <td align="center" valign="top">No</td>
109 </tr>
110 <tr>
111 <td valign="top">onerror</td>
112 <td valign="top">The action to take if there was a failure in defining the
113 type. The values are <i>fail</i> - cause a build exception, <i>report</i>,
114 output a warning, but continue, <i>ignore</i>, do nothing. The default
115 is <i>fail</i>.
116 (introduced in ant1.6)
117 </td>
118 <td valign="top" align="center">No</td>
119 </tr>
120 <tr>
121 <td valign="top">adapter</td>
122 <td valign="top">A class that is used to adapt the defined class to
123 another interface/class. The adapter class must implement the interface
124 "org.apache.tools.ant.TypeAdapter". The adapter class will be used
125 to wrap the defined class unless the defined class implements/extends
126 the class defined by the attribute "adaptto".
127 If "adaptto" is not set,
128 the defined class will always be wrapped.
129 (introduced in ant1.6)
130 </td>
131 <td valign="top" align="center">No</td>
132 </tr>
133 <tr>
134 <td valign="top">adaptto</td>
135 <td valign="top">This attribute is used in conjunction with the
136 adapter attribute.
137 If the defined class does not implement/extend the interface/class
138 specified by this attribute, the adaptor class will be used
139 to wrap the class.
140 (introduced in ant1.6)
141 </td>
142 <td valign="top" align="center">No</td>
143 </tr>
144 <tr>
145 <td valign="top">uri</td>
146 <td valign="top">
147 The uri that this definition should live in.
148 <em>since Ant1.6</em>
149 </td>
150 <td valign="top" align="center">No</td>
151 </tr>
152</table>
153 <h3>Parameters specified as nested elements</h3>
154 <h4>classpath</h4>
155 <p><code>Typedef</code>'s <i>classpath</i> attribute is a
156 <a href="../using.html#path">PATH like structure</a> and can also be set
157 via a nested <i>classpath</i> element.</p>
158
159<h3>Examples</h3>
160 The following fragment defines define a type called <i>urlset</i>.
161 <pre>
162 &lt;typedef name="urlset" classname="com.mydomain.URLSet"/&gt; </pre>
163 The data type is now availabe to Ant. The
164 class <code>com.mydomain.URLSet</code> implements this type.</p>
165 <p>
166 Assuming a class <i>org.acme.ant.RunnableAdapter</i> that
167 extends Task and implements <i>org.apache.tools.ant.TypeAdapter</i>,
168 and in the execute method invokes <i>run</i> on the proxied object,
169 one may use a Runnable class as an Ant task. The following fragment
170 defines a task called <i>runclock</i>.
171 <pre>
172 &lt;typedef name="runclock"
173 classname="com.acme.ant.RunClock"
174 adapter="org.acme.ant.RunnableAdapter"/&gt;
175 </pre>
176<hr>
177<p align="center">Copyright &copy; 2001-2004 The Apache Software
178Foundation. All rights Reserved.</p>
179
180</body>
181</html>
182
Note: See TracBrowser for help on using the repository browser.