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

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

initial import of LiRK3

File size: 8.9 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Copy Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="copy">Copy</a></h2>
12<h3>Description</h3>
13<p>Copies a file or FileSet to a new file or directory. By default, files are
14only copied if the source file is newer than the destination file,
15or when the destination file does not exist. However, you can explicitly
16overwrite files with the <code>overwrite</code> attribute.</p>
17
18<p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select a
19set of files to copy.
20To use a <code>&lt;fileset&gt;</code>, the <code>todir</code> attribute
21must be set.</p>
22
23<p>
24<strong>Note: </strong>If you employ filters in your copy operation, you should
25limit the copy to text files. Binary files will be corrupted by the copy operation.
26This applies whether the filters are implicitly defined by the
27<a href="filter.html">filter</a> task or explicitly provided to the copy
28operation as <a href="../CoreTypes/filterset.html">filtersets</a>
29</p>
30
31<h3>Parameters</h3>
32<table border="1" cellpadding="2" cellspacing="0">
33 <tr>
34 <td valign="top"><b>Attribute</b></td>
35 <td valign="top"><b>Description</b></td>
36 <td align="center" valign="top"><b>Required</b></td>
37 </tr>
38 <tr>
39 <td valign="top">file</td>
40 <td valign="top">The file to copy.</td>
41 <td valign="top" align="center">Yes, unless a nested
42 <code>&lt;fileset&gt;</code> element is used.</td>
43 </tr>
44 <tr>
45 <td valign="top">preservelastmodified</td>
46 <td valign="top">Give the copied files the same last modified
47 time as the original source files.</td>
48 <td valign="top" align="center">No; defaults to false.</td>
49 </tr>
50 <tr>
51 <td valign="top">tofile</td>
52 <td valign="top">The file to copy to.</td>
53 <td valign="top" align="center" rowspan="2">With the <code>file</code>
54 attribute, either <code>tofile</code> or <code>todir</code> can be used.
55 With nested <code>&lt;fileset&gt;</code> elements, if the set of files
56 is greater than 1, or if only the <code>dir</code> attribute is
57 specified in the <code>&lt;fileset&gt;</code>, or if the
58 <code>file</code> attribute is also specified, then only
59 <code>todir</code> is allowed.</td>
60 </tr>
61 <tr>
62 <td valign="top">todir</td>
63 <td valign="top">The directory to copy to.</td>
64 </tr>
65 <tr>
66 <td valign="top">overwrite</td>
67 <td valign="top">Overwrite existing files even if the destination
68 files are newer.</td>
69 <td valign="top" align="center">No; defaults to false.</td>
70 </tr>
71 <tr>
72 <td valign="top">filtering</td>
73 <td valign="top">Indicates whether token filtering using the global
74 build-file filters should take place during the copy.
75 <em>Note</em>: Nested <code>&lt;filterset&gt;</code> elements will
76 always be used, even if this attribute is not specified, or its value is
77 <code>false</code> (<code>no</code>, or <code>off</code>).</td>
78 <td valign="top" align="center">No; defaults to false.</td>
79 </tr>
80 <tr>
81 <td valign="top">flatten</td>
82 <td valign="top">Ignore the directory structure of the source files,
83 and copy all files into the directory specified by the <code>todir</code>
84 attribute. Note that you can achieve the same effect by using a
85 <a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a>.</td>
86 <td valign="top" align="center">No; defaults to false.</td>
87 </tr>
88 <tr>
89 <td valign="top">includeEmptyDirs</td>
90 <td valign="top">Copy any empty directories included in the FileSet(s).
91 </td>
92 <td valign="top" align="center">No; defaults to true.</td>
93 </tr>
94 <tr>
95 <td valign="top">failonerror</td>
96 <td valign="top">If false, log a warning message, but do not stop the
97 build, when the file to copy does not exist or one of the nested
98 filesets points to a directory that doesn't exist or an error occurs
99 while copying.
100 </td>
101 <td valign="top" align="center">No; defaults to true.</td>
102 </tr>
103 <tr>
104 <td valign="top">verbose</td>
105 <td valign="top">Log the files that are being copied.</td>
106 <td valign="top" align="center">No; defaults to false.</td>
107 </tr>
108 <tr>
109 <td valign="top">encoding</td>
110 <td valign="top">The encoding to assume when filter-copying the
111 files. <em>since Ant 1.5</em>.</td>
112 <td align="center">No - defaults to default JVM encoding</td>
113 </tr>
114 <tr>
115 <td valign="top">outputencoding</td>
116 <td valign="top">The encoding to use when writing the files.
117 <em>since Ant 1.6</em>.</td>
118 <td align="center">No - defaults to the value of the encoding
119 attribute if given or the default JVM encoding otherwise.</td>
120 </tr>
121 <tr>
122 <td valign="top">enablemultiplemappings</td>
123 <td valign="top">
124 If true the task will process to all the mappings for a
125 given source path. If false the task will only process
126 the first file or directory. This attribute is only relevant
127 if there is a mapper subelement.
128 <em>since Ant 1.6</em>.</td>
129 <td align="center">No - defaults to false.</td>
130 </tr>
131 <tr>
132 <td valign="top">granularity</td>
133 <td valign="top">The number of milliseconds leeway to give before
134 deciding a file is out of date. This is needed because not every
135 file system supports tracking the last modified time to the
136 millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
137 systems. This can also be useful if source and target files live
138 on separate machines with clocks being out of sync. <em>since Ant
139 1.6.2</em>.</td>
140 </tr>
141</table>
142<h3>Parameters specified as nested elements</h3>
143
144<h4>fileset</h4>
145 <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
146sets of files to copy.
147 To use a fileset, the <code>todir</code> attribute must be set.</p>
148
149<h4>mapper</h4>
150 <p>You can define filename transformations by using a nested <a
151 href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
152 <code>&lt;copy&gt;</code> is the <a
153 href="../CoreTypes/mapper.html#identity-mapper">identity mapper</a>.</p>
154 <p>
155 <em>Since Ant 1.6.3</em>,
156 one can use a filenamemapper type in place of the mapper element.
157 </p>
158
159<h4>filterset</h4>
160 <p><a href="../CoreTypes/filterset.html">FilterSet</a>s are used to replace
161tokens in files that are copied.
162 To use a FilterSet, use the nested <code>&lt;filterset&gt;</code> element.</p>
163
164<h4>filterchain</h4>
165<p>The Copy task supports nested <a href="../CoreTypes/filterchain.html">
166FilterChain</a>s.</p>
167
168<p>
169If <code>&lt;filterset&gt;</code> and <code>&lt;filterchain&gt;</code> elements are used inside the
170same <code>&lt;copy&gt;</code> task, all <code>&lt;filterchain&gt;</code> elements are processed first
171followed by <code>&lt;filterset&gt;</code> elements.
172</p>
173
174<h3>Examples</h3>
175<p><b>Copy a single file</b></p>
176<pre>
177 &lt;copy file=&quot;myfile.txt&quot; tofile=&quot;mycopy.txt&quot;/&gt;
178</pre>
179<p><b>Copy a single file to a directory</b></p>
180<pre>
181 &lt;copy file=&quot;myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
182</pre>
183<p><b>Copy a directory to another directory</b></p>
184<pre>
185 &lt;copy todir=&quot;../new/dir&quot;&gt;
186 &lt;fileset dir=&quot;src_dir&quot;/&gt;
187 &lt;/copy&gt;
188</pre>
189<p><b>Copy a set of files to a directory</b></p>
190<pre>
191 &lt;copy todir=&quot;../dest/dir&quot;&gt;
192 &lt;fileset dir=&quot;src_dir&quot;&gt;
193 &lt;exclude name=&quot;**/*.java&quot;/&gt;
194 &lt;/fileset&gt;
195 &lt;/copy&gt;
196
197 &lt;copy todir=&quot;../dest/dir&quot;&gt;
198 &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
199 &lt;/copy&gt;
200</pre>
201<p><b>Copy a set of files to a directory, appending
202<code>.bak</code> to the file name on the fly</b></p>
203<pre>
204 &lt;copy todir=&quot;../backup/dir&quot;&gt;
205 &lt;fileset dir=&quot;src_dir&quot;/&gt;
206 &lt;globmapper from=&quot;*&quot; to=&quot;*.bak&quot;/&gt;
207 &lt;/copy&gt;
208</pre>
209
210
211<p><b>Copy a set of files to a directory, replacing @TITLE@ with Foo Bar
212in all files.</b></p>
213<pre>
214 &lt;copy todir=&quot;../backup/dir&quot;&gt;
215 &lt;fileset dir=&quot;src_dir&quot;/&gt;
216 &lt;filterset&gt;
217 &lt;filter token=&quot;TITLE&quot; value=&quot;Foo Bar&quot;/&gt;
218 &lt;/filterset&gt;
219 &lt;/copy&gt;
220</pre>
221
222<p><strong>Unix Note:</strong> File permissions are not retained when files
223are copied; they end up with the default <code>UMASK</code> permissions
224instead. This
225is caused by the lack of any means to query or set file permissions in the
226current Java runtimes. If you need a permission-preserving copy function,
227use <code>&lt;exec executable="cp" ... &gt;</code> instead.
228</p>
229
230<p><strong>Windows Note:</strong> If you copy a file to a directory
231where that file already exists, but with different casing,
232the copied file takes on the case of the original. The workaround is to
233<a href="delete.html">delete</a>
234the file in the destination directory before you copy it.
235</p>
236
237<hr><p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation.
238All rights Reserved.</p>
239
240</body>
241</html>
242
Note: See TracBrowser for help on using the repository browser.