bodewig 2003/04/24 06:02:57
Modified: . WHATSNEW src/etc/testcases/taskdefs unzip.xml src/main/org/apache/tools/ant/taskdefs Expand.java src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java Added: src/etc/testcases/taskdefs/zip test.exe Log: <unzip> can now deal with self-extracting archives. PR: 16213 Submitted by: Jason Salter <jasonsalter at hotmail dot com> Revision Changes Path 1.405 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.404 retrieving revision 1.405 diff -u -r1.404 -r1.405 --- WHATSNEW 24 Apr 2003 09:11:38 -0000 1.404 +++ WHATSNEW 24 Apr 2003 13:02:53 -0000 1.405 @@ -273,6 +273,9 @@ * A wrapper script for OS/2 has been added. +* <unzip> will now detect and successfully extract self-extracting + archives. Bugzilla Report 16213. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== 1.5 +5 -0 ant/src/etc/testcases/taskdefs/unzip.xml Index: unzip.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/unzip.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- unzip.xml 7 Feb 2003 14:59:06 -0000 1.4 +++ unzip.xml 24 Apr 2003 13:02:56 -0000 1.5 @@ -63,4 +63,9 @@ </patternset> </unzip> </target> + + <target name="selfExtractingArchive"> + <mkdir dir="unziptestout"/> + <unzip dest="unziptestout" src="zip/test.exe"/> + </target> </project> 1.1 ant/src/etc/testcases/taskdefs/zip/test.exe <<Binary file>> 1.42 +40 -7 ant/src/main/org/apache/tools/ant/taskdefs/Expand.java Index: Expand.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- Expand.java 7 Mar 2003 11:23:01 -0000 1.41 +++ Expand.java 24 Apr 2003 13:02:56 -0000 1.42 @@ -56,14 +56,16 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.RandomAccessFile; import java.io.FileOutputStream; -import java.io.IOException; +import java.io.FileNotFoundException; import java.io.InputStream; +import java.io.IOException; +import java.util.Arrays; import java.util.Date; import java.util.Vector; -import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import java.util.zip.ZipEntry; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -78,6 +80,7 @@ * @author [EMAIL PROTECTED] * @author Stefan Bodewig * @author Magesh Umasankar + * @author <a href="mailto:[EMAIL PROTECTED]">Jason Salter</a> * * @since Ant 1.1 * @@ -92,6 +95,9 @@ private boolean overwrite = true; private Vector patternsets = new Vector(); private Vector filesets = new Vector(); + private static final byte[] ZIPMARKER = {0x50, 0x4b, 0x03, 0x04}; + private static final int MARKER_SIZE = ZIPMARKER.length; + private static final int MAX_LOOKAHEAD = 50 * 1024; // 50K. /** * Do the work. @@ -148,11 +154,34 @@ protected void expandFile(FileUtils fileUtils, File srcF, File dir) { log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); ZipInputStream zis = null; + FileInputStream fis = null; + RandomAccessFile raf = null; + byte[] buff = new byte[MARKER_SIZE]; try { - // code from WarExpand - zis = new ZipInputStream(new FileInputStream(srcF)); - ZipEntry ze = null; + raf = new RandomAccessFile(srcF, "r"); + long offset = 0; + int more = raf.read(buff); + boolean foundMarker = false; + while (more != -1 || offset < MAX_LOOKAHEAD) { + if (Arrays.equals(buff, ZIPMARKER)) { + foundMarker = true; + break; + } + raf.seek(++offset); + more = raf.read(buff); + } + raf.close(); + raf = null; + fis = new FileInputStream(srcF); + if (foundMarker && offset > 0) { + log("found a preamble of " + offset + + " bytes, probably a self-extracting archive"); + fis.skip(offset); + } + + zis = new ZipInputStream(fis); + ZipEntry ze = null; while ((ze = zis.getNextEntry()) != null) { extractFile(fileUtils, srcF, dir, zis, ze.getName(), new Date(ze.getTime()), @@ -164,6 +193,11 @@ throw new BuildException("Error while expanding " + srcF.getPath(), ioe); } finally { + if (raf != null) { + try { + raf.close(); + } catch (IOException e) {} + } if (zis != null) { try { zis.close(); @@ -216,7 +250,6 @@ return; } } - File f = fileUtils.resolveFile(dir, entryName); try { if (!overwrite && f.exists() 1.9 +9 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java Index: UnzipTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- UnzipTest.java 7 Mar 2003 11:23:11 -0000 1.8 +++ UnzipTest.java 24 Apr 2003 13:02:57 -0000 1.9 @@ -134,4 +134,13 @@ !getProject().resolveFile("unziptestout/2/bar").exists()); } + /* + * PR 16213 + */ + public void testSelfExtractingArchive() { + expectLogContaining("selfExtractingArchive", + "found a preamble of 38439 bytes, " + + "probably a self-extracting archive"); + } + }