Browse Source

<unzip> can now deal with self-extracting archives.

PR: 16213
Submitted by:	Jason Salter <jasonsalter at hotmail dot com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274512 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
b113154a3a
5 changed files with 57 additions and 7 deletions
  1. +3
    -0
      WHATSNEW
  2. +5
    -0
      src/etc/testcases/taskdefs/unzip.xml
  3. BIN
      src/etc/testcases/taskdefs/zip/test.exe
  4. +40
    -7
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  5. +9
    -0
      src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java

+ 3
- 0
WHATSNEW View File

@@ -273,6 +273,9 @@ Other changes:


* A wrapper script for OS/2 has been added. * 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 Changes from Ant 1.5.2 to Ant 1.5.3
=================================== ===================================




+ 5
- 0
src/etc/testcases/taskdefs/unzip.xml View File

@@ -63,4 +63,9 @@
</patternset> </patternset>
</unzip> </unzip>
</target> </target>

<target name="selfExtractingArchive">
<mkdir dir="unziptestout"/>
<unzip dest="unziptestout" src="zip/test.exe"/>
</target>
</project> </project>

BIN
src/etc/testcases/taskdefs/zip/test.exe View File


+ 40
- 7
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -56,14 +56,16 @@ package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Vector; import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@@ -78,6 +80,7 @@ import org.apache.tools.ant.util.FileUtils;
* @author costin@dnt.ro * @author costin@dnt.ro
* @author Stefan Bodewig * @author Stefan Bodewig
* @author Magesh Umasankar * @author Magesh Umasankar
* @author <a href="mailto:jasonsalter@hotmail.com">Jason Salter</a>
* *
* @since Ant 1.1 * @since Ant 1.1
* *
@@ -92,6 +95,9 @@ public class Expand extends Task {
private boolean overwrite = true; private boolean overwrite = true;
private Vector patternsets = new Vector(); private Vector patternsets = new Vector();
private Vector filesets = 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. * Do the work.
@@ -148,11 +154,34 @@ public class Expand extends Task {
protected void expandFile(FileUtils fileUtils, File srcF, File dir) { protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
ZipInputStream zis = null; ZipInputStream zis = null;
FileInputStream fis = null;
RandomAccessFile raf = null;
byte[] buff = new byte[MARKER_SIZE];
try { 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) { while ((ze = zis.getNextEntry()) != null) {
extractFile(fileUtils, srcF, dir, zis, extractFile(fileUtils, srcF, dir, zis,
ze.getName(), new Date(ze.getTime()), ze.getName(), new Date(ze.getTime()),
@@ -164,6 +193,11 @@ public class Expand extends Task {
throw new BuildException("Error while expanding " + srcF.getPath(), throw new BuildException("Error while expanding " + srcF.getPath(),
ioe); ioe);
} finally { } finally {
if (raf != null) {
try {
raf.close();
} catch (IOException e) {}
}
if (zis != null) { if (zis != null) {
try { try {
zis.close(); zis.close();
@@ -216,7 +250,6 @@ public class Expand extends Task {
return; return;
} }
} }

File f = fileUtils.resolveFile(dir, entryName); File f = fileUtils.resolveFile(dir, entryName);
try { try {
if (!overwrite && f.exists() if (!overwrite && f.exists()


+ 9
- 0
src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java View File

@@ -134,4 +134,13 @@ public class UnzipTest extends BuildFileTest {
!getProject().resolveFile("unziptestout/2/bar").exists()); !getProject().resolveFile("unziptestout/2/bar").exists());
} }


/*
* PR 16213
*/
public void testSelfExtractingArchive() {
expectLogContaining("selfExtractingArchive",
"found a preamble of 38439 bytes, "
+ "probably a self-extracting archive");
}

} }

Loading…
Cancel
Save