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 9.3 KiB

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