source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/zip.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 13.5 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Zip Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="zip">Zip</a></h2>
12<h3>Description</h3>
13<p>Creates a zipfile.</p>
14<p>The <i>basedir</i> attribute is the reference directory from where to zip.</p>
15<p>Note that file permissions will not be stored in the resulting zipfile.</p>
16<p>It is possible to refine the set of files that are being zipped. This can be
17done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
18attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
19have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
20the files you want to have excluded. This is also done with patterns. And
21finally with the <i>defaultexcludes</i> attribute, you can specify whether you
22want to use default exclusions or not. See the section on <a
23href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
24inclusion/exclusion of files works, and how to write patterns. </p>
25<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
26supports all attributes of <code>&lt;fileset&gt;</code>
27(<code>dir</code> becomes <code>basedir</code>) as well as the nested
28<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
29<code>&lt;patternset&gt;</code> elements.</p>
30<p>Or, you may place within it nested file sets, or references to file sets.
31In this case <code>basedir</code> is optional; the implicit file set is <i>only used</i>
32if <code>basedir</code> is set. You may use any mixture of the implicit file set
33(with <code>basedir</code> set, and optional attributes like <code>includes</code>
34and optional subelements like <code>&lt;include&gt;</code>); explicit nested
35<code>&lt;fileset&gt;</code> elements so long as at least one fileset total is specified. The ZIP file will
36only 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>
37<p>The Zip task also supports the merging of multiple zip files into the zip file.
38This is possible through either the <i>src</i> attribute of any nested filesets
39or by using the special nested fileset <i>zipgroupfileset</i>.</p>
40
41<p>The <code>update</code> parameter controls what happens if the ZIP
42file already exists. When set to <code>yes</code>, the ZIP file is
43updated with the files specified. (New files are added; old files are
44replaced with the new versions.) When set to <code>no</code> (the
45default) the ZIP file is overwritten if any of the files that would be
46added to the archive are newer than the entries inside the archive.
47Please note that ZIP files store file modification times with a
48granularity of two seconds. If a file is less than two seconds newer
49than the entry in the archive, Ant will not consider it newer.</p>
50
51<p>The <code>whenempty</code> parameter controls what happens when no files match.
52If <code>skip</code> (the default), the ZIP is not created and a warning is issued.
53If <code>fail</code>, the ZIP is not created and the build is halted with an error.
54If <code>create</code>, an empty ZIP file (explicitly zero entries) is created,
55which should be recognized as such by compliant ZIP manipulation tools.</p>
56<p>This task will now use the platform's default character encoding
57for filenames - this is consistent with the command line ZIP tools,
58but causes problems if you try to open them from within Java and your
59filenames contain non US-ASCII characters. Use the encoding attribute
60and set it to UTF8 to create zip files that can safely be read by
61Java.</p>
62
63<p>Starting with Ant 1.5.2, <code>&lt;zip&gt;</code> can store Unix permissions
64inside the archive (see description of the filemode and dirmode
65attributes for <a href="../CoreTypes/zipfileset.html">&lt;zipfileset&gt;</a>).
66Unfortunately there is no portable way to store these permissions.
67Ant uses the algorithm used by <a href="http://www.info-zip.org">Info-Zip's</a>
68implementation of the zip and unzip commands - these are the default
69versions of zip and unzip for many Unix and Unix-like systems.</p>
70
71<p><b>Please note that the zip format allows multiple files of the same
72fully-qualified name to exist within a single archive. This has been
73documented as causing various problems for unsuspecting users. If you wish
74to avoid this behavior you must set the <code>duplicate</code> attribute
75to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
76
77<h3>Parameters</h3>
78<table border="1" cellpadding="2" cellspacing="0">
79 <tr>
80 <td valign="top"><b>Attribute</b></td>
81 <td valign="top"><b>Description</b></td>
82 <td valign="top" align="center"><b>Required</b></td>
83 </tr>
84 <tr>
85 <td valign="top">destfile</td>
86 <td valign="top">the zip-file to create.</td>
87 <td align="center" valign="top" rowspan="2">Exactly one of the two.</td>
88 </tr>
89 <tr>
90 <td valign="top">zipfile</td>
91 <td valign="top">the <i>deprecated</i> old name of destfile.</td>
92 </tr>
93 <tr>
94 <td valign="top">basedir</td>
95 <td valign="top">the directory from which to zip the files.</td>
96 <td align="center" valign="top">No</td>
97 </tr>
98 <tr>
99 <td valign="top">compress</td>
100 <td valign="top">Not only store data but also compress them,
101 defaults to true. Unless you set the <em>keepcompression</em>
102 attribute to false, this will apply to the entire archive, not
103 only the files you've added while updating.</td>
104 <td align="center" valign="top">No</td>
105 </tr>
106 <tr>
107 <td valign="top">keepcompression</td>
108 <td valign="top">For entries coming from existing archives (like
109 nested <em>zipfileset</em>s or while updating the archive), keep
110 the compression as it has been originally instead of using the
111 <em>compress</em> attribute. Defaults false. <em>Since Ant
112 1.6</em></td>
113 <td align="center" valign="top">No</td>
114 </tr>
115 <tr>
116 <td valign="top">encoding</td>
117 <td valign="top">The character encoding to use for filenames
118 inside the zip file. For a list of possible values see <a
119 href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html">http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html</a>.
120 Defaults to the platform's default character encoding.</td>
121 <td align="center" valign="top">No</td>
122 </tr>
123 <tr>
124 <td valign="top">filesonly</td>
125 <td valign="top">Store only file entries, defaults to false</td>
126 <td align="center" valign="top">No</td>
127 </tr>
128 <tr>
129 <td valign="top">includes</td>
130 <td valign="top">comma- or space-separated list of patterns of files that must be
131 included. All files are included when omitted.</td>
132 <td valign="top" align="center">No</td>
133 </tr>
134 <tr>
135 <td valign="top">includesfile</td>
136 <td valign="top">the name of a file. Each line of this file is
137 taken to be an include pattern</td>
138 <td valign="top" align="center">No</td>
139 </tr>
140 <tr>
141 <td valign="top">excludes</td>
142 <td valign="top">comma- or space-separated list of patterns of files that must be
143 excluded. No files (except default excludes) are excluded when omitted.</td>
144 <td valign="top" align="center">No</td>
145 </tr>
146 <tr>
147 <td valign="top">excludesfile</td>
148 <td valign="top">the name of a file. Each line of this file is
149 taken to be an exclude pattern</td>
150 <td valign="top" align="center">No</td>
151 </tr>
152 <tr>
153 <td valign="top">defaultexcludes</td>
154 <td valign="top">indicates whether default excludes should be used or not
155 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
156 <td valign="top" align="center">No</td>
157 </tr>
158 <tr>
159 <td valign="top">update</td>
160 <td valign="top">indicates whether to update or overwrite
161 the destination file if it already exists. Default is &quot;false&quot;.</td>
162 <td valign="top" align="center">No</td>
163 </tr>
164 <tr>
165 <td valign="top">whenempty</td>
166 <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>
167 <td valign="top" align="center">No</td>
168 </tr>
169 <tr>
170 <td valign="top">duplicate</td>
171 <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>
172 <td valign="top" align="center">No</td>
173 </tr>
174 <tr>
175 <td valign="top">roundup</td>
176 <td valign="top">Whether the file modification times will be
177 rounded up to the next even number of seconds.<br>
178 Zip archives store file modification times with a granularity of
179 two seconds, so the times will either be rounded up or down. If
180 you round down, the archive will always seem out-of-date when you
181 rerun the task, so the default is to round up. Rounding up may
182 lead to a different type of problems like JSPs inside a web
183 archive that seem to be slightly more recent than precompiled
184 pages, rendering precompilation useless.<br>
185 Defaults to true. <em>Since Ant 1.6.2</em></td>
186 <td align="center" valign="top">No</td>
187 </tr>
188 <tr>
189 <td valign="top">comment</td>
190 <td valign="top">Comment to store in the archive. <em>Since Ant 1.6.3</em></td>
191 <td valign="top" align="center">No</td>
192 </tr>
193</table>
194<h3>Parameters specified as nested elements</h3>
195<h4>fileset</h4>
196<p>The zip task supports any number of nested <a
197href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
198the files to be included in the archive.</p>
199
200<h4>zipfileset</h4>
201
202<p>The zip task supports any number of nested <a
203href="../CoreTypes/zipfileset.html"><code>&lt;zipfileset&gt;</code></a> elements to specify
204the files to be included in the archive.</p>
205
206<h4>zipgroupfileset</h4>
207<p>A <code>&lt;zipgroupfileset&gt;</code> allows for multiple zip files to be
208merged into the archive. Each file found in this fileset is added to the archive
209the same way that <i>zipfileset src</i> files are added.</p>
210
211
212<h3>Examples</h3>
213<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
214 basedir=&quot;htdocs/manual&quot;
215 /&gt;</pre>
216<p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
217in the <code>${dist}</code> directory.</p>
218<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
219 basedir=&quot;htdocs/manual&quot;
220 update=&quot;true&quot;
221 /&gt;</pre>
222<p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
223in the <code>${dist}</code> directory. If <code>manual.zip</code>
224doesn't exist, it is created; otherwise it is updated with the
225new/changed files.</p>
226<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
227 basedir=&quot;htdocs/manual&quot;
228 excludes=&quot;mydocs/**, **/todo.html&quot;
229 /&gt;</pre>
230<p>zips all files in the <code>htdocs/manual</code> directory. Files in the directory <code>mydocs</code>,
231or files with the name <code>todo.html</code> are excluded.</p>
232<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
233 basedir=&quot;htdocs/manual&quot;
234 includes=&quot;api/**/*.html&quot;
235 excludes=&quot;**/todo.html&quot;
236 /&gt;</pre>
237<p>zips all files in the <code>htdocs/manual</code> directory. Only html files under the directory <code>api</code>
238are zipped, and files with the name <code>todo.html</code> are excluded.</p>
239<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
240 &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
241 &lt;fileset dir=&quot;.&quot; includes=&quot;ChangeLog.txt&quot;/&gt;
242 &lt;/zip&gt;</pre>
243<p>zips all files in the <code>htdocs/manual</code> directory, and also adds the file <code>ChangeLog.txt</code> in the
244current directory. <code>ChangeLog.txt</code> will be added to the top of the ZIP file, just as if
245it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
246<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
247 &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
248 &lt;zipfileset dir=&quot;.&quot; includes=&quot;ChangeLog27.txt&quot; fullpath=&quot;docs/ChangeLog.txt&quot;/&gt;
249 &lt;zipfileset src=&quot;examples.zip&quot; includes=&quot;**/*.html&quot; prefix=&quot;docs/examples&quot;/&gt;
250 &lt;/zip&gt;</pre>
251<p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory
252in the archive, adds the file <code>ChangeLog27.txt</code> in the
253current directory as <code>docs/ChangeLog.txt</code>, and includes all the html files in <code>examples.zip</code>
254under <code>docs/examples</code>. The archive might end up containing the files:</p>
255<pre> docs/user-guide/html/index.html
256 docs/ChangeLog.txt
257 docs/examples/index.html
258</pre>
259<p>
260The code
261<pre>
262 &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
263 &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
264 &lt;zipgroupfileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
265 &lt;/zip&gt;
266</pre>
267<p>
268<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>.
269<hr>
270<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
271Reserved.</p>
272
273</body>
274</html>
275
Note: See TracBrowser for help on using the repository browser.