source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/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: 12.9 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, &lt;zip&gt; 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<h3>Parameters</h3>
72<table border="1" cellpadding="2" cellspacing="0">
73 <tr>
74 <td valign="top"><b>Attribute</b></td>
75 <td valign="top"><b>Description</b></td>
76 <td valign="top" align="center"><b>Required</b></td>
77 </tr>
78 <tr>
79 <td valign="top">destfile</td>
80 <td valign="top">the zip-file to create.</td>
81 <td align="center" valign="top" rowspan="2">Exactly one of the two.</td>
82 </tr>
83 <tr>
84 <td valign="top">zipfile</td>
85 <td valign="top">the <i>deprecated</i> old name of destfile.</td>
86 </tr>
87 <tr>
88 <td valign="top">basedir</td>
89 <td valign="top">the directory from which to zip the files.</td>
90 <td align="center" valign="top">No</td>
91 </tr>
92 <tr>
93 <td valign="top">compress</td>
94 <td valign="top">Not only store data but also compress them,
95 defaults to true. Unless you set the <em>keepcompression</em>
96 attribute to false, this will apply to the entire archive, not
97 only the files you've added while updating.</td>
98 <td align="center" valign="top">No</td>
99 </tr>
100 <tr>
101 <td valign="top">keepcompression</td>
102 <td valign="top">For entries coming from existing archives (like
103 nested <em>zipfileset</em>s or while updating the archive), keep
104 the compression as it has been originally instead of using the
105 <em>compress</em> attribute. Defaults false. <em>Since Ant
106 1.6</em></td>
107 <td align="center" valign="top">No</td>
108 </tr>
109 <tr>
110 <td valign="top">encoding</td>
111 <td valign="top">The character encoding to use for filenames
112 inside the zip file. For a list of possible values see <a
113 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>.
114 Defaults to the platform's default character encoding.</td>
115 <td align="center" valign="top">No</td>
116 </tr>
117 <tr>
118 <td valign="top">filesonly</td>
119 <td valign="top">Store only file entries, defaults to false</td>
120 <td align="center" valign="top">No</td>
121 </tr>
122 <tr>
123 <td valign="top">includes</td>
124 <td valign="top">comma- or space-separated list of patterns of files that must be
125 included. All files are included when omitted.</td>
126 <td valign="top" align="center">No</td>
127 </tr>
128 <tr>
129 <td valign="top">includesfile</td>
130 <td valign="top">the name of a file. Each line of this file is
131 taken to be an include pattern</td>
132 <td valign="top" align="center">No</td>
133 </tr>
134 <tr>
135 <td valign="top">excludes</td>
136 <td valign="top">comma- or space-separated list of patterns of files that must be
137 excluded. No files (except default excludes) are excluded when omitted.</td>
138 <td valign="top" align="center">No</td>
139 </tr>
140 <tr>
141 <td valign="top">excludesfile</td>
142 <td valign="top">the name of a file. Each line of this file is
143 taken to be an exclude pattern</td>
144 <td valign="top" align="center">No</td>
145 </tr>
146 <tr>
147 <td valign="top">defaultexcludes</td>
148 <td valign="top">indicates whether default excludes should be used or not
149 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
150 <td valign="top" align="center">No</td>
151 </tr>
152 <tr>
153 <td valign="top">update</td>
154 <td valign="top">indicates whether to update or overwrite
155 the destination file if it already exists. Default is &quot;false&quot;.</td>
156 <td valign="top" align="center">No</td>
157 </tr>
158 <tr>
159 <td valign="top">whenempty</td>
160 <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>
161 <td valign="top" align="center">No</td>
162 </tr>
163 <tr>
164 <td valign="top">duplicate</td>
165 <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>
166 <td valign="top" align="center">No</td>
167 </tr>
168 <tr>
169 <td valign="top">roundup</td>
170 <td valign="top">Whether the file modification times will be
171 rounded up to the next even number of seconds.<br>
172 Zip archives store file modification times with a granularity of
173 two seconds, so the times will either be rounded up or down. If
174 you round down, the archive will always seem out-of-date when you
175 rerun the task, so the default is to round up. Rounding up may
176 lead to a different type of problems like JSPs inside a web
177 archive that seem to be slightly more recent than precompiled
178 pages, rendering precompilation useless.<br>
179 Defaults to true. <em>Since Ant 1.6.2</em></td>
180 <td align="center" valign="top">No</td>
181 </tr>
182</table>
183<h3>Parameters specified as nested elements</h3>
184<h4>fileset</h4>
185<p>The zip task supports any number of nested <a
186href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
187the files to be included in the archive.</p>
188
189<h4>zipfileset</h4>
190
191<p>The zip task supports any number of nested <a
192href="../CoreTypes/zipfileset.html"><code>&lt;zipfileset&gt;</code></a> elements to specify
193the files to be included in the archive.</p>
194
195<h4>zipgroupfileset</h4>
196<p>A <code>&lt;zipgroupfileset&gt;</code> allows for multiple zip files to be
197merged into the archive. Each file found in this fileset is added to the archive
198the same way that <i>zipfileset src</i> files are added.</p>
199
200
201<h3>Examples</h3>
202<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
203 basedir=&quot;htdocs/manual&quot;
204 /&gt;</pre>
205<p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
206in the <code>${dist}</code> directory.</p>
207<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
208 basedir=&quot;htdocs/manual&quot;
209 update=&quot;true&quot;
210 /&gt;</pre>
211<p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
212in the <code>${dist}</code> directory. If <code>manual.zip</code>
213doesn't exist, it is created; otherwise it is updated with the
214new/changed files.</p>
215<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
216 basedir=&quot;htdocs/manual&quot;
217 excludes=&quot;mydocs/**, **/todo.html&quot;
218 /&gt;</pre>
219<p>zips all files in the <code>htdocs/manual</code> directory. Files in the directory <code>mydocs</code>,
220or files with the name <code>todo.html</code> are excluded.</p>
221<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
222 basedir=&quot;htdocs/manual&quot;
223 includes=&quot;api/**/*.html&quot;
224 excludes=&quot;**/todo.html&quot;
225 /&gt;</pre>
226<p>zips all files in the <code>htdocs/manual</code> directory. Only html files under the directory <code>api</code>
227are zipped, and files with the name <code>todo.html</code> are excluded.</p>
228<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
229 &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
230 &lt;fileset dir=&quot;.&quot; includes=&quot;ChangeLog.txt&quot;/&gt;
231 &lt;/zip&gt;</pre>
232<p>zips all files in the <code>htdocs/manual</code> directory, and also adds the file <code>ChangeLog.txt</code> in the
233current directory. <code>ChangeLog.txt</code> will be added to the top of the ZIP file, just as if
234it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
235<pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
236 &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
237 &lt;zipfileset dir=&quot;.&quot; includes=&quot;ChangeLog27.txt&quot; fullpath=&quot;docs/ChangeLog.txt&quot;/&gt;
238 &lt;zipfileset src=&quot;examples.zip&quot; includes=&quot;**/*.html&quot; prefix=&quot;docs/examples&quot;/&gt;
239 &lt;/zip&gt;</pre>
240<p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory
241in the archive, adds the file <code>ChangeLog27.txt</code> in the
242current directory as <code>docs/ChangeLog.txt</code>, and includes all the html files in <code>examples.zip</code>
243under <code>docs/examples</code>. The archive might end up containing the files:</p>
244<pre><code> docs/user-guide/html/index.html
245 docs/ChangeLog.txt
246 docs/examples/index.html
247</code></pre>
248<p>
249The code
250<pre>
251 &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
252 &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
253 &lt;zipgroupfileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
254 &lt;/zip&gt;</pre>
255</pre>
256<p>
257<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>.
258<hr>
259<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
260Reserved.</p>
261
262</body>
263</html>
264
Note: See TracBrowser for help on using the repository browser.