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