donaldp 00/12/08 16:33:51
Modified: src/main/org/apache/tools/ant/taskdefs Zip.java
Log:
Fixed a number of bugs with new Zip modifications.
Submitted By: "Rosen, Alex" <[EMAIL PROTECTED]>
Revision Changes Path
1.21 +26 -5
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Zip.java 2000/12/07 12:21:12 1.20
+++ Zip.java 2000/12/09 00:33:50 1.21
@@ -150,9 +150,11 @@
}
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 " +
- "one fileset must be given!" );
+ "one fileset or prefixedfileset must
be given!" );
+ }
if (zipFile == null) {
throw new BuildException("You must specify the " + archiveType +
" file to create!");
@@ -178,6 +180,7 @@
log("Building "+ archiveType +": "+ zipFile.getAbsolutePath());
try {
+ boolean success = false;
ZipOutputStream zOut = new ZipOutputStream(new
FileOutputStream(zipFile));
try {
if (doCompress) {
@@ -191,9 +194,24 @@
for (int j = 0; j < dssSize; j++) {
addFiles(scanners[j], zOut, "");
+
+ success = true;
}
} 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) {
String msg = "Problem creating " + archiveType + ": " +
ioe.getMessage();
@@ -473,7 +491,7 @@
}
/**
- * 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.
*/
protected void addPrefixedFiles(Vector v, ZipOutputStream zOut)
@@ -486,8 +504,11 @@
&& !prefix.endsWith("/")
&& !prefix.endsWith("\\")) {
prefix += "/";
+ }
+ if (prefix.length() > 0) {
+ addParentDirs(null, prefix, zOut, "");
+ zipDir(null, zOut, prefix);
}
- zipDir(null, zOut, prefix);
addFiles(ds, zOut, prefix);
}
}