Author: bodewig
Date: Thu Aug 11 04:43:02 2011
New Revision: 1156486
URL: http://svn.apache.org/viewvc?rev=1156486&view=rev
Log:
Control ZIP64 support
Added:
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java
(with props)
Modified:
ant/antlibs/compress/trunk/changes.xml
ant/antlibs/compress/trunk/docs/archive.html
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
ant/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
Modified: ant/antlibs/compress/trunk/changes.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/changes.xml?rev=1156486&r1=1156485&r2=1156486&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/changes.xml (original)
+++ ant/antlibs/compress/trunk/changes.xml Thu Aug 11 04:43:02 2011
@@ -43,6 +43,11 @@
Compress 1.3 which in turn requires Java5 at runtime.
</action>
<action type="update">
+ The <zip> task has a new attribute zip64Mode that
+ controls whether Zip64 extended information is written to the
+ archive.
+ </action>
+ <action type="update">
The <ar> task now optionally suppports writing entries
with names longer than 16 characters using the BSD variant of
AR archives.
Modified: ant/antlibs/compress/trunk/docs/archive.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/archive.html?rev=1156486&r1=1156485&r2=1156486&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/archive.html (original)
+++ ant/antlibs/compress/trunk/docs/archive.html Thu Aug 11 04:43:02 2011
@@ -463,6 +463,26 @@ the executable files and include all oth
Default is false.</td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">zip64Mode</td>
+ <td valign="top">Controls whether Zip64 extended information is
+ written to the archive.<br/>
+ In order to store entries bigger than 4GB or more than 65536
+ entries inside an archive, so called Zip64 extensions must be
+ used. An archive that uses such extensions may not be
+ readable by all unarchivers.<br/>
+ The possible modes are "always", "never" and "as-needed". The
+ default is "as-needed" which enables Zip64 extensions if a
+ resource is added to the archive whose size is known to exceed
+ 4GB or if there are more than 65536 entries. "as-needed" does
+ not work for resources of unknown size (like URL-resources),
+ if you try to archive such resources, the default will be
+ "never" instead of "as-needed".<br/>
+ If the mode is "never" and the resource actually exceeds the
+ limit, the build will fail.
+ </td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<h3>Examples</h3>
Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=1156486&r1=1156485&r2=1156486&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Thu
Aug 11 04:43:02 2011
@@ -131,4 +131,9 @@
name="hasmode"
classname="org.apache.ant.compress.conditions.HasMode"
/>
+
+ <typedef
+ name="devzero"
+ classname="org.apache.ant.compress.resources.DevZeroResource"
+ />
</antlib>
Added:
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java?rev=1156486&view=auto
==============================================================================
---
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java
(added)
+++
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java
Thu Aug 11 04:43:02 2011
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ant.compress.resources;
+
+import org.apache.tools.ant.types.Resource;
+import java.io.InputStream;
+import java.util.Arrays;
+
+/**
+ * A resource that returns arbitrary many 0-bytes as its content.
+ *
+ * <p>This class should likely be part of Ant and only lives here as
+ * it is needed for tests.</p>
+ *
+ * @since Compress Antlib 1.2
+ */
+public class DevZeroResource extends Resource {
+
+ public InputStream getInputStream() {
+ final long size = getSize();
+ return new InputStream() {
+ private long bytesRead = 0;
+ public int read() {
+ return bytesRead++ < size ? 0 : -1;
+ }
+ public int read(byte[] b) {
+ return read(b, 0, b.length);
+ }
+ public int read(byte[] b, int off, int len) {
+ len = (int) Math.min((long) len, size - bytesRead);
+ bytesRead += len;
+ Arrays.fill(b, off, off + len, (byte) 0);
+ return len == 0 ? -1 : len;
+ }
+ };
+ }
+}
Propchange:
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/DevZeroResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java?rev=1156486&r1=1156485&r2=1156486&view=diff
==============================================================================
---
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
(original)
+++
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
Thu Aug 11 04:43:02 2011
@@ -29,6 +29,7 @@ import org.apache.ant.compress.util.ZipS
import org.apache.ant.compress.resources.ZipFileSet;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.tools.ant.types.ArchiveFileSet;
@@ -45,6 +46,7 @@ public class Zip extends ArchiveBase {
private boolean fallBackToUTF8 = false;
private boolean useLanguageEncodingFlag = true;
private UnicodeExtraField createUnicodeExtraFields =
UnicodeExtraField.NEVER;
+ private Zip64Enum zip64Mode = Zip64Enum.AS_NEEDED;
public Zip() {
setFactory(new ZipStreamFactory() {
@@ -162,12 +164,22 @@ public class Zip extends ArchiveBase {
createUnicodeExtraFields = b;
}
+ /**
+ * Whether to create Zip64 extended information.
+ *
+ * @since Commons Compress 1.1
+ */
+ public void setZip64Mode(Zip64Enum mode) {
+ zip64Mode = mode;
+ }
+
private void configure(ZipArchiveOutputStream o) {
o.setLevel(level);
o.setComment(comment);
o.setFallbackToUTF8(fallBackToUTF8);
o.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
o.setCreateUnicodeExtraFields(createUnicodeExtraFields.getPolicy());
+ o.setUseZip64(zip64Mode.getPolicy());
}
/**
@@ -208,4 +220,37 @@ public class Zip extends ArchiveBase {
POLICIES.get(getValue());
}
}
+
+ /**
+ * Policiy for creation of Zip64 extended information: never, always or
+ * as-needed.
+ */
+ public static final class Zip64Enum extends EnumeratedAttribute {
+ private static final Map POLICIES = new HashMap();
+ private static final String NEVER_KEY = "never";
+ private static final String ALWAYS_KEY = "always";
+ private static final String A_N_KEY = "as-needed";
+ static {
+ POLICIES.put(NEVER_KEY, Zip64Mode.Never);
+ POLICIES.put(ALWAYS_KEY, Zip64Mode.Always);
+ POLICIES.put(A_N_KEY, Zip64Mode.AsNeeded);
+ }
+
+ public String[] getValues() {
+ return new String[] {NEVER_KEY, ALWAYS_KEY, A_N_KEY};
+ }
+
+ public static final Zip64Enum AS_NEEDED = new Zip64Enum(A_N_KEY);
+
+ private Zip64Enum(String name) {
+ setValue(name);
+ }
+
+ public Zip64Enum() {
+ }
+
+ public Zip64Mode getPolicy() {
+ return (Zip64Mode) POLICIES.get(getValue());
+ }
+ }
}
\ No newline at end of file
Modified: ant/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/zip-test.xml?rev=1156486&r1=1156485&r2=1156486&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/zip-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/zip-test.xml Thu Aug 11
04:43:02 2011
@@ -597,4 +597,23 @@
</cond:islastmodified>
</au:assertFalse>
</target>
+
+ <target name="testBigArchiveWithZip64" depends="setUp">
+ <cmp:zip dest="${dest}" zip64mode="always">
+ <cmp:devzero size="5000000000" name="big"/>
+ </cmp:zip>
+ <assertResourceExists>
+ <cmp:zipentry name="big">
+ <file file="${dest}"/>
+ </cmp:zipentry>
+ </assertResourceExists>
+ </target>
+
+ <target name="testBigArchiveWithoutZip64" depends="setUp">
+ <au:expectfailure>
+ <cmp:zip dest="${dest}" zip64mode="never">
+ <cmp:devzero size="5000000000" name="big"/>
+ </cmp:zip>
+ </au:expectfailure>
+ </target>
</project>