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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 copy. To use a
  127. resource collection, the <code>todir</code> attribute must be set.</p>
  128. <p>Prior to Ant 1.7 only <code>&lt;fileset&gt;</code> has been
  129. supported as a nested element.</p>
  130. <h3>Examples</h3>
  131. <pre>
  132. &lt;tar tarfile=&quot;${dist}/manual.tar&quot; basedir=&quot;htdocs/manual&quot;/&gt;
  133. &lt;gzip zipfile=&quot;${dist}/manual.tar.gz&quot; src=&quot;${dist}/manual.tar&quot;/&gt;</pre>
  134. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  135. in the <code>${dist}</code> directory, then applies the gzip task to compress
  136. it.</p>
  137. <pre>
  138. &lt;tar destfile=&quot;${dist}/manual.tar&quot;
  139. basedir=&quot;htdocs/manual&quot;
  140. excludes=&quot;mydocs/**, **/todo.html&quot;
  141. /&gt;</pre>
  142. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  143. in the <code>${dist}</code> directory. Files in the directory <code>mydocs</code>,
  144. or files with the name <code>todo.html</code> are excluded.</p>
  145. <pre>
  146. &lt;tar destfile=&quot;${basedir}/docs.tar&quot;&gt;
  147. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  148. fullpath=&quot;/usr/doc/ant/README&quot;
  149. preserveLeadingSlashes=&quot;true&quot;&gt;
  150. &lt;include name=&quot;readme.txt&quot;/&gt;
  151. &lt;/tarfileset&gt;
  152. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  153. prefix=&quot;/usr/doc/ant&quot;
  154. preserveLeadingSlashes=&quot;true&quot;&gt;
  155. &lt;include name=&quot;*.html&quot;/&gt;
  156. &lt;/tarfileset&gt;
  157. &lt;/tar&gt;</pre>
  158. <p>
  159. Writes the file <code>docs/readme.txt</code> as
  160. <code>/usr/doc/ant/README</code> into the archive. All
  161. <code>*.html</code> files in the <code>docs</code> directory are
  162. prefixed by <code>/usr/doc/ant</code>, so for example
  163. <code>docs/index.html</code> is written as
  164. <code>/usr/doc/ant/index.html</code> to the archive.
  165. </p>
  166. <pre>
  167. &lt;tar longfile=&quot;gnu&quot;
  168. destfile=&quot;${dist.base}/${dist.name}-src.tar&quot; &gt;
  169. &lt;tarfileset dir=&quot;${dist.name}/..&quot; mode=&quot;755&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  170. &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  171. &lt;include name=&quot;${dist.name}/build.sh&quot;/&gt;
  172. &lt;/tarfileset&gt;
  173. &lt;tarfileset dir=&quot;${dist.name}/..&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  174. &lt;include name=&quot;${dist.name}/**&quot;/&gt;
  175. &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  176. &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
  177. &lt;/tarfileset&gt;
  178. &lt;/tar&gt;
  179. </pre>
  180. <p>This example shows building a tar which uses the GNU extensions for long paths and
  181. where some files need to be marked as executable (mode 755)
  182. and the rest are use the default mode (read-write by owner). The first
  183. fileset selects just the executable files. The second fileset must exclude
  184. the executable files and include all others. </p>
  185. <p><strong>Note: </strong> The tar task does not ensure that a file is only selected
  186. by one resource collection. If the same file is selected by more than one collection, it will be included in the
  187. tar file twice, with the same path.</p>
  188. <p><strong>Note:</strong> The patterns in the include and exclude
  189. elements are considered to be relative to the corresponding dir
  190. attribute as with all other filesets. In the example above,
  191. <code>${dist.name}</code> is not an absolute path, but a simple name
  192. of a directory, so <code>${dist.name}</code> is a valid path relative
  193. to <code>${dist.name}/..</code>.</p>
  194. <pre>
  195. &lt;tar dest="release.tar.gz" compress="gzip"&gt;
  196. &lt;zipfileset src="release.zip"/&gt;
  197. &lt;/tar&gt;
  198. </pre>
  199. <p>Re-packages a ZIP archive as a GZip compressed tar archive. If
  200. Unix file permissions have been stored as part of the ZIP file, they
  201. will be retained in the resulting tar archive.</p>
  202. <hr>
  203. <p align="center">Copyright &copy; 2000-2002,2004-2005 The Apache Software Foundation. All rights
  204. Reserved.</p>
  205. </body>
  206. </html>