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>
|
---|
32 | and, as such, forms an implicit <a href="../CoreTypes/fileset.html">Fileset</a>. This
|
---|
33 | defines which files, relative to the <i>basedir</i>, will be included in the
|
---|
34 | archive. The tar task supports all the attributes of Fileset to refine the
|
---|
35 | set 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
|
---|
39 | filesets are extended to allow control over the access mode, username and groupname
|
---|
40 | to be applied to the tar entries. This is useful, for example, when preparing archives for
|
---|
41 | Unix 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
|
---|
44 | characters. Modern versions of tar do so, but in incompatible ways.
|
---|
45 | The behaviour of the tar task when it encounters such paths is
|
---|
46 | controlled by the <i>longfile</i> attribute.
|
---|
47 | If the longfile attribute is set to <code>fail</code>, any long paths will
|
---|
48 | cause 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
|
---|
50 | maximum length prior to adding to the archive. If the value of the longfile
|
---|
51 | attribute is set to <code>omit</code> then files containing long paths will be
|
---|
52 | omitted from the archive. Either option ensures that the archive can be
|
---|
53 | untarred by any compliant version of tar. If the loss of path or file
|
---|
54 | information is not acceptable, and it rarely is, longfile may be set to the
|
---|
55 | value <code>gnu</code>. The tar task will then produce a GNU tar file which
|
---|
56 | can have arbitrary length paths. Note however, that the resulting archive will
|
---|
57 | only be able to be untarred with GNU tar. The default for the longfile
|
---|
58 | attribute is <code>warn</code> which behaves just like the gnu option except
|
---|
59 | that it produces a warning for each file path encountered that does not match
|
---|
60 | the limit.</p>
|
---|
61 |
|
---|
62 | <p>This task can perform compression by setting the compression attribute to "gzip"
|
---|
63 | or "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 (>100 chars) are to be
|
---|
85 | handled. Allowable values are "truncate", "fail",
|
---|
86 | "warn", "omit" and "gnu". Default is
|
---|
87 | "warn".</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 | ("yes"/"no"). 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 | "none", "gzip" and "bzip2". Default is
|
---|
124 | "none".</td>
|
---|
125 | <td valign="top" align="center">No</td>
|
---|
126 | </tr>
|
---|
127 | </table>
|
---|
128 |
|
---|
129 | <h3>Nested Elements</h3>
|
---|
130 |
|
---|
131 | The tar task supports nested <a
|
---|
132 | href="../CoreTypes/tarfileset.html">tarfileset</a> elements. These are
|
---|
133 | extended <a href="../CoreTypes/fileset.html">FileSets</a> which,
|
---|
134 | in addition to the standard elements, support one additional
|
---|
135 | attributes
|
---|
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
|
---|
153 | Collection</a>s are used to select groups of files to archive.</p>
|
---|
154 | <p>Prior to Ant 1.7 only <code><fileset></code> has been
|
---|
155 | supported as a nested element.</p>
|
---|
156 |
|
---|
157 | <h3>Examples</h3>
|
---|
158 | <pre>
|
---|
159 | <tar tarfile="${dist}/manual.tar" basedir="htdocs/manual"/>
|
---|
160 | <gzip zipfile="${dist}/manual.tar.gz" src="${dist}/manual.tar"/></pre>
|
---|
161 | <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
|
---|
162 | in the <code>${dist}</code> directory, then applies the gzip task to compress
|
---|
163 | it.</p>
|
---|
164 | <pre>
|
---|
165 | <tar destfile="${dist}/manual.tar"
|
---|
166 | basedir="htdocs/manual"
|
---|
167 | excludes="mydocs/**, **/todo.html"
|
---|
168 | /></pre>
|
---|
169 | <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
|
---|
170 | in the <code>${dist}</code> directory. Files in the directory <code>mydocs</code>,
|
---|
171 | or files with the name <code>todo.html</code> are excluded.</p>
|
---|
172 |
|
---|
173 | <pre>
|
---|
174 | <tar destfile="${basedir}/docs.tar">
|
---|
175 | <tarfileset dir="${dir.src}/docs"
|
---|
176 | fullpath="/usr/doc/ant/README"
|
---|
177 | preserveLeadingSlashes="true">
|
---|
178 | <include name="readme.txt"/>
|
---|
179 | </tarfileset>
|
---|
180 | <tarfileset dir="${dir.src}/docs"
|
---|
181 | prefix="/usr/doc/ant"
|
---|
182 | preserveLeadingSlashes="true">
|
---|
183 | <include name="*.html"/>
|
---|
184 | </tarfileset>
|
---|
185 | </tar></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 | <tar longfile="gnu"
|
---|
199 | destfile="${dist.base}/${dist.name}-src.tar" >
|
---|
200 | <tarfileset dir="${dist.name}/.." mode="755" username="ant" group="ant">
|
---|
201 | <include name="${dist.name}/bootstrap.sh"/>
|
---|
202 | <include name="${dist.name}/build.sh"/>
|
---|
203 | </tarfileset>
|
---|
204 | <tarfileset dir="${dist.name}/.." username="ant" group="ant">
|
---|
205 | <include name="${dist.name}/**"/>
|
---|
206 | <exclude name="${dist.name}/bootstrap.sh"/>
|
---|
207 | <exclude name="${dist.name}/build.sh"/>
|
---|
208 | </tarfileset>
|
---|
209 | </tar>
|
---|
210 | </pre>
|
---|
211 |
|
---|
212 | <p>This example shows building a tar which uses the GNU extensions for long paths and
|
---|
213 | where some files need to be marked as executable (mode 755)
|
---|
214 | and the rest are use the default mode (read-write by owner). The first
|
---|
215 | fileset selects just the executable files. The second fileset must exclude
|
---|
216 | the 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
|
---|
221 | by one resource collection. If the same file is selected by more than one collection, it will be included in the
|
---|
222 | tar file twice, with the same path.</p>
|
---|
223 |
|
---|
224 | <p><strong>Note:</strong> The patterns in the include and exclude
|
---|
225 | elements are considered to be relative to the corresponding dir
|
---|
226 | attribute as with all other filesets. In the example above,
|
---|
227 | <code>${dist.name}</code> is not an absolute path, but a simple name
|
---|
228 | of a directory, so <code>${dist.name}</code> is a valid path relative
|
---|
229 | to <code>${dist.name}/..</code>.</p>
|
---|
230 |
|
---|
231 | <pre>
|
---|
232 | <tar dest="release.tar.gz" compress="gzip">
|
---|
233 | <zipfileset src="release.zip"/>
|
---|
234 | </tar>
|
---|
235 | </pre>
|
---|
236 |
|
---|
237 | <p>Re-packages a ZIP archive as a GZip compressed tar archive. If
|
---|
238 | Unix file permissions have been stored as part of the ZIP file, they
|
---|
239 | will 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 |
|
---|