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