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

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