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 33 kB

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