donaldp 01/09/24 09:28:05
Modified: src/main/org/apache/tools/ant/taskdefs Zip.java
Log:
Fixed case where
<zip zipfile="test.zip">
<zipfileset src="test1.jar"
includes="META-INF/taglib.tld"
fullpath="tld/taglib.tld"/>
</zip>
would fail to copy source file to fullpath.
Submitted by: "Bordet, Simone" <[EMAIL PROTECTED]>
Revision Changes Path
1.51 +18 -9
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.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- Zip.java 2001/09/24 15:57:24 1.50
+++ Zip.java 2001/09/24 16:28:05 1.51
@@ -268,7 +268,7 @@
boolean success = false;
try {
ZipOutputStream zOut =
- new ZipOutputStream(new FileOutputStream(zipFile));
+ new ZipOutputStream(new FileOutputStream(zipFile));
zOut.setEncoding(encoding);
try {
if (doCompress) {
@@ -367,7 +367,7 @@
protected void addFiles(FileScanner scanner, ZipOutputStream zOut,
String prefix, String fullpath) throws
IOException {
if (prefix.length() > 0 && fullpath.length() > 0)
- throw new BuildException("Both prefix and fullpath attributes
may not be set on the same fileset.");
+ throw new BuildException("Both prefix and fullpath attributes
may not be set on the same fileset.");
File thisBaseDir = scanner.getBasedir();
@@ -388,7 +388,7 @@
// files that matched include patterns
String[] files = scanner.getIncludedFiles();
- if (files.length > 1 && fullpath.length() > 0)
+ if (files.length > 1 && fullpath.length() > 0)
throw new BuildException("fullpath attribute may only be
specified for filesets that specify a single file.");
for (int i = 0; i < files.length; i++) {
File f = new File(thisBaseDir, files[i]);
@@ -409,9 +409,12 @@
}
protected void addZipEntries(ZipFileSet fs, DirectoryScanner ds,
- ZipOutputStream zOut, String prefix)
+ ZipOutputStream zOut, String prefix, String
fullpath)
throws IOException
{
+ if (prefix.length() > 0 && fullpath.length() > 0)
+ throw new BuildException("Both prefix and fullpath attributes
may not be set on the same fileset.");
+
ZipScanner zipScanner = (ZipScanner) ds;
File zipSrc = fs.getSrc();
@@ -425,9 +428,14 @@
entry = new ZipEntry(origEntry);
String vPath = entry.getName();
if (zipScanner.match(vPath)) {
- addParentDirs(null, vPath, zOut, prefix);
- if (! entry.isDirectory()) {
- zipFile(in, zOut, prefix+vPath, entry.getTime());
+ if (prefix.length() > 0) {
+ addParentDirs(null, vPath, zOut, prefix);
+ if (! entry.isDirectory()) {
+ zipFile(in, zOut, prefix+vPath, entry.getTime());
+ }
+ }
+ else if (fullpath.length() > 0) {
+ zipFile(in, zOut, fullpath, entry.getTime());
}
}
}
@@ -691,7 +699,8 @@
/**
* Iterate over the given Vector of (zip)filesets and add
- * all files to the ZipOutputStream using the given prefix.
+ * all files to the ZipOutputStream using the given prefix
+ * or fullpath.
*/
protected void addFiles(Vector filesets, ZipOutputStream zOut)
throws IOException {
@@ -725,7 +734,7 @@
if (fs instanceof ZipFileSet
&& ((ZipFileSet) fs).getSrc() != null) {
- addZipEntries((ZipFileSet) fs, ds, zOut, prefix);
+ addZipEntries((ZipFileSet) fs, ds, zOut, prefix, fullpath);
} else {
// Add the fileset.
addFiles(ds, zOut, prefix, fullpath);