Debian Codegraph @

manual/Types/mapper.html

raw
1 <!DOCTYPE html>
2 <!--
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 https://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 -->
18 <html lang="en">
19
20 <head>
21 <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22 <title>Mapper Type</title>
23 </head>
24
25 <body>
26
27 <h2 id="mapper">Mapping File Names</h2>
28 <p>Some tasks take source files and create target files. Depending on the task, it may be quite
29 obvious which name a target file will have (using <a href="../Tasks/javac.html">javac</a>, you know
30 there will be <samp>.class</samp> files for your <samp>.java</samp> files)&mdash;in other cases you
31 may want to specify the target files, either to help Apache Ant or to get an extra bit of
32 functionality.</p>
33 <p>While source files are usually specified as <a href="fileset.html">fileset</a>s, you don't
34 specify target files directly&mdash;instead, you tell Ant how to find the target file(s) for one
35 source file. An instance of <code class="code">org.apache.tools.ant.util.FileNameMapper</code> is
36 responsible for this. It constructs target file names based on rules that can be parameterized
37 with <var>from</var> and <var>to</var> attributes&mdash;the exact meaning of which is
38 implementation-dependent.</p>
39 <p>These instances are defined in <code>&lt;mapper&gt;</code> elements with the following
40 attributes:</p>
41 <table class="attr">
42 <tr>
43 <th scope="col">Attribute</th>
44 <th scope="col">Description</th>
45 <th scope="col">Required</th>
46 </tr>
47 <tr>
48 <td>type</td>
49 <td>specifies one of the built-in implementations.</td>
50 <td rowspan="2">Exactly one of these</td>
51 </tr>
52 <tr>
53 <td>classname</td>
54 <td class="left">specifies the implementation by class name.</td>
55 </tr>
56 <tr>
57 <td>classpath</td>
58 <td>the classpath to use when looking up
59 <code>classname</code>.</td>
60 <td>No</td>
61 </tr>
62 <tr>
63 <td>classpathref</td>
64 <td>the classpath to use, given as <a href="../using.html#references">reference</a> to a
65 path defined elsewhere.</td>
66 <td>No</td>
67 </tr>
68 <tr>
69 <td>from</td>
70 <td>the <code>from</code> attribute for the given implementation.</td>
71 <td>Depends on implementation</td>
72 </tr>
73 <tr>
74 <td>to</td>
75 <td>the <code>to</code> attribute for the given implementation.</td>
76 <td>Depends on implementation</td>
77 </tr>
78 <tr>
79 <td>refid</td>
80 <td>Makes this <code>mapper</code>
81 a <a href="../using.html#references">reference</a> to
82 a <code>mapper</code> defined elsewhere. If specified no other
83 attributes or nested elements are allowed.</td>
84 <td>No</td>
85 </tr>
86 </table>
87 <p>Note that Ant will not automatically convert <q>/</q> or <q>\</q> characters in the <var>to</var>
88 and <var>from</var> attributes to the correct directory separator of your current platform. If you
89 need to specify this separator, use <code>${file.separator}</code> instead. For the regexp
90 mapper, <code>${file.separator}</code> will not work, as on Windows it is the <q>\</q> character,
91 and this is an escape character for regular expressions, one should use
92 the <code>handledirsep</code> attribute instead.
93 </p>
94 <h3>Parameters specified as nested elements</h3>
95 <p>The classpath can be specified via a nested <code>&lt;classpath&gt;</code>, as well&mdash;that
96 is, a <a href="../using.html#path">path</a>-like structure.</p>
97 <p><em>Since Ant 1.7.0</em>, nested File Mappers can be supplied via
98 either <code>&lt;mapper&gt;</code> elements
99 or <a href="../Tasks/typedef.html"><code>&lt;typedef&gt;</code></a>'d implementations
100 of <code class="code">org.apache.tools.ant.util.FileNameMapper</code>. If nested File Mappers are
101 specified by either means, the mapper will be implicitly configured as
102 a <a href="#composite-mapper">composite mapper</a>.</p>
103 <h3>The built-in mapper types</h3>
104 <p>All built-in mappers are case-sensitive.</p>
105 <p><em>Since Ant 1.7.0</em>, each of the built-in mapper implementation types is directly accessible
106 using a specific tagname. This makes it possible for filename mappers to support attributes in
107 addition to the generally available <var>to</var> and <var>from</var>.<br/>
108 The <code>&lt;mapper <var>type</var>|<var>classname</var>=&quot;...&quot;&gt;</code> usage form
109 remains valid for reasons of backward compatibility.</p>
110
111 <!-- -->
112 <!-- Identity Mapper -->
113 <!-- -->
114
115 <h4 id="identity-mapper">identity</h4>
116 <p>The target file name is identical to the source file name. Both <var>to</var> and <var>from</var>
117 will be ignored.</p>
118 <h5>Examples</h5>
119 <pre>
120 &lt;mapper type=&quot;identity&quot;/&gt;
121 &lt;identitymapper/&gt;</pre>
122 <table>
123 <tr>
124 <th scope="col">Source file name</th>
125 <th scope="col">Target file name</th>
126 </tr>
127 <tr>
128 <td><code>A.java</code></td>
129 <td><code>A.java</code></td>
130 </tr>
131 <tr>
132 <td><code>foo/bar/B.java</code></td>
133 <td><code>foo/bar/B.java</code></td>
134 </tr>
135 <tr>
136 <td><code>C.properties</code></td>
137 <td><code>C.properties</code></td>
138 </tr>
139 <tr>
140 <td><code>Classes/dir/dir2/A.properties</code></td>
141 <td><code>Classes/dir/dir2/A.properties</code></td>
142 </tr>
143 </table>
144
145 <!-- -->
146 <!-- Flatten Mapper -->
147 <!-- -->
148
149 <h4 id="flatten-mapper">flatten</h4>
150 <p>The target file name is identical to the source file name, with all leading directory information
151 stripped off. Both <var>to</var> and <var>from</var> will be ignored.</p>
152 <h5>Examples</h5>
153 <pre>
154 &lt;mapper type=&quot;flatten&quot;/&gt;
155 &lt;flattenmapper/&gt;</pre>
156 <table>
157 <tr>
158 <th scope="col">Source file name</th>
159 <th scope="col">Target file name</th>
160 </tr>
161 <tr>
162 <td><code>A.java</code></td>
163 <td><code>A.java</code></td>
164 </tr>
165 <tr>
166 <td><code>foo/bar/B.java</code></td>
167 <td><code>B.java</code></td>
168 </tr>
169 <tr>
170 <td><code>C.properties</code></td>
171 <td><code>C.properties</code></td>
172 </tr>
173 <tr>
174 <td><code>Classes/dir/dir2/A.properties</code></td>
175 <td><code>A.properties</code></td>
176 </tr>
177 </table>
178
179 <!-- -->
180 <!-- Merge Mapper -->
181 <!-- -->
182
183 <h4 id="merge-mapper">merge</h4>
184 <p>The target file name will always be the same, as defined by <var>to</var>&mdash;<var>from</var>
185 will be ignored.</p>
186 <h5>Examples</h5>
187 <pre>
188 &lt;mapper type=&quot;merge&quot; to=&quot;archive.tar&quot;/&gt;
189 &lt;mergemapper to=&quot;archive.tar&quot;/&gt;</pre>
190 <table>
191 <tr>
192 <th scope="col">Source file name</th>
193 <th scope="col">Target file name</th>
194 </tr>
195 <tr>
196 <td><code>A.java</code></td>
197 <td><code>archive.tar</code></td>
198 </tr>
199 <tr>
200 <td><code>foo/bar/B.java</code></td>
201 <td><code>archive.tar</code></td>
202 </tr>
203 <tr>
204 <td><code>C.properties</code></td>
205 <td><code>archive.tar</code></td>
206 </tr>
207 <tr>
208 <td><code>Classes/dir/dir2/A.properties</code></td>
209 <td><code>archive.tar</code></td>
210 </tr>
211 </table>
212
213 <!-- -->
214 <!-- Glob Mapper -->
215 <!-- -->
216
217 <h4 id="glob-mapper">glob</h4>
218 <p>Both <var>to</var> and <var>from</var> are required and define patterns that may contain at most
219 one <q>*</q>. For each source file that matches the <var>from</var> pattern, a target file name will
220 be constructed from the <var>to</var> pattern by substituting the <q>*</q> in the <var>to</var>
221 pattern with the text that matches the <q>*</q> in the <var>from</var> pattern. Source file names
222 that don't match the <var>from</var> pattern will be ignored.</p>
223 <h5>Examples</h5>
224 <pre>
225 &lt;mapper type=&quot;glob&quot; from=&quot;*.java&quot; to=&quot;*.java.bak&quot;/&gt;
226 &lt;globmapper from=&quot;*.java&quot; to=&quot;*.java.bak&quot;/&gt;</pre>
227 <table>
228 <tr>
229 <th scope="col">Source file name</th>
230 <th scope="col">Target file name</th>
231 </tr>
232 <tr>
233 <td><code>A.java</code></td>
234 <td><code>A.java.bak</code></td>
235 </tr>
236 <tr>
237 <td><code>foo/bar/B.java</code></td>
238 <td><code>foo/bar/B.java.bak</code></td>
239 </tr>
240 <tr>
241 <td><code>C.properties</code></td>
242 <td>ignored</td>
243 </tr>
244 <tr>
245 <td><code>Classes/dir/dir2/A.properties</code></td>
246 <td>ignored</td>
247 </tr>
248 </table>
249 <pre>
250 &lt;mapper type=&quot;glob&quot; from=&quot;C*ies&quot; to=&quot;Q*y&quot;/&gt;
251 &lt;globmapper from=&quot;C*ies&quot; to=&quot;Q*y&quot;/&gt;</pre>
252 <table>
253 <tr>
254 <th scope="col">Source file name</th>
255 <th scope="col">Target file name</th>
256 </tr>
257 <tr>
258 <td><code>A.java</code></td>
259 <td>ignored</td>
260 </tr>
261 <tr>
262 <td><code>foo/bar/B.java</code></td>
263 <td>ignored</td>
264 </tr>
265 <tr>
266 <td><code>C.properties</code></td>
267 <td><code>Q.property</code></td>
268 </tr>
269 <tr>
270 <td><code>Classes/dir/dir2/A.properties</code></td>
271 <td><code>Qlasses/dir/dir2/A.property</code></td>
272 </tr>
273 </table>
274 <p>The <code>globmapper</code> mapper can take the following extra attributes.</p>
275 <table class="attr">
276 <tr>
277 <th scope="col">Attribute</th>
278 <th scope="col">Description</th>
279 <th scope="col">Required</th>
280 </tr>
281 <tr>
282 <td>casesensitive</td>
283 <td>
284 This attribute can be <q>true</q> or <q>false</q>. If this is <q>false</q>, the mapper will
285 ignore case when matching the glob pattern. <em>Since Ant 1.6.3</em>
286 </td>
287 <td>No; default is <q>true</q></td>
288 </tr>
289 <tr>
290 <td>handledirsep</td>
291 <td>
292 This attribute can be <q>true</q> or <q>false</q>. If this is specified, the mapper will
293 ignore the difference between the normal directory separator characters&mdash;<q>\</q>
294 and <q>/</q>. This attribute is useful for cross-platform build files. <em>Since Ant
295 1.6.3</em>
296 <td>No; default is <q>false</q></td>
297 </tr>
298 </table>
299 <p>An example:</p>
300 <pre>
301 &lt;pathconvert property="x" targetos="unix"&gt;
302 &lt;path path="Aj.Java"/&gt;
303 &lt;mapper&gt;
304 &lt;chainedmapper&gt;
305 &lt;flattenmapper/&gt;
306 &lt;globmapper from="a*.java" to="*.java.bak" casesensitive="no"/&gt;
307 &lt;/chainedmapper&gt;
308 &lt;/mapper&gt;
309 &lt;/pathconvert&gt;
310 &lt;echo&gt;x is ${x}&lt;/echo&gt;</pre>
311 <p>will output <code>x is j.java.bak</code>, and</p>
312 <pre>
313 &lt;pathconvert property="x" targetos="unix"&gt;
314 &lt;path path="d/e/f/j.java"/&gt;
315 &lt;mapper&gt;
316 &lt;globmapper from="${basedir}\d/e\*" to="*" handledirsep="yes"/&gt;
317 &lt;/mapper&gt;
318 &lt;/pathconvert&gt;
319 &lt;echo&gt;x is ${x}&lt;/echo&gt;</pre>
320 <p>will output <code>x is f/j.java</code>.</p>
321
322 <!-- -->
323 <!-- RegExp Mapper -->
324 <!-- -->
325
326 <h4 id="regexp-mapper">regexp</h4>
327
328 <p>Both <var>to</var> and <var>from</var> are required and define regular expressions. If the source
329 file name (as a whole or in part) matches the <var>from</var> pattern, the target file name will be
330 constructed from the <var>to</var> pattern, using <code>\0</code> to <code>\9</code> as
331 back-references for the full match (<code>\0</code>) or the matches of the subexpressions in
332 parentheses. The <var>to</var> pattern determines the <strong>whole</strong> file name, so if you
333 wanted to replace the extension of a file you should not use <code>from="\.old$" to=".new"</code>
334 but rather <code>from="(.*)\.old$" to="\1.new"</code> (or rather use a glob mapper in this
335 case).</p>
336
337 <p>Source files not matching the <var>from</var> pattern will be ignored.</p>
338
339 <p>Note that you need to escape a dollar-sign (<q>$</q>) with another dollar-sign in Ant.</p>
340
341 <p>For information about using <a href="https://savannah.gnu.org/projects/gnu-regexp/"
342 target="_top">gnu.regexp</a> or <a href="https://github.com/kzn/regex4j/" target="_top">gnu.rex</a>
343 with Ant, see <a href="https://marc.info/?l=ant-dev&m=97550753813481&w=2" target="_top">this</a>
344 article. Please keep in mind that <a href="http://tusker.org/regex/regex_benchmark.html"
345 target="_top">your mileage may vary</a> with different regexp engines.</p>
346
347 <p>If you want to use one of the <a href="../install.html#librarydependencies">regular expression
348 libraries</a> other than <code>java.util.regex</code> you need to also use the
349 corresponding <samp>ant-[apache-oro, apache-regexp].jar</samp> from the Ant release you are using.
350 Make sure that both will be loaded from the same classpath, that is either put them into
351 your <code>CLASSPATH</code>, <samp>ANT_HOME/lib</samp> directory or a
352 nested <code>&lt;classpath&gt;</code> element of the mapper&mdash;you cannot
353 have <samp>ant-[apache-oro, apache-regexp].jar</samp> in <samp>ANT_HOME/lib</samp> and the library
354 in a nested <code>&lt;classpath&gt;</code>.</p>
355 <p>Ant will choose the regular expression library based on the following algorithm:</p>
356 <ul>
357 <li>If the system property <code>ant.regexp.matcherimpl</code> has been set, it is taken as the name
358 of the class implementing <code class="code">org.apache.tools.ant.util.regexp.RegexpMatcher</code>
359 that should be used.</li>
360 <li>If it has not been set, uses the default from the <code>java.util.regex</code> package.</li>
361 </ul>
362
363 <h5>Examples</h5>
364 <pre>
365 &lt;mapper type=&quot;regexp&quot; from=&quot;^(.*)\.java$$&quot; to=&quot;\1.java.bak&quot;/&gt;
366 &lt;regexpmapper from=&quot;^(.*)\.java$$&quot; to=&quot;\1.java.bak&quot;/&gt;</pre>
367 <table>
368 <tr>
369 <th scope="col">Source file name</th>
370 <th scope="col">Target file name</th>
371 </tr>
372 <tr>
373 <td><code>A.java</code></td>
374 <td><code>A.java.bak</code></td>
375 </tr>
376 <tr>
377 <td><code>foo/bar/B.java</code></td>
378 <td><code>foo/bar/B.java.bak</code></td>
379 </tr>
380 <tr>
381 <td><code>C.properties</code></td>
382 <td>ignored</td>
383 </tr>
384 <tr>
385 <td><code>Classes/dir/dir2/A.properties</code></td>
386 <td>ignored</td>
387 </tr>
388 </table>
389 <pre>
390 &lt;mapper type=&quot;regexp&quot; from=&quot;^(.*)/([^/]+)/([^/]*)$$&quot; to=&quot;\1/\2/\2-\3&quot;/&gt;
391 &lt;regexpmapper from=&quot;^(.*)/([^/]+)/([^/]*)$$&quot; to=&quot;\1/\2/\2-\3&quot;/&gt;</pre>
392 <table>
393 <tr>
394 <th scope="col">Source file name</th>
395 <th scope="col">Target file name</th>
396 </tr>
397 <tr>
398 <td><code>A.java</code></td>
399 <td>ignored</td>
400 </tr>
401 <tr>
402 <td><code>foo/bar/B.java</code></td>
403 <td><code>foo/bar/bar-B.java</code></td>
404 </tr>
405 <tr>
406 <td><code>C.properties</code></td>
407 <td>ignored</td>
408 </tr>
409 <tr>
410 <td><code>Classes/dir/dir2/A.properties</code></td>
411 <td><code>Classes/dir/dir2/dir2-A.properties</code></td>
412 </tr>
413 </table>
414 <pre>
415 &lt;mapper type="regexp" from="^(.*)\.(.*)$$" to="\2.\1"/&gt;
416 &lt;regexpmapper from="^(.*)\.(.*)$$" to="\2.\1"/&gt;</pre>
417 <table>
418 <tr>
419 <th scope="col">Source file name</th>
420 <th scope="col">Target file name</th>
421 </tr>
422 <tr>
423 <td><code>A.java</code></td>
424 <td><code>java.A</code></td>
425 </tr>
426 <tr>
427 <td><code>foo/bar/B.java</code></td>
428 <td><code>java.foo/bar/B</code></td>
429 </tr>
430 <tr>
431 <td><code>C.properties</code></td>
432 <td><code>properties.C</code></td>
433 </tr>
434 <tr>
435 <td><code>Classes/dir/dir2/A.properties</code></td>
436 <td><code>properties.Classes/dir/dir2/A</code></td>
437 </tr>
438 </table>
439 <pre>
440 &lt;mapper type="regexp" from="^(.*?)(\$$[^/\\\.]*)?\.class$$" to="\1.java"/&gt;
441 &lt;regexpmapper from="^(.*?)(\$$[^/\\\.]*)?\.class$$" to="\1.java"/&gt;</pre>
442 <table>
443 <tr>
444 <th scope="col">Source file name</th>
445 <th scope="col">Target file name</th>
446 </tr>
447 <tr>
448 <td><code>ClassLoader.class</code></td>
449 <td><code>ClassLoader.java</code></td>
450 </tr>
451 <tr>
452 <td><code>java/lang/ClassLoader.class</code></td>
453 <td><code>java/lang/ClassLoader.java</code></td>
454 </tr>
455 <tr>
456 <td><code>java\lang\ClassLoader$1.class</code></td>
457 <td><code>java\lang\ClassLoader.java</code></td>
458 </tr>
459 <tr>
460 <td><code>java/lang/ClassLoader$foo$1.class</code></td>
461 <td><code>java/lang/ClassLoader.java</code></td>
462 </tr>
463 </table>
464 <p>The regexp mapper can take the following extra attributes.</p>
465 <table class="attr">
466 <tr>
467 <th scope="col">Attribute</th>
468 <th scope="col">Description</th>
469 <th scope="col">Required</th>
470 </tr>
471 <tr>
472 <td>casesensitive</td>
473 <td>
474 This attribute can be <q>true</q> or <q>false</q>. If this is <q>false</q>, the mapper will
475 ignore case when matching the pattern.
476 <em>Since Ant 1.6.3</em>
477 </td>
478 <td>No; default is <q>true</q></td>
479 </tr>
480 <tr>
481 <td>handledirsep</td>
482 <td>
483 This attribute can be <q>true</q> or <q>false</q>. If this is specified, the mapper will
484 treat a <q>\</q> character in a filename as a <q>/</q> for the purposes of matching. This
485 attribute is useful for cross-platform build files.
486 <em>Since Ant 1.6.3</em>
487 <td>No; default is <q>false</q></td>
488 </tr>
489 </table>
490 <p>An example:</p>
491 <pre>
492 &lt;pathconvert property="x" targetos="unix"&gt;
493 &lt;path path="Aj.Java"/&gt;
494 &lt;chainedmapper&gt;
495 &lt;flattenmapper/&gt;
496 &lt;regexpmapper from="a(.*)\.java" to="\1.java.bak" casesensitive="no"/&gt;
497 &lt;/chainedmapper&gt;
498 &lt;/pathconvert&gt;
499 &lt;echo&gt;x is ${x}&lt;/echo&gt;</pre>
500 <p>will output <code>x is j.java.bak</code>, and</p>
501 <pre>
502 &lt;pathconvert property="hd.prop" targetos="windows"&gt;
503 &lt;path path="d\e/f\j.java"/&gt;
504 &lt;chainedmapper&gt;
505 &lt;regexpmapper from="${basedir}/d/e/(.*)" to="\1" handledirsep="yes"/&gt;
506 &lt;/chainedmapper&gt;
507 &lt;/pathconvert&gt;</pre>
508 <p>will set <code>hd.prop</code> to <code>f\j.java</code>.</p>
509
510 <!-- -->
511 <!-- Package Mapper -->
512 <!-- -->
513
514 <h4 id="package-mapper">package</h4>
515 <p>Sharing the same syntax as the <a href="#glob-mapper">glob mapper</a>, the package mapper
516 replaces directory separators found in the matched source pattern with dots in the target pattern
517 placeholder. This mapper is particularly useful in combination with <code>&lt;uptodate&gt;</code>
518 and <code>&lt;junit&gt;</code> output.</p>
519 <p>The <var>to</var> and <var>from</var> attributes are both required.</p>
520 <h5>Example</h5>
521 <pre>
522 &lt;mapper type="package" from="*Test.java" to="TEST-*Test.xml"/&gt;
523 &lt;packagemapper from="*Test.java" to="TEST-*Test.xml"/&gt;</pre>
524 <table>
525 <tr>
526 <th scope="col">Source file name</th>
527 <th scope="col">Target file name</th>
528 </tr>
529 <tr>
530 <td><code>org/apache/tools/ant/util/PackageMapperTest.java</code></td>
531 <td><code>TEST-org.apache.tools.ant.util.PackageMapperTest.xml</code></td>
532 </tr>
533 <tr>
534 <td><code>org/apache/tools/ant/util/Helper.java</code></td>
535 <td>ignored</td>
536 </tr>
537 </table>
538
539 <!-- -->
540 <!-- Unpackage Mapper -->
541 <!-- -->
542
543 <h4 id="unpackage-mapper">unpackage</h4>
544 <p><em>Since Ant 1.6.0</em></p>
545 <p>This mapper is the inverse of the <a href="#package-mapper">package</a> mapper. It replaces the
546 dots in a package name with directory separators. This is useful for matching XML formatter results
547 against their JUnit test test cases. The mapper shares the sample syntax as
548 the <a href="#glob-mapper">glob mapper</a>.</p>
549 <p>The <var>to</var> and <var>from</var> attributes are both required.</p>
550 <h5>Example</h5>
551 <pre>
552 &lt;mapper type="unpackage" from="TEST-*Test.xml" to="${test.src.dir}/*Test.java"&gt;
553 &lt;unpackagemapper from="TEST-*Test.xml" to="${test.src.dir}/*Test.java"&gt;</pre>
554 <table>
555 <tr>
556 <th scope="col">Source file name</th>
557 <th scope="col">Target file name</th>
558 </tr>
559 <tr>
560 <td><code>TEST-org.acme.AcmeTest.xml</code></td>
561 <td><code>${test.src.dir}/org/acme/AcmeTest.java</code></td>
562 </tr>
563 </table>
564
565 <!-- -->
566 <!-- Composite Mapper -->
567 <!-- -->
568
569 <h4 id="composite-mapper">composite</h4>
570 <p><em>Since Ant 1.7.0</em></p>
571 <p>This mapper implementation can contain multiple nested mappers. File mapping is performed by
572 passing the source filename to each nested <code>&lt;mapper&gt;</code> in turn, returning all
573 results. The <var>to</var> and <var>from</var> attributes are ignored.</p>
574 <p><em>Since Ant 1.8.0</em>, the order of the mapped results is the same as the order of the nested
575 mappers; prior to Ant 1.8.0 the order has been undefined.</p>
576 <h5>Examples</h5>
577 <pre>
578 &lt;compositemapper&gt;
579 &lt;identitymapper/&gt;
580 &lt;packagemapper from="*.java" to="*"/&gt;
581 &lt;/compositemapper&gt;</pre>
582 <table>
583 <tr>
584 <th scope="col">Source file name</th>
585 <th scope="col">Target file names</th>
586 </tr>
587 <tr>
588 <td rowspan="2"><code>foo/bar/A.java</code></td>
589 <td><code>foo/bar/A.java</code></td>
590 </tr>
591 <tr>
592 <td><code>foo.bar.A</code></td>
593 </tr>
594 </table>
595 <p>The composite mapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var>
596 attribute.</p>
597
598 <!-- -->
599 <!-- Chained Mapper -->
600 <!-- -->
601
602 <h4 id="chained-mapper">chained</h4>
603 <p><em>Since Ant 1.7.0</em></p>
604 <p>This mapper implementation can contain multiple nested mappers. File mapping is performed by
605 passing the source filename to the first nested mapper, its results to the second, and so on. The
606 target filenames generated by the last nested mapper comprise the ultimate results of the mapping
607 operation. The <var>to</var> and <var>from</var> attributes are ignored.</p>
608 <h5>Examples</h5>
609 <pre>
610 &lt;chainedmapper&gt;
611 &lt;flattenmapper/&gt;
612 &lt;globmapper from="*" to="new/path/*"/&gt;
613 &lt;mapper&gt;
614 &lt;globmapper from="*" to="*1"/&gt;
615 &lt;globmapper from="*" to="*2"/&gt;
616 &lt;/mapper&gt;
617 &lt;/chainedmapper&gt;</pre>
618 <table>
619 <tr>
620 <th scope="col">Source file name</th>
621 <th scope="col">Target file names</th>
622 </tr>
623 <tr>
624 <td rowspan="2"><code>foo/bar/A.java</code></td>
625 <td><code>new/path/A.java1</code></td>
626 </tr>
627 <tr>
628 <td><code>new/path/A.java2</code></td>
629 </tr>
630 <tr>
631 <td rowspan="2"><code>boo/far/B.java</code></td>
632 <td><code>new/path/B.java1</code></td>
633 </tr>
634 <tr>
635 <td><code>new/path/B.java2</code></td>
636 </tr>
637 </table>
638 <p>The chained mapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var>
639 attribute.</p>
640
641 <!-- -->
642 <!-- Filter Mapper -->
643 <!-- -->
644
645 <h4 id="filter-mapper">filtermapper</h4>
646 <p><em>Since Ant 1.6.3</em></p>
647 <p>This mapper implementation applies a <a href="filterchain.html">filterchain</a> to the source
648 file name.</p>
649 <h5>Examples</h5>
650 <pre>
651 &lt;filtermapper&gt;
652 &lt;replacestring from="\" to="/"/&gt;
653 &lt;/filtermapper&gt;</pre>
654
655 <table>
656 <tr>
657 <th scope="col">Source file name</th>
658 <th scope="col">Target file names</th>
659 </tr>
660 <tr>
661 <td><code>foo\bar\A.java</code></td>
662 <td><code>foo/bar/A.java</code></td>
663 </tr>
664 </table>
665 <pre>
666 &lt;filtermapper&gt;
667 &lt;scriptfilter language="beanshell"&gt;
668 self.setToken(self.getToken().toUpperCase());
669 &lt;/scriptfilter&gt;
670 &lt;/filtermapper&gt;</pre>
671
672 <table>
673 <tr>
674 <th scope="col">Source file name</th>
675 <th scope="col">Target file names</th>
676 </tr>
677 <tr>
678 <td><code>foo\bar\A.java</code></td>
679 <td><code>FOO\BAR\A.JAVA</code></td>
680 </tr>
681 </table>
682
683 <p>The filtermapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var> attribute.</p>
684
685 <!-- -->
686 <!-- Script Mapper -->
687 <!-- -->
688
689 <h4 id="script-mapper">scriptmapper</h4>
690 <p><em>Since Ant 1.7</em></p>
691 <p>This mapper executes a script written in <a href="https://jakarta.apache.org/bsf"
692 target="_top">Apache BSF</a>
693 or <a href="https://jcp.org/aboutJava/communityprocess/maintenance/jsr223/223ChangeLog.html"
694 target="_top">JSR 223</a> supported language, once per file to map.</p>
695 <p>The script can be declared inline or in a specified file.</p>
696 <p>See the <a href="../Tasks/script.html">Script</a> task for an explanation of scripts and
697 dependencies.</p>
698
699 <table class="attr">
700 <tr>
701 <th scope="col">Attribute</th>
702 <th scope="col">Description</th>
703 <th scope="col">Required</th>
704 </tr>
705 <tr>
706 <td>language</td>
707 <td>Scripting language</td>
708 <td>Yes</td>
709 </tr>
710 <tr>
711 <td>manager</td>
712 <td>The script engine manager to use. See the <a href="../Tasks/script.html">script</a> task
713 for using this attribute.</td>
714 <td>No; default is <q>auto</q></td>
715 </tr>
716 <tr>
717 <td>src</td>
718 <td>File containing the script</td>
719 <td>No</td>
720 </tr>
721 <tr>
722 <td>encoding</td>
723 <td>The encoding of the script as a file. <em>Since Ant 1.10.2</em></td>
724 <td>No; defaults to default JVM character encoding</td>
725 </tr>
726 <tr>
727 <td>setbeans</td>
728 <td>whether to have all properties, references and targets as global variables in the
729 script. <em>Since Ant 1.8.0</em></td>
730 <td>No; default is <q>true</q></td>
731 </tr>
732 <tr>
733 <td>classpath</td>
734 <td>The classpath to pass into the script.</td>
735 <td>No</td>
736 </tr>
737 <tr>
738 <td>classpathref</td>
739 <td>The classpath to use, given as a <a href="../using.html#references">reference</a> to a
740 path defined elsewhere.
741 <td>No</td>
742 </tr>
743 </table>
744 <p>This filename mapper can take a nested <code>&lt;classpath&gt;</code> element. See
745 the <a href="../Tasks/script.html">script</a> task on how to use this element.</p>
746
747 <h5>Example</h5>
748 <pre>
749 &lt;scriptmapper language="javascript"&gt;
750 self.addMappedName(source.toUpperCase());
751 self.addMappedName(source.toLowerCase());
752 &lt;/scriptmapper&gt;</pre>
753
754 <table>
755 <tr>
756 <th scope="col">Source file name</th>
757 <th scope="col">Target file names</th>
758 </tr>
759 <tr>
760 <td rowspan="2"><code>foo\bar\A.java</code></td>
761 <td><code>FOO\BAR\A.JAVA</code></td>
762 </tr>
763 <tr>
764 <td><code>foo\bar\a.java</code></td>
765 </tr>
766 </table>
767
768 <p>To use this mapper, the scripts need access to the source file, and the ability to return
769 multiple mappings. Here are the relevant beans and their methods. The script is called once for
770 every source file, with the list of mapped names reset after every invocation.</p>
771
772 <table>
773 <tr>
774 <th scope="col">Script bean</th>
775 <th scope="col">Description</th>
776 </tr>
777 <tr>
778 <td><code>source: String</code></td>
779 <td>The file/path to map</td>
780 </tr>
781 <tr>
782 <td><code>self</code></td>
783 <td>The scriptmapper itself</td>
784 </tr>
785 <tr>
786 <td><code>self.addMappedName(String name)</code></td>
787 <td>Add a new mapping</td>
788 </tr>
789 <tr>
790 <td><code>self.clear()</code></td>
791 <td>Reset the list of files</td>
792 </tr>
793 </table>
794
795 <p>The scriptmapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var> attribute.</p>
796
797 <h4 id="firstmatch-mapper">firstmatchmapper</h4>
798 <p><em>Since Ant 1.8.0</em></p>
799 <p>This mapper supports an arbitrary number of nested mappers and returns the results of the first
800 mapper that matches. This is different from <a href="#composite-mapper">composite mapper</a> which
801 collects the results of all matching children.</p>
802 <h5>Examples</h5>
803 <pre>
804 &lt;firstmatchmapper&gt;
805 &lt;globmapper from="*.txt" to="*.bak"/&gt;
806 &lt;globmapper from="*A.*" to="*B.*"/&gt;
807 &lt;/firstmatchmapper&gt;</pre>
808
809 <table>
810 <tr>
811 <th scope="col">Source file name</th>
812 <th scope="col">Target file names</th>
813 </tr>
814 <tr>
815 <td><code>foo/bar/A.txt</code></td>
816 <td><code>foo/bar/A.bak</code></td>
817 </tr>
818 <tr>
819 <td><code>foo/bar/A.java</code></td>
820 <td><code>foo/bar/B.java</code></td>
821 </tr>
822 </table>
823
824 <p>The firstmatchmapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var>
825 attribute.</p>
826
827 <h4 id="cutdirs-mapper">cutdirsmapper</h4>
828 <p><em>Since Ant 1.8.2</em></p>
829 <p>This mapper strips a configured number of leading directories from the source file name.</p>
830
831 <h5>Examples</h5>
832 <pre>&lt;cutdirsmapper dirs="1"/&gt;</pre>
833
834 <table>
835 <tr>
836 <th scope="col">Source file name</th>
837 <th scope="col">Target file names</th>
838 </tr>
839 <tr>
840 <td><code>foo/bar/A.txt</code></td>
841 <td><code>bar/A.txt</code></td>
842 </tr>
843 </table>
844
845 <p>The cutdirsmapper has no corresponding <code>&lt;mapper&gt;</code> <var>type</var> attribute.</p>
846
847 <table class="attr">
848 <tr>
849 <th scope="col">Attribute</th>
850 <th scope="col">Description</th>
851 <th scope="col">Required</th>
852 </tr>
853 <tr>
854 <td>dirs</td>
855 <td>Number of directories to strip (must be a positive number).</td>
856 <td>Yes</td>
857 </tr>
858 </table>
859
860 </body>
861 </html>