You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tar.html 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Tar Task</title>
  20. </head>
  21. <body>
  22. <h2 id="tar">Tar</h2>
  23. <h3>Description</h3>
  24. <p>Creates a tar archive.</p>
  25. <p>The <var>basedir</var> attribute is the reference directory from where to tar.</p>
  26. <p>This task is a <a href="../dirtasks.html#directorybasedtasks">directory based task</a> and, as
  27. such, forms an implicit <a href="../Types/fileset.html">Fileset</a>. This defines which files,
  28. relative to the <var>basedir</var>, will be included in the archive. The <code>tar</code> task
  29. supports all the attributes of Fileset to refine the set of files to be included in the implicit
  30. fileset.</p>
  31. <p>In addition to the implicit fileset, the <code>tar</code> task supports nested resource
  32. collections and a special form of filesets. These filesets are extended to allow control over the
  33. access mode, username and groupname to be applied to the tar entries. This is useful, for example,
  34. when preparing archives for Unix systems where some files need to have execute permission. By
  35. default this task will use Unix permissions of 644 for files and 755 for directories.</p>
  36. <p>Early versions of <code>tar</code> utility did not support paths longer than 100 characters. Over
  37. time several incompatible extensions have been developed until a new POSIX standard was created that
  38. added so called PAX extension headers (as the <code>pax</code> utility first introduced them) that
  39. among another things addressed file names longer than 100 characters. All modern implementations of
  40. tar support PAX extension headers.</p>
  41. <p>Ant's tar support predates the standard with PAX extension headers, it supports different
  42. dialects that can be enabled using the <var>longfile</var> attribute. If the <var>longfile</var>
  43. attribute is set to <q>fail</q>, any long paths will cause the tar task to fail. If
  44. the <var>longfile</var> attribute is set to <q>truncate</q>, any long paths will be truncated to the
  45. 100 character maximum length prior to adding to the archive. If the value of the <var>longfile</var>
  46. attribute is set to <q>omit</q> then files containing long paths will be omitted from the archive.
  47. Either option ensures that the archive can be untarred by any compliant version of tar.</p>
  48. <p>If the loss of path or file information is not acceptable, and it rarely is, <var>longfile</var>
  49. may be set to the value <q>gnu</q> or <q>posix</q>. With <q>posix</q> Ant will add PAX extension
  50. headers, with <q>gnu</q> it adds GNU tar specific extensions that newer versions of GNU tar
  51. call <q>oldgnu</q>. GNU tar still creates these extensions by default but supports PAX extension
  52. headers as well. Either choice will produce a tar file which can have arbitrary length paths. Note
  53. however, that the resulting archive will only be able to be untarred with tar tools that support the
  54. chosen format.</p>
  55. <p>The default for the <var>longfile</var> attribute is <q>warn</q> which behaves just like
  56. the <q>gnu</q> option except that it produces a warning for each filepath encountered that does not
  57. match the limit. It uses <q>gnu</q> rather than <q>posix</q> for backwards compatibility
  58. reasons.</p>
  59. <p>To achieve best interoperability you should use either <q>fail</q> or <q>posix</q> for
  60. the <var>longfile</var> attribute.</p>
  61. <p>This task can perform compression by setting the <var>compression</var> attribute
  62. to <q>gzip</q>, <q>bzip2</q>, or <q>xz</q>.</p>
  63. <h3>Parameters</h3>
  64. <table class="attr">
  65. <tr>
  66. <th>Attribute</th>
  67. <th>Description</th>
  68. <th>Required</th>
  69. </tr>
  70. <tr>
  71. <td>destfile</td>
  72. <td>the tar file to create.</td>
  73. <td>Yes</td>
  74. </tr>
  75. <tr>
  76. <td>basedir</td>
  77. <td>the directory from which to tar the files.</td>
  78. <td>No</td>
  79. </tr>
  80. <tr>
  81. <td>longfile</td>
  82. <td>Determines how long filenames (&gt; 100 chars) are to be handled. Allowed values
  83. are <q>truncate</q>, <q>fail</q>, <q>warn</q>, <q>omit</q>, <q>gnu</q> and <q>posix</q>.</td>
  84. <td>No; default is <q>warn</q></td>
  85. </tr>
  86. <tr>
  87. <td>includes</td>
  88. <td>comma- or space-separated list of patterns of files that must be included.</td>
  89. <td>No; defaults to all (<q>**</q>)</td>
  90. </tr>
  91. <tr>
  92. <td>includesfile</td>
  93. <td>name of a file. Each line of this file is taken to be an include pattern</td>
  94. <td>No</td>
  95. </tr>
  96. <tr>
  97. <td>excludes</td>
  98. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  99. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  100. </tr>
  101. <tr>
  102. <td>excludesfile</td>
  103. <td>name of a file. Each line of this file is taken to be an exclude pattern</td>
  104. <td>No</td>
  105. </tr>
  106. <tr>
  107. <td>defaultexcludes</td>
  108. <td>indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  109. <td>No; defaults to <q>yes</q></td>
  110. </tr>
  111. <tr>
  112. <td>compression</td>
  113. <td>compression method. Allowable values are <q>none</q>, <q>gzip</q>, <q>xz</q>
  114. and <q>bzip2</q>.</td>
  115. <td>No; default is <q>warn</q></td>
  116. </tr>
  117. <tr>
  118. <td>encoding</td>
  119. <td>The character encoding to use for filenames inside the tar file. For a list of possible
  120. values see
  121. the <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html">Supported
  122. Encodings</a>.<br/><em>Since Ant 1.9.5</em>
  123. <td>No; defaults to default JVM character encoding</td>
  124. </tr>
  125. </table>
  126. <h3>Nested Elements</h3>
  127. <p>The tar task supports nested <a href="../Types/tarfileset.html">tarfileset</a> elements. These
  128. are extended <a href="../Types/fileset.html">FileSets</a> which, in addition to the standard
  129. elements, support one additional attributes</p>
  130. <table class="attr">
  131. <tr>
  132. <th>Attribute</th>
  133. <th>Description</th>
  134. <th>Required</th>
  135. </tr>
  136. <tr>
  137. <td>preserveLeadingSlashes</td>
  138. <td>Indicates whether leading <q>/</q> should be preserved in the file names.</td>
  139. <td>No; default is <q>false</q></td>
  140. </tr>
  141. </table>
  142. <h4>any other resource collection</h4>
  143. <p><a href="../Types/resources.html#collection">Resource Collection</a>s are used to select groups
  144. of files to archive.</p>
  145. <p>Prior to Apache Ant 1.7 only <code>&lt;fileset&gt;</code> has been supported as a nested
  146. element.</p>
  147. <h3>Examples</h3>
  148. <pre>
  149. &lt;tar destfile=&quot;${dist}/manual.tar&quot; basedir=&quot;htdocs/manual&quot;/&gt;
  150. &lt;gzip destfile=&quot;${dist}/manual.tar.gz&quot; src=&quot;${dist}/manual.tar&quot;/&gt;</pre>
  151. <p>tars all files in the <samp>htdocs/manual</samp> directory into a file
  152. called <samp>manual.tar</samp> in the <samp>${dist}</samp> directory, then applies
  153. the <code>gzip</code> task to compress it.</p>
  154. <pre>
  155. &lt;tar destfile=&quot;${dist}/manual.tar&quot;
  156. basedir=&quot;htdocs/manual&quot;
  157. excludes=&quot;mydocs/**, **/todo.html&quot;/&gt;</pre>
  158. <p>tars all files in the <samp>htdocs/manual</samp> directory into a file
  159. called <samp>manual.tar</samp> in the <samp>${dist}</samp> directory. Files in the
  160. directory <samp>mydocs</samp>, or files with the name <samp>todo.html</samp> are excluded.</p>
  161. <pre>
  162. &lt;tar destfile=&quot;${basedir}/docs.tar&quot;&gt;
  163. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  164. fullpath=&quot;/usr/doc/ant/README&quot;
  165. preserveLeadingSlashes=&quot;true&quot;&gt;
  166. &lt;include name=&quot;readme.txt&quot;/&gt;
  167. &lt;/tarfileset&gt;
  168. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  169. prefix=&quot;/usr/doc/ant&quot;
  170. preserveLeadingSlashes=&quot;true&quot;&gt;
  171. &lt;include name=&quot;*.html&quot;/&gt;
  172. &lt;/tarfileset&gt;
  173. &lt;/tar&gt;</pre>
  174. <p>Writes the file <samp>docs/readme.txt</samp> as <samp>/usr/doc/ant/README</samp> into the
  175. archive. All <samp>*.html</samp> files in the <samp>docs</samp> directory are prefixed
  176. by <samp>/usr/doc/ant</samp>, so for example <samp>docs/index.html</samp> is written
  177. as <samp>/usr/doc/ant/index.html</samp> to the archive.</p>
  178. <pre>
  179. &lt;tar longfile=&quot;gnu&quot;
  180. destfile=&quot;${dist.base}/${dist.name}-src.tar&quot;&gt;
  181. &lt;tarfileset dir=&quot;${dist.name}/..&quot; filemode=&quot;755&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  182. &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  183. &lt;include name=&quot;${dist.name}/build.sh&quot;/&gt;
  184. &lt;/tarfileset&gt;
  185. &lt;tarfileset dir=&quot;${dist.name}/..&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  186. &lt;include name=&quot;${dist.name}/**&quot;/&gt;
  187. &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  188. &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
  189. &lt;/tarfileset&gt;
  190. &lt;/tar&gt;</pre>
  191. <p>This example shows building a tar which uses the GNU extensions for long paths and where some
  192. files need to be marked as executable (mode 755) and the rest are use the default mode (read-write
  193. by owner). The first fileset selects just the executable files. The second fileset must exclude the
  194. executable files and include all others.</p>
  195. <p><strong>Note</strong>: The <code>tar</code> task does not ensure that a file is only selected by
  196. one resource collection. If the same file is selected by more than one collection, it will be
  197. included in the tar file twice, with the same path.</p>
  198. <p><strong>Note</strong>: The patterns in the <code>include</code> and <code>exclude</code> elements
  199. are considered to be relative to the corresponding <var>dir</var> attribute as with all other
  200. filesets. In the example above, <samp>${dist.name}</samp> is not an absolute path, but a simple
  201. name of a directory, so <samp>${dist.name}</samp> is a valid path relative
  202. to <samp>${dist.name}/..</samp>.</p>
  203. <pre>
  204. &lt;tar destfile="release.tar.gz" compression="gzip"&gt;
  205. &lt;zipfileset src="release.zip"/&gt;
  206. &lt;/tar&gt;</pre>
  207. <p>Re-packages a ZIP archive as a GZip compressed tar archive. If Unix file permissions have been
  208. stored as part of the ZIP file, they will be retained in the resulting tar archive.</p>
  209. <p><strong>Note</strong>: Please note the <code>tar</code> task creates a tar file, it does not
  210. append to an existing tar file. The existing tar file is replaced instead. As with most tasks in
  211. Ant, the task only takes action if the output file (the tar file in this case) is older than the
  212. input files, or if the output file does not exist.</p>
  213. </body>
  214. </html>