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
|
---|
33 | done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
|
---|
34 | attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
|
---|
35 | have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
|
---|
36 | the files you want to have excluded. This is also done with patterns. And
|
---|
37 | finally with the <i>defaultexcludes</i> attribute, you can specify whether you
|
---|
38 | want to use default exclusions or not. See the section on <a
|
---|
39 | href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
|
---|
40 | inclusion/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
|
---|
42 | supports all attributes of <code><fileset></code>
|
---|
43 | (<code>dir</code> becomes <code>basedir</code>) as well as the nested
|
---|
44 | <code><include></code>, <code><exclude></code> and
|
---|
45 | <code><patternset></code> elements.</p>
|
---|
46 | <p>Or, you may place within it nested file sets, or references to file sets.
|
---|
47 | In this case <code>basedir</code> is optional; the implicit file set is <i>only used</i>
|
---|
48 | if <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>
|
---|
50 | and optional subelements like <code><include></code>); explicit nested
|
---|
51 | <code><fileset></code> elements so long as at least one fileset total is specified. The ZIP file will
|
---|
52 | 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>
|
---|
53 | <p>The Zip task also supports the merging of multiple zip files into the zip file.
|
---|
54 | This is possible through either the <i>src</i> attribute of any nested filesets
|
---|
55 | or by using the special nested fileset <i>zipgroupfileset</i>.</p>
|
---|
56 |
|
---|
57 | <p>The <code>update</code> parameter controls what happens if the ZIP
|
---|
58 | file already exists. When set to <code>yes</code>, the ZIP file is
|
---|
59 | updated with the files specified. (New files are added; old files are
|
---|
60 | replaced with the new versions.) When set to <code>no</code> (the
|
---|
61 | default) the ZIP file is overwritten if any of the files that would be
|
---|
62 | added to the archive are newer than the entries inside the archive.
|
---|
63 | Please note that ZIP files store file modification times with a
|
---|
64 | granularity of two seconds. If a file is less than two seconds newer
|
---|
65 | than 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.
|
---|
68 | If <code>skip</code> (the default), the ZIP is not created and a warning is issued.
|
---|
69 | If <code>fail</code>, the ZIP is not created and the build is halted with an error.
|
---|
70 | If <code>create</code>, an empty ZIP file (explicitly zero entries) is created,
|
---|
71 | which should be recognized as such by compliant ZIP manipulation tools.</p>
|
---|
72 | <p>This task will now use the platform's default character encoding
|
---|
73 | for filenames - this is consistent with the command line ZIP tools,
|
---|
74 | but causes problems if you try to open them from within Java and your
|
---|
75 | filenames contain non US-ASCII characters. Use the encoding attribute
|
---|
76 | and set it to UTF8 to create zip files that can safely be read by
|
---|
77 | Java.</p>
|
---|
78 |
|
---|
79 | <p>Starting with Ant 1.5.2, <code><zip></code> can store Unix permissions
|
---|
80 | inside the archive (see description of the filemode and dirmode
|
---|
81 | attributes for <a href="../CoreTypes/zipfileset.html"><zipfileset></a>).
|
---|
82 | Unfortunately there is no portable way to store these permissions.
|
---|
83 | Ant uses the algorithm used by <a href="http://www.info-zip.org">Info-Zip's</a>
|
---|
84 | implementation of the zip and unzip commands - these are the default
|
---|
85 | versions 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
|
---|
88 | fully-qualified name to exist within a single archive. This has been
|
---|
89 | documented as causing various problems for unsuspecting users. If you wish
|
---|
90 | to avoid this behavior you must set the <code>duplicate</code> attribute
|
---|
91 | to a value other than its default, <code>"add"</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 | ("yes"/"no"). 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 "false".</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 "fail", "skip", and "create". Default is "skip".</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 "add", "preserve", and "fail". The default value is "add". </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
|
---|
221 | Collection</a>s are used to select groups of files to archive.</p>
|
---|
222 | <p>Prior to Ant 1.7 only <code><fileset></code> and
|
---|
223 | <code><zipfileset></code> have been supported as nested elements.</p>
|
---|
224 |
|
---|
225 | <h4>zipgroupfileset</h4>
|
---|
226 | <p>A <code><zipgroupfileset></code> allows for multiple zip files to be
|
---|
227 | merged into the archive. Each file found in this fileset is added to the archive
|
---|
228 | the same way that <i>zipfileset src</i> files are added.</p>
|
---|
229 |
|
---|
230 |
|
---|
231 | <h3>Examples</h3>
|
---|
232 | <pre> <zip destfile="${dist}/manual.zip"
|
---|
233 | basedir="htdocs/manual"
|
---|
234 | /></pre>
|
---|
235 | <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
|
---|
236 | in the <code>${dist}</code> directory.</p>
|
---|
237 | <pre> <zip destfile="${dist}/manual.zip"
|
---|
238 | basedir="htdocs/manual"
|
---|
239 | update="true"
|
---|
240 | /></pre>
|
---|
241 | <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
|
---|
242 | in the <code>${dist}</code> directory. If <code>manual.zip</code>
|
---|
243 | doesn't exist, it is created; otherwise it is updated with the
|
---|
244 | new/changed files.</p>
|
---|
245 | <pre> <zip destfile="${dist}/manual.zip"
|
---|
246 | basedir="htdocs/manual"
|
---|
247 | excludes="mydocs/**, **/todo.html"
|
---|
248 | /></pre>
|
---|
249 | <p>zips all files in the <code>htdocs/manual</code> directory. Files in the directory <code>mydocs</code>,
|
---|
250 | or files with the name <code>todo.html</code> are excluded.</p>
|
---|
251 | <pre> <zip destfile="${dist}/manual.zip"
|
---|
252 | basedir="htdocs/manual"
|
---|
253 | includes="api/**/*.html"
|
---|
254 | excludes="**/todo.html"
|
---|
255 | /></pre>
|
---|
256 | <p>zips all files in the <code>htdocs/manual</code> directory. Only html files under the directory <code>api</code>
|
---|
257 | are zipped, and files with the name <code>todo.html</code> are excluded.</p>
|
---|
258 | <pre> <zip destfile="${dist}/manual.zip">
|
---|
259 | <fileset dir="htdocs/manual"/>
|
---|
260 | <fileset dir="." includes="ChangeLog.txt"/>
|
---|
261 | </zip></pre>
|
---|
262 | <p>zips all files in the <code>htdocs/manual</code> directory, and also adds the file <code>ChangeLog.txt</code> in the
|
---|
263 | current directory. <code>ChangeLog.txt</code> will be added to the top of the ZIP file, just as if
|
---|
264 | it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
|
---|
265 | <pre> <zip destfile="${dist}/manual.zip">
|
---|
266 | <zipfileset dir="htdocs/manual" prefix="docs/user-guide"/>
|
---|
267 | <zipfileset dir="." includes="ChangeLog27.txt" fullpath="docs/ChangeLog.txt"/>
|
---|
268 | <zipfileset src="examples.zip" includes="**/*.html" prefix="docs/examples"/>
|
---|
269 | </zip></pre>
|
---|
270 | <p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory
|
---|
271 | in the archive, adds the file <code>ChangeLog27.txt</code> in the
|
---|
272 | current directory as <code>docs/ChangeLog.txt</code>, and includes all the html files in <code>examples.zip</code>
|
---|
273 | under <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>
|
---|
279 | The code
|
---|
280 | <pre>
|
---|
281 | <zip destfile="${dist}/manual.zip">
|
---|
282 | <zipfileset dir="htdocs/manual" prefix="docs/user-guide"/>
|
---|
283 | <zipgroupfileset dir="." includes="examples*.zip"/>
|
---|
284 | </zip>
|
---|
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 | <zip dest="release.zip">
|
---|
291 | <tarfileset src="release.tar"/>
|
---|
292 | </zip>
|
---|
293 | </pre>
|
---|
294 |
|
---|
295 | <p>Re-packages a TAR archive as a ZIP archive. If Unix file
|
---|
296 | permissions have been stored as part of the TAR file, they will be
|
---|
297 | retained in the resulting ZIP archive.</p>
|
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|
301 | </body>
|
---|
302 | </html>
|
---|
303 |
|
---|