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.

pathconvert.html 7.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="foreach">Pathconvert</a></h2>
  8. <h3>Description</h3>
  9. <p>Converts a nested path, path reference, or fileset reference to the form usable on a
  10. specified platform
  11. and stores the result in a given property. This operation is useful when script files
  12. (batch files or shell scripts) must be generated my the build system and they contain
  13. path information that must be properly formatted for the target architecture, not the
  14. architecture on which the build is running, or when you need to create a list of files
  15. separated by a given character, like a comma or a space.
  16. </p>
  17. <p>Prefix maps can be specified to map Windows drive letters to Unix paths and vice
  18. versa.</p>
  19. <h3>Parameters</h3>
  20. <table border="1" cellpadding="2" cellspacing="0">
  21. <tr>
  22. <td valign="top"><b>Attribute</b></td>
  23. <td valign="top"><b>Description</b></td>
  24. <td align="center" valign="top"><b>Required</b></td>
  25. </tr>
  26. <tr>
  27. <td valign="top">targetos</td>
  28. <td valign="top">
  29. The target architecture. Must be one of 'unix' or 'windows'. <BR>This is a
  30. shorthand mechanism for specifying both <tt>pathsep</tt> and <tt>dirsep</tt>
  31. according to the specified target architecture.
  32. </td>
  33. <td valign="top" align="center">
  34. Must specify one of <tt>targetos</tt>, <tt>pathsep</tt>,or <tt>dirsep</tt>.
  35. </td>
  36. </tr>
  37. <tr>
  38. <td valign="top">dirsep</td>
  39. <td valign="top">
  40. The character to use as the directory separator in the generated paths.
  41. </td>
  42. <td valign="top" align="center">No, defaults to current JVM <tt>File.separator</tt></td>
  43. </tr>
  44. <tr>
  45. <td valign="top">pathsep</td>
  46. <td valign="top">
  47. The character to use as the path element separator in the generated paths.
  48. </td>
  49. <td valign="top" align="center">No, defaults to current JVM <tt>File.pathSeparator</tt></td>
  50. </tr>
  51. <tr>
  52. <td valign="top">property</td>
  53. <td valign="top">The name of the property in which to place the converted path</td>
  54. <td valign="top" align="center">Yes</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">refid</td>
  58. <td valign="top">What to convert, given as a
  59. <a href="../using.html#references">reference</a> to a PATH or FILESET
  60. defined elsewhere</td>
  61. <td valign="top" align="center">No, if omitted a nested &lt;path> element must be supplied.</td>
  62. </tr>
  63. </table>
  64. <h3>Parameters specified as nested elements</h3>
  65. <h4>map</h4>
  66. <p>Specifies the mapping of path prefixes between Unix and Windows.</p>
  67. <table border="1" cellpadding="2" cellspacing="0">
  68. <tr>
  69. <td valign="top"><b>Attribute</b></td>
  70. <td valign="top"><b>Description</b></td>
  71. <td align="center" valign="top"><b>Required</b></td>
  72. </tr>
  73. <tr>
  74. <td valign="top">from</td>
  75. <td valign="top">The prefix to match. Note that this value is case insensitive when
  76. the build is running on a windows platform and case sensitive when running on a
  77. Unix platform.</td>
  78. <td valign="top" align="center">Yes</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">to</td>
  82. <td valign="top">The replacement text to use when <i>from</i> is matched.</td>
  83. <td valign="top" align="center">Yes</td>
  84. </tr>
  85. </table>
  86. <p>Each map element specifies a single replacement map to be applied to the elements of
  87. the path being processed. If no map entries are specified, then no path prefix mapping
  88. is performed.
  89. </p>
  90. <p><i>Note that the map elements are applied in the order specified and the only the first
  91. matching map element is applied. So, the ordering of your map elements can be important
  92. if any <TT>from</tt> values are prefixes of other <tt>from</tt> values.</i>
  93. </p>
  94. <h4>path</h4>
  95. <p>If a path reference is not supplied using the <i>refid</i> attribute, then a
  96. nested path element must be supplied. See
  97. <a href="../using.html#path">Path-like Structures</a> for details.</p>
  98. <h3>Examples</h3>
  99. <p>In the examples below, assume that the property <b>wl.home</b> has the value
  100. <tt>d:\weblogic</tt> on Windows and <tt>/weblogic</tt> on Unix.</p>
  101. <h4>Example 1</h4>
  102. <pre>
  103. &lt;path id="wl.path"&gt;
  104. &lt;pathelement location=&quot;${wl.home}/lib/weblogicaux.jar&quot; /&gt;
  105. &lt;pathelement location=&quot;${wl.home}/classes&quot; /&gt;
  106. &lt;pathelement location=&quot;${wl.home}/mssqlserver4/classes&quot; /&gt;
  107. &lt;pathelement location=&quot;c:\winnt\System32&quot; /&gt;
  108. &lt;/path&gt;
  109. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;newpath&quot; refid=&quot;wl.path&quot;/&gt;
  110. </pre>
  111. <p>Assuming wl.property has the value "d:\weblogic", will generate the path shown below
  112. and store it in the property named <tt>newpath</tt>
  113. </p>
  114. <pre>
  115. /weblogic/lib/weblogicaux.jar:/weblogic/classes:/weblogic/mssqlserver4/classes:/WINNT/SYSTEM32
  116. </pre>
  117. Note that the drive letters have been removed. This is the default behavior when no map
  118. elements have been specified.
  119. <h4>Example 2</h4>
  120. <pre>
  121. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;newpath&quot; &gt;
  122. &lt;path id="wl.path"&gt;
  123. &lt;pathelement location=&quot;${wl.home}/lib/weblogicaux.jar&quot; /&gt;
  124. &lt;pathelement location=&quot;${wl.home}/classes&quot; /&gt;
  125. &lt;pathelement location=&quot;${wl.home}/mssqlserver4/classes&quot; /&gt;
  126. &lt;pathelement location=&quot;c:\winnt\System32&quot; /&gt;
  127. &lt;/path&gt;
  128. &lt;/pathconvert&gt;
  129. </pre>
  130. This generates the exact same path as the previous example. It demonstrates the use of
  131. a nested path element.
  132. <h4>Example 3</h4>
  133. <pre>
  134. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;newpath&quot; refid=&quot;wl.path&quot;&gt;
  135. &lt;map from=&quot;d:&quot; to=&quot;/foo&quot;/&gt;
  136. &lt;map from=&quot;c:&quot; to=&quot;/bar&quot;/&gt;
  137. &lt;/pathconvert&gt;
  138. </pre>
  139. <p>This example specifies two map entries that will convert path elements that start with
  140. <tt>c:</tt> to <TT>/dos</tt> and <tt>d:</tt> to <TT>/</tt>. The resulting path is shown
  141. below.</p>
  142. <pre>
  143. /weblogic/lib/weblogicaux.jar:/weblogic/classes:/weblogic/mssqlserver4/classes:/dos/WINNT/SYSTEM32
  144. </pre>
  145. <h4>Example 4</h4>
  146. <pre>
  147. &lt;pathconvert targetos=&quot;windows&quot; property=&quot;newpath&quot; &gt;
  148. &lt;path id="wl.path"&gt;
  149. &lt;pathelement location=&quot;${wl.home}/lib/weblogicaux.jar&quot; /&gt;
  150. &lt;pathelement location=&quot;${wl.home}/classes&quot; /&gt;
  151. &lt;pathelement location=&quot;${wl.home}/mssqlserver4/classes&quot; /&gt;
  152. &lt;pathelement location=&quot;/dos/winnt/System32&quot; /&gt;
  153. &lt;/path&gt;
  154. &lt;map from=&quot;/dos&quot; to=&quot;c:\&quot;/&gt;
  155. &lt;map from=&quot;/&quot; to=&quot;d:\&quot;/&gt;
  156. &lt;/pathconvert&gt;
  157. </pre>
  158. <p>This example, similar to the one above but targetting windows, specifies two map
  159. entries that will convert path elements that start with
  160. <tt>/dos</tt> to <TT>c:\</tt> and <tt>/</tt> to <TT>d:\</tt>. Note that the order of the
  161. map elements was important here since <tt>/</tt> is a prefix of <tt>/dos</tt>.
  162. The resulting path is shown below.</p>
  163. <pre>
  164. d:\weblogic\lib\weblogicaux.jar;d:\weblogic\classes;d:\weblogic\mssqlserver4\classes;c:\WINNT\SYSTEM32
  165. </pre>
  166. <h4>Example 5</h4>
  167. <pre>
  168. &lt;fileset dir=&quot;${src.dir}&quot; id=&quot;src.files&quot;&gt;
  169. &lt;include name=&quot;**/*.java&quot;/&gt;
  170. &lt;/fileset&gt;
  171. &lt;pathconvert pathsep=&quot;,&quot; property=&quot;javafiles&quot; refid=&quot;src.files&quot;/&gt;
  172. </pre>
  173. <p>This example takes the set of files determined by the fileset (all files ending
  174. in <tt>.java</tt>), joins them together separated by commas, and places the resulting
  175. list into the property <tt>javafiles</tt>. The directory separator is not specified, so
  176. it defaults to the appropriate character for the current platform. Such a list could
  177. then be used in another task, like <tt>javadoc</tt>, that requires a comma separated
  178. list of files.
  179. </p>
  180. <hr>
  181. </body>
  182. </html>