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

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