Browse Source

Fixed a number of bugs with new Zip modifications.

Submitted By: "Rosen, Alex" <arosen@silverstream.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268334 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
bca3e675c3
1 changed files with 26 additions and 5 deletions
  1. +26
    -5
      src/main/org/apache/tools/ant/taskdefs/Zip.java

+ 26
- 5
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -150,9 +150,11 @@ public class Zip extends MatchingTask {
} }


public void execute() throws BuildException { public void execute() throws BuildException {
if (baseDir == null && filesets.size() == 0 && "zip".equals(archiveType))
if (baseDir == null && filesets.size() == 0 &&
locFileSets.size() == 0 && "zip".equals(archiveType)) {
throw new BuildException( "basedir attribute must be set, or at least " + throw new BuildException( "basedir attribute must be set, or at least " +
"one fileset must be given!" );
"one fileset or prefixedfileset must be given!" );
}


if (zipFile == null) { if (zipFile == null) {
throw new BuildException("You must specify the " + archiveType + " file to create!"); throw new BuildException("You must specify the " + archiveType + " file to create!");
@@ -178,6 +180,7 @@ public class Zip extends MatchingTask {
log("Building "+ archiveType +": "+ zipFile.getAbsolutePath()); log("Building "+ archiveType +": "+ zipFile.getAbsolutePath());


try { try {
boolean success = false;
ZipOutputStream zOut = new ZipOutputStream(new FileOutputStream(zipFile)); ZipOutputStream zOut = new ZipOutputStream(new FileOutputStream(zipFile));
try { try {
if (doCompress) { if (doCompress) {
@@ -191,9 +194,24 @@ public class Zip extends MatchingTask {
for (int j = 0; j < dssSize; j++) { for (int j = 0; j < dssSize; j++) {
addFiles(scanners[j], zOut, ""); addFiles(scanners[j], zOut, "");
success = true;
} }
} finally { } finally {
zOut.close ();
// Close the output stream.
try {
if (zOut != null)
zOut.close ();
} catch(IOException ex) {
// If we're in this finally clause because of an exception, we don't
// really care if there's an exception when closing the stream. E.g. if it
// throws "ZIP file must have at least one entry", because an exception happened
// before we added any files, then we must swallow this exception. Otherwise,
// the error that's reported will be the close() error, which is not the real
// cause of the problem.
if (success)
throw ex;
}
} }
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Problem creating " + archiveType + ": " + ioe.getMessage(); String msg = "Problem creating " + archiveType + ": " + ioe.getMessage();
@@ -473,7 +491,7 @@ public class Zip extends MatchingTask {
} }


/** /**
* Iterate over the given Vector of relocatablefilesets and add
* Iterate over the given Vector of prefixedfilesets and add
* all files to the ZipOutputStream using the given prefix. * all files to the ZipOutputStream using the given prefix.
*/ */
protected void addPrefixedFiles(Vector v, ZipOutputStream zOut) protected void addPrefixedFiles(Vector v, ZipOutputStream zOut)
@@ -487,7 +505,10 @@ public class Zip extends MatchingTask {
&& !prefix.endsWith("\\")) { && !prefix.endsWith("\\")) {
prefix += "/"; prefix += "/";
} }
zipDir(null, zOut, prefix);
if (prefix.length() > 0) {
addParentDirs(null, prefix, zOut, "");
zipDir(null, zOut, prefix);
}
addFiles(ds, zOut, prefix); addFiles(ds, zOut, prefix);
} }
} }


Loading…
Cancel
Save