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.

replace.html 7.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Replace Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="replace">Replace</a></h2>
  8. <h3>Description</h3>
  9. <p>Replace is a directory based task for replacing the occurrence of a given string with another string
  10. in selected file.</p>
  11. <p>If you want to replace a text that crosses line boundaries, you
  12. must use a nested <code>&lt;replacetoken&gt;</code> element.</p>
  13. <p>The output file is only written if it differs from the existing
  14. file. This prevents spurious rebuilds based on unchanged files which
  15. have been regenerated by this task.</p>
  16. <h3>Parameters</h3>
  17. <table border="1" cellpadding="2" cellspacing="0">
  18. <tr>
  19. <td valign="top"><b>Attribute</b></td>
  20. <td valign="top"><b>Description</b></td>
  21. <td align="center" valign="top"><b>Required</b></td>
  22. </tr>
  23. <tr>
  24. <td valign="top">file</td>
  25. <td valign="top">file for which the token should be replaced.</td>
  26. <td align="center" rowspan="2">Exactly one of the two.</td>
  27. </tr>
  28. <tr>
  29. <td valign="top">dir</td>
  30. <td valign="top">The base directory to use when replacing a token in
  31. multiple files.</td>
  32. </tr>
  33. <tr>
  34. <td valign="top">encoding</td>
  35. <td valign="top">The encoding of the files upon which replace operates.</td>
  36. <td align="center">No - defaults to default JVM encoding</td>
  37. </tr>
  38. <tr>
  39. <td valign="top">token</td>
  40. <td valign="top">the token which must be replaced.</td>
  41. <td valign="top" align="center">Yes, unless a nested
  42. <code>replacetoken</code> element or the replacefilterfile
  43. attribute is used.</td>
  44. </tr>
  45. <tr>
  46. <td valign="top">value</td>
  47. <td valign="top">the new value for the token. When omitted, an empty string
  48. (&quot;&quot;) is used.</td>
  49. <td valign="top" align="center">No</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">summary</td>
  53. <td valign="top">Indicates whether a summary of the replace operation
  54. should be produced, detailing how many token occurrences
  55. and files were processed
  56. </td>
  57. <td valign="top" align="center">No, by default no summary is produced</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">propertyFile</td>
  61. <td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td>
  62. <td valign="top" align="center">Yes only if <i>property</i> attribute of <code>&lt;replacefilter&gt;</code> is used.</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">replacefilterfile</td>
  66. <td valign="top">valid property file. Each property will be
  67. treated as a replacefilter where <code>token</code> is the name of
  68. the property and <code>value</code> is the properties value.
  69. <td valign="top" align="center">No.</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">includes</td>
  73. <td valign="top">comma- or space-separated list of patterns of files that must be
  74. included. All files are included when omitted.</td>
  75. <td valign="top" align="center">No</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">includesfile</td>
  79. <td valign="top">the name of a file. Each line of this file is
  80. taken to be an include pattern</td>
  81. <td valign="top" align="center">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">excludes</td>
  85. <td valign="top">comma- or space-separated list of patterns of files that must be
  86. excluded. No files (except default excludes) are excluded when omitted.</td>
  87. <td valign="top" align="center">No</td>
  88. </tr>
  89. <tr>
  90. <td valign="top">excludesfile</td>
  91. <td valign="top">the name of a file. Each line of this file is
  92. taken to be an exclude pattern</td>
  93. <td valign="top" align="center">No</td>
  94. </tr>
  95. <tr>
  96. <td valign="top">defaultexcludes</td>
  97. <td valign="top">indicates whether default excludes should be used or not
  98. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  99. <td valign="top" align="center">No</td>
  100. </tr>
  101. </table>
  102. <h3>Examples</h3>
  103. <pre> &lt;replace file=&quot;${src}/index.html&quot; token=&quot;@@@&quot; value=&quot;wombat&quot;/&gt;</pre>
  104. <p>replaces occurrences of the string &quot;@@@&quot; with the string
  105. &quot;wombat&quot;, in the file <code>${src}/index.html</code>.</p>
  106. <h3>Parameters specified as nested elements</h3>
  107. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  108. supports all attributes of <code>&lt;fileset&gt;</code> as well as the
  109. nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  110. <code>&lt;patternset&gt;</code> elements.</p>
  111. <p>If either the text you want to replace or the replacement text
  112. cross line boundaries, you can use nested elements to specify
  113. them.</p>
  114. <h3>Examples</h3>
  115. <blockquote><pre>
  116. &lt;replace dir=&quot;${src}&quot; value=&quot;wombat&quot;&gt;
  117. &lt;include name=&quot;**/*.html&quot;/&gt;
  118. &lt;replacetoken&gt;&lt;![CDATA[multi line
  119. token]]&gt;&lt;/replacetoken&gt;
  120. &lt;/replace&gt;
  121. </pre></blockquote>
  122. <p>replaces occurrences of the string &quot;multi
  123. line<i>\n</i>token&quot; with the string &quot;wombat&quot;, in all
  124. HTML files in the directory <code>${src}</code>.Where <i>\n</i> is
  125. the platform specific line separator.</p>
  126. <blockquote><pre>
  127. &lt;replace file=&quot;${src}/index.html&quot;&gt;
  128. &lt;replacetoken&gt;&lt;![CDATA[two line
  129. token]]&gt;&lt;/replacetoken&gt;
  130. &lt;replacevalue&gt;&lt;![CDATA[two line
  131. token]]&gt;&lt;/replacevalue&gt;
  132. &lt;/replace&gt;
  133. </pre></blockquote>
  134. <h4>replacefilter</h4>
  135. <p>In addition to allowing for multiple replacements, optional nested <code>&lt;replacefilter&gt;</code> elements allow replacement values to be extracted from a property file. The name of this file is specified using the <code>&lt;replace&gt;</code> attribute <i>propertyFile</i>.
  136. </p>
  137. <table border="1" cellpadding="2" cellspacing="0">
  138. <tr>
  139. <td valign="top"><b>Attribute</b></td>
  140. <td valign="top"><b>Description</b></td>
  141. <td align="center" valign="top"><b>Required</b></td>
  142. </tr>
  143. <tr>
  144. <td valign="top">token</td>
  145. <td valign="top">The string to search for.</td>
  146. <td align="center" valign="top">Yes</td>
  147. </tr>
  148. <tr>
  149. <td valign="top">value</td>
  150. <td valign="top">The replacement string.</td>
  151. <td align="center" rowspan="2">Either may be specified, but not both. Both can be omitted, if desired.</td>
  152. </tr>
  153. <tr>
  154. <td valign="top">property</td>
  155. <td valign="top">Name of the property whose value is to serve as the replacement value.</td>
  156. </tr>
  157. </table>
  158. <p>If neither <i>value</i> nor <i>property</i> is used, the value provided using the <code>&lt;replace&gt;</code> attribute <i>value</i> and/or the <code>&lt;replacevalue&gt;</code> element is used. If no value was specified using either of these options, the token is replaced with an empty string.
  159. </p>
  160. <h3>Examples</h3>
  161. <blockquote><pre>
  162. &lt;replace
  163. file=&quot;configure.sh&quot;
  164. value=&quot;defaultvalue&quot;
  165. propertyFile=&quot;source/name.properties&quot;&gt;
  166. &lt;replacefilter
  167. token=&quot;@token1@&quot;/&gt;
  168. &lt;replacefilter
  169. token=&quot;@token2@&quot;
  170. value=&quot;value2&quot;/&gt;
  171. &lt;replacefilter
  172. token=&quot;@token3@&quot;
  173. property=&quot;property.key&quot;/&gt;
  174. &lt;/replace&gt;
  175. </pre></blockquote>
  176. <p>In file <code>configure.sh</code>, replace all instances of &quot;@token1@&quot; with &quot;defaultvalue&quot;, all instances of &quot;@token2@&quot; with &quot;value2&quot;, and all instances of &quot;@token3@&quot; with the value of the property &quot;property.key&quot;, as it appears in property file <code>src/name.properties</code>.</p>
  177. <p><b>Note:</b> It is possible to use either the <i>token</i>/<code>&lt;replacetoken&gt;</code> and <i>value</i>/<code>&lt;replacevalue&gt;</code> attributes/elements, the nested replacefilter elements, or both in the same operation.
  178. </p>
  179. <hr>
  180. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  181. Reserved.</p>
  182. </body>
  183. </html>