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

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