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