source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/replace.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

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