source: release-kits/lirk3/bin/ant-installer/web/manual/manual/CoreTasks/tar.html@ 14982

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

initial import of LiRK3

File size: 10.3 KB
Line 
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>Tar Task</title>
23</head>
24
25<body>
26
27<h2><a name="tar">Tar</a></h2>
28<h3>Description</h3>
29<p>Creates a tar archive.</p>
30<p>The <i>basedir</i> attribute is the reference directory from where to tar.</p>
31<p>This task is a <a href="../dirtasks.html#directorybasedtasks">directory based task</a>
32and, as such, forms an implicit <a href="../CoreTypes/fileset.html">Fileset</a>. This
33defines which files, relative to the <i>basedir</i>, will be included in the
34archive. The tar task supports all the attributes of Fileset to refine the
35set of files to be included in the implicit fileset.</p>
36
37<p>In addition to the implicit fileset, the tar task supports nested
38 resource collections and a special form of filesets. These
39filesets are extended to allow control over the access mode, username and groupname
40to be applied to the tar entries. This is useful, for example, when preparing archives for
41Unix systems where some files need to have execute permission.</p>
42
43<p>Early versions of tar did not support path lengths greater than 100
44characters. Modern versions of tar do so, but in incompatible ways.
45The behaviour of the tar task when it encounters such paths is
46controlled by the <i>longfile</i> attribute.
47If the longfile attribute is set to <code>fail</code>, any long paths will
48cause the tar task to fail. If the longfile attribute is set to
49<code>truncate</code>, any long paths will be truncated to the 100 character
50maximum length prior to adding to the archive. If the value of the longfile
51attribute is set to <code>omit</code> then files containing long paths will be
52omitted from the archive. Either option ensures that the archive can be
53untarred by any compliant version of tar. If the loss of path or file
54information is not acceptable, and it rarely is, longfile may be set to the
55value <code>gnu</code>. The tar task will then produce a GNU tar file which
56can have arbitrary length paths. Note however, that the resulting archive will
57only be able to be untarred with GNU tar. The default for the longfile
58attribute is <code>warn</code> which behaves just like the gnu option except
59that it produces a warning for each file path encountered that does not match
60the limit.</p>
61
62<p>This task can perform compression by setting the compression attribute to "gzip"
63or "bzip2".</p>
64
65<h3>Parameters</h3>
66<table border="1" cellpadding="2" cellspacing="0">
67 <tr>
68 <td valign="top"><b>Attribute</b></td>
69 <td valign="top"><b>Description</b></td>
70 <td valign="top" align="center"><b>Required</b></td>
71 </tr>
72 <tr>
73 <td valign="top">destfile</td>
74 <td valign="top">the tar-file to create.</td>
75 <td align="center" valign="top">Yes</td>
76 </tr>
77 <tr>
78 <td valign="top">basedir</td>
79 <td valign="top">the directory from which to tar the files.</td>
80 <td align="center" valign="top">No</td>
81 </tr>
82 <tr>
83 <td valign="top">longfile</td>
84 <td valign="top">Determines how long files (&gt;100 chars) are to be
85 handled. Allowable values are &quot;truncate&quot;, &quot;fail&quot;,
86 &quot;warn&quot;, &quot;omit&quot; and &quot;gnu&quot;. Default is
87 &quot;warn&quot;.</td>
88 <td valign="top" align="center">No</td>
89 </tr>
90 <tr>
91 <td valign="top">includes</td>
92 <td valign="top">comma- or space-separated list of patterns of files that must be
93 included. All files are included when omitted.</td>
94 <td valign="top" align="center">No</td>
95 </tr>
96 <tr>
97 <td valign="top">includesfile</td>
98 <td valign="top">the name of a file. Each line of this file is
99 taken to be an include pattern</td>
100 <td valign="top" align="center">No</td>
101 </tr>
102 <tr>
103 <td valign="top">excludes</td>
104 <td valign="top">comma- or space-separated list of patterns of files that must be
105 excluded. No files (except default excludes) are excluded when omitted.</td>
106 <td valign="top" align="center">No</td>
107 </tr>
108 <tr>
109 <td valign="top">excludesfile</td>
110 <td valign="top">the name of a file. Each line of this file is
111 taken to be an exclude pattern</td>
112 <td valign="top" align="center">No</td>
113 </tr>
114 <tr>
115 <td valign="top">defaultexcludes</td>
116 <td valign="top">indicates whether default excludes should be used or not
117 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
118 <td valign="top" align="center">No</td>
119 </tr>
120 <tr>
121 <td valign="top">compression</td>
122 <td valign="top">compression method. Allowable values are
123 &quot;none&quot;, &quot;gzip&quot; and &quot;bzip2&quot;. Default is
124 &quot;none&quot;.</td>
125 <td valign="top" align="center">No</td>
126 </tr>
127</table>
128
129<h3>Nested Elements</h3>
130
131The tar task supports nested <a
132href="../CoreTypes/tarfileset.html">tarfileset</a> elements. These are
133extended <a href="../CoreTypes/fileset.html">FileSets</a> which,
134in addition to the standard elements, support one additional
135attributes
136
137<table border="1" cellpadding="2" cellspacing="0">
138 <tr>
139 <td valign="top"><b>Attribute</b></td>
140 <td valign="top"><b>Description</b></td>
141 <td valign="top" align="center"><b>Required</b></td>
142 </tr>
143 <tr>
144 <td valign="top">preserveLeadingSlashes</td>
145 <td valign="top">Indicates whether leading `/'s should
146 be preserved in the file names. Default is <code>false</code>.</td>
147 <td align="center" valign="top">No</td>
148 </tr>
149</table>
150
151<h4>any other resource collection</h4>
152<p><a href="../CoreTypes/resources.html#collection">Resource
153Collection</a>s are used to select groups of files to archive.</p>
154<p>Prior to Ant 1.7 only <code>&lt;fileset&gt;</code> has been
155supported as a nested element.</p>
156
157<h3>Examples</h3>
158<pre>
159&lt;tar tarfile=&quot;${dist}/manual.tar&quot; basedir=&quot;htdocs/manual&quot;/&gt;
160&lt;gzip zipfile=&quot;${dist}/manual.tar.gz&quot; src=&quot;${dist}/manual.tar&quot;/&gt;</pre>
161<p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
162in the <code>${dist}</code> directory, then applies the gzip task to compress
163it.</p>
164<pre>
165&lt;tar destfile=&quot;${dist}/manual.tar&quot;
166 basedir=&quot;htdocs/manual&quot;
167 excludes=&quot;mydocs/**, **/todo.html&quot;
168/&gt;</pre>
169<p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
170in the <code>${dist}</code> directory. Files in the directory <code>mydocs</code>,
171or files with the name <code>todo.html</code> are excluded.</p>
172
173<pre>
174&lt;tar destfile=&quot;${basedir}/docs.tar&quot;&gt;
175 &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
176 fullpath=&quot;/usr/doc/ant/README&quot;
177 preserveLeadingSlashes=&quot;true&quot;&gt;
178 &lt;include name=&quot;readme.txt&quot;/&gt;
179 &lt;/tarfileset&gt;
180 &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
181 prefix=&quot;/usr/doc/ant&quot;
182 preserveLeadingSlashes=&quot;true&quot;&gt;
183 &lt;include name=&quot;*.html&quot;/&gt;
184 &lt;/tarfileset&gt;
185&lt;/tar&gt;</pre>
186
187<p>
188 Writes the file <code>docs/readme.txt</code> as
189 <code>/usr/doc/ant/README</code> into the archive. All
190 <code>*.html</code> files in the <code>docs</code> directory are
191 prefixed by <code>/usr/doc/ant</code>, so for example
192 <code>docs/index.html</code> is written as
193 <code>/usr/doc/ant/index.html</code> to the archive.
194</p>
195
196
197<pre>
198&lt;tar longfile=&quot;gnu&quot;
199 destfile=&quot;${dist.base}/${dist.name}-src.tar&quot; &gt;
200 &lt;tarfileset dir=&quot;${dist.name}/..&quot; mode=&quot;755&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
201 &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
202 &lt;include name=&quot;${dist.name}/build.sh&quot;/&gt;
203 &lt;/tarfileset&gt;
204 &lt;tarfileset dir=&quot;${dist.name}/..&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
205 &lt;include name=&quot;${dist.name}/**&quot;/&gt;
206 &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
207 &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
208 &lt;/tarfileset&gt;
209&lt;/tar&gt;
210</pre>
211
212<p>This example shows building a tar which uses the GNU extensions for long paths and
213where some files need to be marked as executable (mode 755)
214and the rest are use the default mode (read-write by owner). The first
215fileset selects just the executable files. The second fileset must exclude
216the executable files and include all others. </p>
217
218
219
220<p><strong>Note: </strong> The tar task does not ensure that a file is only selected
221by one resource collection. If the same file is selected by more than one collection, it will be included in the
222tar file twice, with the same path.</p>
223
224<p><strong>Note:</strong> The patterns in the include and exclude
225elements are considered to be relative to the corresponding dir
226attribute as with all other filesets. In the example above,
227<code>${dist.name}</code> is not an absolute path, but a simple name
228of a directory, so <code>${dist.name}</code> is a valid path relative
229to <code>${dist.name}/..</code>.</p>
230
231<pre>
232&lt;tar dest="release.tar.gz" compress="gzip"&gt;
233 &lt;zipfileset src="release.zip"/&gt;
234&lt;/tar&gt;
235</pre>
236
237<p>Re-packages a ZIP archive as a GZip compressed tar archive. If
238Unix file permissions have been stored as part of the ZIP file, they
239will be retained in the resulting tar archive.</p>
240
241 <p><strong>Note:</strong>
242 Please note the tar task creates a tar file, it does not append
243 to an existing tar file. The existing tar file is replaced instead.
244 As with most tasks in Ant, the task only takes action if the output
245 file (the tar file in this case) is older than the input files, or
246 if the output file does not exist.
247 </p>
248
249</body>
250</html>
251
Note: See TracBrowser for help on using the repository browser.