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.1 KiB

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