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

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