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 KiB

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