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

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