You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mapper.html 29 kB

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