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.

zip.html 16 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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>Zip Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="zip">Zip</a></h2>
  23. <h3>Description</h3>
  24. <p>Creates a zipfile.</p>
  25. <p>The <i>basedir</i> attribute is the reference directory from where to zip.</p>
  26. <p>Note that file permissions will not be stored in the resulting zipfile.</p>
  27. <p>It is possible to refine the set of files that are being zipped. This can be
  28. done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  29. attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  30. have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  31. the files you want to have excluded. This is also done with patterns. And
  32. finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  33. want to use default exclusions or not. See the section on <a
  34. href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  35. inclusion/exclusion of files works, and how to write patterns. </p>
  36. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  37. supports all attributes of <code>&lt;fileset&gt;</code>
  38. (<code>dir</code> becomes <code>basedir</code>) as well as the nested
  39. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  40. <code>&lt;patternset&gt;</code> elements.</p>
  41. <p>Or, you may place within it nested file sets, or references to file sets.
  42. In this case <code>basedir</code> is optional; the implicit file set is <i>only used</i>
  43. if <code>basedir</code> is set. You may use any mixture of the implicit file set
  44. (with <code>basedir</code> set, and optional attributes like <code>includes</code>
  45. and optional subelements like <code>&lt;include&gt;</code>); explicit nested
  46. <code>&lt;fileset&gt;</code> elements so long as at least one fileset total is specified. The ZIP file will
  47. only reflect the relative paths of files <i>within</i> each fileset. The Zip task and its derivatives know a special form of a fileset named zipfileset that has additional attributes (described below). </p>
  48. <p>The Zip task also supports the merging of multiple zip files into the zip file.
  49. This is possible through either the <i>src</i> attribute of any nested filesets
  50. or by using the special nested fileset <i>zipgroupfileset</i>.</p>
  51. <p>The <code>update</code> parameter controls what happens if the ZIP
  52. file already exists. When set to <code>yes</code>, the ZIP file is
  53. updated with the files specified. (New files are added; old files are
  54. replaced with the new versions.) When set to <code>no</code> (the
  55. default) the ZIP file is overwritten if any of the files that would be
  56. added to the archive are newer than the entries inside the archive.
  57. Please note that ZIP files store file modification times with a
  58. granularity of two seconds. If a file is less than two seconds newer
  59. than the entry in the archive, Ant will not consider it newer.</p>
  60. <p>The <code>whenempty</code> parameter controls what happens when no files match.
  61. If <code>skip</code> (the default), the ZIP is not created and a warning is issued.
  62. If <code>fail</code>, the ZIP is not created and the build is halted with an error.
  63. If <code>create</code>, an empty ZIP file (explicitly zero entries) is created,
  64. which should be recognized as such by compliant ZIP manipulation tools.</p>
  65. <p>This task will now use the platform's default character encoding
  66. for filenames - this is consistent with the command line ZIP tools,
  67. but causes problems if you try to open them from within Java and your
  68. filenames contain non US-ASCII characters. Use the encoding attribute
  69. and set it to UTF8 to create zip files that can safely be read by
  70. Java.</p>
  71. <p>Starting with Ant 1.5.2, <code>&lt;zip&gt;</code> can store Unix permissions
  72. inside the archive (see description of the filemode and dirmode
  73. attributes for <a href="../CoreTypes/zipfileset.html">&lt;zipfileset&gt;</a>).
  74. Unfortunately there is no portable way to store these permissions.
  75. Ant uses the algorithm used by <a href="http://www.info-zip.org">Info-Zip's</a>
  76. implementation of the zip and unzip commands - these are the default
  77. versions of zip and unzip for many Unix and Unix-like systems.</p>
  78. <p><b>Please note that the zip format allows multiple files of the same
  79. fully-qualified name to exist within a single archive. This has been
  80. documented as causing various problems for unsuspecting users. If you wish
  81. to avoid this behavior you must set the <code>duplicate</code> attribute
  82. to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
  83. <p><b>Please also note</b> that different ZIP tools handle timestamps
  84. differently when it comes to applying timezone offset calculations of
  85. files. Some ZIP libraries will store the timestamps as they've been
  86. read from the filesystem while others will modify the timestamps both
  87. when reading and writing the files to make all timestamps use the same
  88. timezone. A ZIP archive created by one library may extract files with
  89. "wrong timestamps" when extracted by another library.</p>
  90. <p>Ant's ZIP classes use the same algorithm as the InfoZIP tools and
  91. zlib (timestamps get adjusted), Windows' "compressed folders" function
  92. and WinZIP don't change the timestamps. This means that using the
  93. unzip task on files created by Windows' compressed folders function
  94. may create files with timestamps that are "wrong", the same is true if
  95. you use Windows' functions to extract an Ant generated ZIP
  96. archive.</p>
  97. <h3>Parameters</h3>
  98. <table border="1" cellpadding="2" cellspacing="0">
  99. <tr>
  100. <td valign="top"><b>Attribute</b></td>
  101. <td valign="top"><b>Description</b></td>
  102. <td valign="top" align="center"><b>Required</b></td>
  103. </tr>
  104. <tr>
  105. <td valign="top">destfile</td>
  106. <td valign="top">the zip-file to create.</td>
  107. <td align="center" valign="top" rowspan="2">Exactly one of the two.</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">zipfile</td>
  111. <td valign="top">the <i>deprecated</i> old name of destfile.</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">basedir</td>
  115. <td valign="top">the directory from which to zip the files.</td>
  116. <td align="center" valign="top">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">compress</td>
  120. <td valign="top">Not only store data but also compress them,
  121. defaults to true. Unless you set the <em>keepcompression</em>
  122. attribute to false, this will apply to the entire archive, not
  123. only the files you've added while updating.</td>
  124. <td align="center" valign="top">No</td>
  125. </tr>
  126. <tr>
  127. <td valign="top">keepcompression</td>
  128. <td valign="top">For entries coming from existing archives (like
  129. nested <em>zipfileset</em>s or while updating the archive), keep
  130. the compression as it has been originally instead of using the
  131. <em>compress</em> attribute. Defaults false. <em>Since Ant
  132. 1.6</em></td>
  133. <td align="center" valign="top">No</td>
  134. </tr>
  135. <tr>
  136. <td valign="top">encoding</td>
  137. <td valign="top">The character encoding to use for filenames
  138. inside the zip file. For a list of possible values see <a
  139. href="http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html">http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html</a>.
  140. Defaults to the platform's default character encoding.</td>
  141. <td align="center" valign="top">No</td>
  142. </tr>
  143. <tr>
  144. <td valign="top">filesonly</td>
  145. <td valign="top">Store only file entries, defaults to false</td>
  146. <td align="center" valign="top">No</td>
  147. </tr>
  148. <tr>
  149. <td valign="top">includes</td>
  150. <td valign="top">comma- or space-separated list of patterns of files that must be
  151. included. All files are included when omitted.</td>
  152. <td valign="top" align="center">No</td>
  153. </tr>
  154. <tr>
  155. <td valign="top">includesfile</td>
  156. <td valign="top">the name of a file. Each line of this file is
  157. taken to be an include pattern</td>
  158. <td valign="top" align="center">No</td>
  159. </tr>
  160. <tr>
  161. <td valign="top">excludes</td>
  162. <td valign="top">comma- or space-separated list of patterns of files that must be
  163. excluded. No files (except default excludes) are excluded when omitted.</td>
  164. <td valign="top" align="center">No</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">excludesfile</td>
  168. <td valign="top">the name of a file. Each line of this file is
  169. taken to be an exclude pattern</td>
  170. <td valign="top" align="center">No</td>
  171. </tr>
  172. <tr>
  173. <td valign="top">defaultexcludes</td>
  174. <td valign="top">indicates whether default excludes should be used or not
  175. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  176. <td valign="top" align="center">No</td>
  177. </tr>
  178. <tr>
  179. <td valign="top">update</td>
  180. <td valign="top">indicates whether to update or overwrite
  181. the destination file if it already exists. Default is &quot;false&quot;.</td>
  182. <td valign="top" align="center">No</td>
  183. </tr>
  184. <tr>
  185. <td valign="top">whenempty</td>
  186. <td valign="top">behavior when no files match. Valid values are &quot;fail&quot;, &quot;skip&quot;, and &quot;create&quot;. Default is &quot;skip&quot;.</td>
  187. <td valign="top" align="center">No</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">duplicate</td>
  191. <td valign="top">behavior when a duplicate file is found. Valid values are &quot;add&quot;, &quot;preserve&quot;, and &quot;fail&quot;. The default value is &quot;add&quot;. </td>
  192. <td valign="top" align="center">No</td>
  193. </tr>
  194. <tr>
  195. <td valign="top">roundup</td>
  196. <td valign="top">Whether the file modification times will be
  197. rounded up to the next even number of seconds.<br>
  198. Zip archives store file modification times with a granularity of
  199. two seconds, so the times will either be rounded up or down. If
  200. you round down, the archive will always seem out-of-date when you
  201. rerun the task, so the default is to round up. Rounding up may
  202. lead to a different type of problems like JSPs inside a web
  203. archive that seem to be slightly more recent than precompiled
  204. pages, rendering precompilation useless.<br>
  205. Defaults to true. <em>Since Ant 1.6.2</em></td>
  206. <td align="center" valign="top">No</td>
  207. </tr>
  208. <tr>
  209. <td valign="top">comment</td>
  210. <td valign="top">Comment to store in the archive. <em>Since Ant 1.6.3</em></td>
  211. <td valign="top" align="center">No</td>
  212. </tr>
  213. <tr>
  214. <td valign="top">level</td>
  215. <td valign="top">Non-default level at which file compression should be
  216. performed. Valid values range from 0 (no compression/fastest) to 9
  217. (maximum compression/slowest). <em>Since Ant 1.7</em></td>
  218. <td valign="top" align="center">No</td>
  219. </tr>
  220. <tr>
  221. <td valign="top">preserve0permissions</td>
  222. <td valign="top">when updating an archive or adding entries from a
  223. different archive Ant will assume that a Unix permissions value of
  224. 0 (nobody is allowed to do anything to the file/directory) means
  225. that the permissions haven't been stored at all rather than real
  226. permissions and will instead apply its own default values.<br/>
  227. Set this attribute to true if you really want to preserve the
  228. original permission field.<em>since Ant 1.8.0</em>
  229. </td>
  230. <td valign="top" align="center">No, default is false</td>
  231. </tr>
  232. </table>
  233. <h3>Parameters specified as nested elements</h3>
  234. <h4>any resource collection</h4>
  235. <p><a href="../CoreTypes/resources.html#collection">Resource
  236. Collection</a>s are used to select groups of files to archive.</p>
  237. <p>Prior to Ant 1.7 only <code>&lt;fileset&gt;</code> and
  238. <code>&lt;zipfileset&gt;</code> have been supported as nested elements.</p>
  239. <a name="zipgroupfileset" />
  240. <h4>zipgroupfileset</h4>
  241. <p>A <code>&lt;zipgroupfileset&gt;</code> allows for multiple zip files to be
  242. merged into the archive. Each file found in this fileset is added to the archive
  243. the same way that <i>zipfileset src</i> files are added.</p>
  244. <h3>Examples</h3>
  245. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  246. basedir=&quot;htdocs/manual&quot;
  247. /&gt;</pre>
  248. <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
  249. in the <code>${dist}</code> directory.</p>
  250. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  251. basedir=&quot;htdocs/manual&quot;
  252. update=&quot;true&quot;
  253. /&gt;</pre>
  254. <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
  255. in the <code>${dist}</code> directory. If <code>manual.zip</code>
  256. doesn't exist, it is created; otherwise it is updated with the
  257. new/changed files.</p>
  258. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  259. basedir=&quot;htdocs/manual&quot;
  260. excludes=&quot;mydocs/**, **/todo.html&quot;
  261. /&gt;</pre>
  262. <p>zips all files in the <code>htdocs/manual</code> directory. Files in the directory <code>mydocs</code>,
  263. or files with the name <code>todo.html</code> are excluded.</p>
  264. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  265. basedir=&quot;htdocs/manual&quot;
  266. includes=&quot;api/**/*.html&quot;
  267. excludes=&quot;**/todo.html&quot;
  268. /&gt;</pre>
  269. <p>zips all files in the <code>htdocs/manual</code> directory. Only html files under the directory <code>api</code>
  270. are zipped, and files with the name <code>todo.html</code> are excluded.</p>
  271. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  272. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  273. &lt;fileset dir=&quot;.&quot; includes=&quot;ChangeLog.txt&quot;/&gt;
  274. &lt;/zip&gt;</pre>
  275. <p>zips all files in the <code>htdocs/manual</code> directory, and also adds the file <code>ChangeLog.txt</code> in the
  276. current directory. <code>ChangeLog.txt</code> will be added to the top of the ZIP file, just as if
  277. it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
  278. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  279. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  280. &lt;zipfileset dir=&quot;.&quot; includes=&quot;ChangeLog27.txt&quot; fullpath=&quot;docs/ChangeLog.txt&quot;/&gt;
  281. &lt;zipfileset src=&quot;examples.zip&quot; includes=&quot;**/*.html&quot; prefix=&quot;docs/examples&quot;/&gt;
  282. &lt;/zip&gt;</pre>
  283. <p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory
  284. in the archive, adds the file <code>ChangeLog27.txt</code> in the
  285. current directory as <code>docs/ChangeLog.txt</code>, and includes all the html files in <code>examples.zip</code>
  286. under <code>docs/examples</code>. The archive might end up containing the files:</p>
  287. <pre> docs/user-guide/html/index.html
  288. docs/ChangeLog.txt
  289. docs/examples/index.html
  290. </pre>
  291. <p>
  292. The code
  293. <pre>
  294. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  295. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  296. &lt;zipgroupfileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
  297. &lt;/zip&gt;
  298. </pre>
  299. <p>
  300. <p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory in the archive and includes all the files in any file that maches <code>examples*.zip</code>, such as all files within <code>examples1.zip</code> or <code>examples_for_brian.zip</code>.
  301. <pre>
  302. &lt;zip dest="release.zip"&gt;
  303. &lt;tarfileset src="release.tar"/&gt;
  304. &lt;/zip&gt;
  305. </pre>
  306. <p>Re-packages a TAR archive as a ZIP archive. If Unix file
  307. permissions have been stored as part of the TAR file, they will be
  308. retained in the resulting ZIP archive.</p>
  309. </body>
  310. </html>