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

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