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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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="../CoreTypes/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.</p>
  36. <p>Early versions of tar did not support path lengths greater than 100
  37. characters. Modern versions of tar do so, but in incompatible ways.
  38. The behaviour of the tar task when it encounters such paths is
  39. controlled by the <i>longfile</i> attribute.
  40. If the longfile attribute is set to <code>fail</code>, any long paths will
  41. cause the tar task to fail. If the longfile attribute is set to
  42. <code>truncate</code>, any long paths will be truncated to the 100 character
  43. maximum length prior to adding to the archive. If the value of the longfile
  44. attribute is set to <code>omit</code> then files containing long paths will be
  45. omitted from the archive. Either option ensures that the archive can be
  46. untarred by any compliant version of tar. If the loss of path or file
  47. information is not acceptable, and it rarely is, longfile may be set to the
  48. value <code>gnu</code>. The tar task will then produce a GNU tar file which
  49. can have arbitrary length paths. Note however, that the resulting archive will
  50. only be able to be untarred with GNU tar. The default for the longfile
  51. attribute is <code>warn</code> which behaves just like the gnu option except
  52. that it produces a warning for each file path encountered that does not match
  53. the limit.</p>
  54. <p>This task can perform compression by setting the compression attribute to "gzip"
  55. or "bzip2".</p>
  56. <h3>Parameters</h3>
  57. <table border="1" cellpadding="2" cellspacing="0">
  58. <tr>
  59. <td valign="top"><b>Attribute</b></td>
  60. <td valign="top"><b>Description</b></td>
  61. <td valign="top" align="center"><b>Required</b></td>
  62. </tr>
  63. <tr>
  64. <td valign="top">destfile</td>
  65. <td valign="top">the tar-file to create.</td>
  66. <td align="center" valign="top">Yes</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">basedir</td>
  70. <td valign="top">the directory from which to tar the files.</td>
  71. <td align="center" valign="top">No</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">longfile</td>
  75. <td valign="top">Determines how long files (&gt;100 chars) are to be
  76. handled. Allowable values are &quot;truncate&quot;, &quot;fail&quot;,
  77. &quot;warn&quot;, &quot;omit&quot; and &quot;gnu&quot;. Default is
  78. &quot;warn&quot;.</td>
  79. <td valign="top" align="center">No</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">includes</td>
  83. <td valign="top">comma- or space-separated list of patterns of files that must be
  84. included. All files are included when omitted.</td>
  85. <td valign="top" align="center">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">includesfile</td>
  89. <td valign="top">the name of a file. Each line of this file is
  90. taken to be an include pattern</td>
  91. <td valign="top" align="center">No</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">excludes</td>
  95. <td valign="top">comma- or space-separated list of patterns of files that must be
  96. excluded. No files (except default excludes) are excluded when omitted.</td>
  97. <td valign="top" align="center">No</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">excludesfile</td>
  101. <td valign="top">the name of a file. Each line of this file is
  102. taken to be an exclude pattern</td>
  103. <td valign="top" align="center">No</td>
  104. </tr>
  105. <tr>
  106. <td valign="top">defaultexcludes</td>
  107. <td valign="top">indicates whether default excludes should be used or not
  108. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  109. <td valign="top" align="center">No</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">compression</td>
  113. <td valign="top">compression method. Allowable values are
  114. &quot;none&quot;, &quot;gzip&quot; and &quot;bzip2&quot;. Default is
  115. &quot;none&quot;.</td>
  116. <td valign="top" align="center">No</td>
  117. </tr>
  118. </table>
  119. <h3>Nested Elements</h3>
  120. The tar task supports nested <a
  121. href="../CoreTypes/tarfileset.html">tarfileset</a> elements. These are
  122. extended <a href="../CoreTypes/fileset.html">FileSets</a> which,
  123. in addition to the standard elements, support one additional
  124. attributes
  125. <table border="1" cellpadding="2" cellspacing="0">
  126. <tr>
  127. <td valign="top"><b>Attribute</b></td>
  128. <td valign="top"><b>Description</b></td>
  129. <td valign="top" align="center"><b>Required</b></td>
  130. </tr>
  131. <tr>
  132. <td valign="top">preserveLeadingSlashes</td>
  133. <td valign="top">Indicates whether leading `/'s should
  134. be preserved in the file names. Default is <code>false</code>.</td>
  135. <td align="center" valign="top">No</td>
  136. </tr>
  137. </table>
  138. <h4>any other resource collection</h4>
  139. <p><a href="../CoreTypes/resources.html#collection">Resource
  140. Collection</a>s are used to select groups of files to archive.</p>
  141. <p>Prior to Ant 1.7 only <code>&lt;fileset&gt;</code> has been
  142. supported as a nested element.</p>
  143. <h3>Examples</h3>
  144. <pre>
  145. &lt;tar tarfile=&quot;${dist}/manual.tar&quot; basedir=&quot;htdocs/manual&quot;/&gt;
  146. &lt;gzip zipfile=&quot;${dist}/manual.tar.gz&quot; src=&quot;${dist}/manual.tar&quot;/&gt;</pre>
  147. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  148. in the <code>${dist}</code> directory, then applies the gzip task to compress
  149. it.</p>
  150. <pre>
  151. &lt;tar destfile=&quot;${dist}/manual.tar&quot;
  152. basedir=&quot;htdocs/manual&quot;
  153. excludes=&quot;mydocs/**, **/todo.html&quot;
  154. /&gt;</pre>
  155. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  156. in the <code>${dist}</code> directory. Files in the directory <code>mydocs</code>,
  157. or files with the name <code>todo.html</code> are excluded.</p>
  158. <pre>
  159. &lt;tar destfile=&quot;${basedir}/docs.tar&quot;&gt;
  160. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  161. fullpath=&quot;/usr/doc/ant/README&quot;
  162. preserveLeadingSlashes=&quot;true&quot;&gt;
  163. &lt;include name=&quot;readme.txt&quot;/&gt;
  164. &lt;/tarfileset&gt;
  165. &lt;tarfileset dir=&quot;${dir.src}/docs&quot;
  166. prefix=&quot;/usr/doc/ant&quot;
  167. preserveLeadingSlashes=&quot;true&quot;&gt;
  168. &lt;include name=&quot;*.html&quot;/&gt;
  169. &lt;/tarfileset&gt;
  170. &lt;/tar&gt;</pre>
  171. <p>
  172. Writes the file <code>docs/readme.txt</code> as
  173. <code>/usr/doc/ant/README</code> into the archive. All
  174. <code>*.html</code> files in the <code>docs</code> directory are
  175. prefixed by <code>/usr/doc/ant</code>, so for example
  176. <code>docs/index.html</code> is written as
  177. <code>/usr/doc/ant/index.html</code> to the archive.
  178. </p>
  179. <pre>
  180. &lt;tar longfile=&quot;gnu&quot;
  181. destfile=&quot;${dist.base}/${dist.name}-src.tar&quot; &gt;
  182. &lt;tarfileset dir=&quot;${dist.name}/..&quot; mode=&quot;755&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  183. &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  184. &lt;include name=&quot;${dist.name}/build.sh&quot;/&gt;
  185. &lt;/tarfileset&gt;
  186. &lt;tarfileset dir=&quot;${dist.name}/..&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  187. &lt;include name=&quot;${dist.name}/**&quot;/&gt;
  188. &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  189. &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
  190. &lt;/tarfileset&gt;
  191. &lt;/tar&gt;
  192. </pre>
  193. <p>This example shows building a tar which uses the GNU extensions for long paths and
  194. where some files need to be marked as executable (mode 755)
  195. and the rest are use the default mode (read-write by owner). The first
  196. fileset selects just the executable files. The second fileset must exclude
  197. the executable files and include all others. </p>
  198. <p><strong>Note: </strong> The tar task does not ensure that a file is only selected
  199. by one resource collection. If the same file is selected by more than one collection, it will be included in the
  200. tar file twice, with the same path.</p>
  201. <p><strong>Note:</strong> The patterns in the include and exclude
  202. elements are considered to be relative to the corresponding dir
  203. attribute as with all other filesets. In the example above,
  204. <code>${dist.name}</code> is not an absolute path, but a simple name
  205. of a directory, so <code>${dist.name}</code> is a valid path relative
  206. to <code>${dist.name}/..</code>.</p>
  207. <pre>
  208. &lt;tar dest="release.tar.gz" compress="gzip"&gt;
  209. &lt;zipfileset src="release.zip"/&gt;
  210. &lt;/tar&gt;
  211. </pre>
  212. <p>Re-packages a ZIP archive as a GZip compressed tar archive. If
  213. Unix file permissions have been stored as part of the ZIP file, they
  214. will be retained in the resulting tar archive.</p>
  215. <p><strong>Note:</strong>
  216. Please note the tar task creates a tar file, it does not append
  217. to an existing tar file. The existing tar file is replaced instead.
  218. As with most tasks in Ant, the task only takes action if the output
  219. file (the tar file in this case) is older than the input files, or
  220. if the output file does not exist.
  221. </p>
  222. </body>
  223. </html>