From e24b8aa6a0ca6c3984c88e6b71b3335315fb20b1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 15 Jul 2009 10:10:54 +0000 Subject: [PATCH] new zip logic bypassed overridden method in jar and broke manifest/index logic git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@794212 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Jar.java | 12 ++++++---- .../org/apache/tools/ant/taskdefs/Zip.java | 24 +++++++++++-------- src/tests/antunit/taskdefs/jar-test.xml | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index e4287250a..2251b3c8d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -462,7 +462,7 @@ public class Jar extends Zip { super.zipFile(is, zOut, "META-INF/services/" + service.getType(), System.currentTimeMillis(), null, - ZipFileSet.DEFAULT_FILE_MODE); + ZipFileSet.DEFAULT_FILE_MODE, null); } finally { // technically this is unnecessary since // Service.getAsStream returns a ByteArrayInputStream @@ -550,7 +550,7 @@ public class Jar extends Zip { try { super.zipFile(bais, zOut, MANIFEST_NAME, System.currentTimeMillis(), null, - ZipFileSet.DEFAULT_FILE_MODE); + ZipFileSet.DEFAULT_FILE_MODE, null); } finally { // not really required FileUtils.close(bais); @@ -638,7 +638,7 @@ public class Jar extends Zip { new ByteArrayInputStream(baos.toByteArray()); try { super.zipFile(bais, zOut, INDEX_NAME, System.currentTimeMillis(), - null, ZipFileSet.DEFAULT_FILE_MODE); + null, ZipFileSet.DEFAULT_FILE_MODE, null); } finally { // not really required FileUtils.close(bais); @@ -658,7 +658,8 @@ public class Jar extends Zip { * @throws IOException on error */ protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, - long lastModified, File fromArchive, int mode) + long lastModified, File fromArchive, int mode, + ZipExtraField[] extra) throws IOException { if (MANIFEST_NAME.equalsIgnoreCase(vPath)) { if (isFirstPass()) { @@ -673,7 +674,8 @@ public class Jar extends Zip { if (index && vPath.indexOf("/") == -1) { rootEntries.addElement(vPath); } - super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode); + super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode, + extra); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index dc09e40e5..21569fc08 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -921,7 +921,9 @@ public class Zip extends MatchingTask { ? fileMode : getUnixMode(resources[i], zf, fileMode); addResource(resources[i], name, prefix, - zOut, thisFileMode, zf); + zOut, thisFileMode, zf, + zfs == null + ? null : zfs.getSrc(getProject())); } } } @@ -982,7 +984,7 @@ public class Zip extends MatchingTask { */ private void addResource(Resource r, String name, String prefix, ZipOutputStream zOut, int mode, - ZipFile zf) + ZipFile zf, File fromArchive) throws IOException { if (zf != null) { @@ -997,7 +999,7 @@ public class Zip extends MatchingTask { try { is = zf.getInputStream(ze); zipFile(is, zOut, prefix + name, ze.getTime(), - mode, ze.getExtraFields()); + fromArchive, mode, ze.getExtraFields()); } finally { doCompress = oldCompress; FileUtils.close(is); @@ -1008,7 +1010,7 @@ public class Zip extends MatchingTask { try { is = r.getInputStream(); zipFile(is, zOut, prefix + name, r.getLastModified(), - mode, r instanceof ZipResource + fromArchive, mode, r instanceof ZipResource ? ((ZipResource) r).getExtraFields() : null); } finally { FileUtils.close(is); @@ -1065,7 +1067,7 @@ public class Zip extends MatchingTask { } else { addResource(resources[i], name, "", zOut, ArchiveFileSet.DEFAULT_FILE_MODE, - null); + null, null); } } } @@ -1639,11 +1641,9 @@ public class Zip extends MatchingTask { * @throws IOException on error */ protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath, - long lastModified, - /* unused, BWC */ File fromArchive, - int mode) + long lastModified, File fromArchive, int mode) throws IOException { - zipFile(in, zOut, vPath, lastModified, mode, null); + zipFile(in, zOut, vPath, lastModified, fromArchive, mode, null); } /** @@ -1663,8 +1663,12 @@ public class Zip extends MatchingTask { * @throws IOException on error */ protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath, - long lastModified, int mode, ZipExtraField[] extra) + long lastModified, File fromArchive, + int mode, ZipExtraField[] extra) throws IOException { + + // fromArchive is used in subclasses overriding this method + if (entries.contains(vPath)) { if (duplicate.equals("preserve")) { diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml index e8f1d1235..0edae8ccd 100644 --- a/src/tests/antunit/taskdefs/jar-test.xml +++ b/src/tests/antunit/taskdefs/jar-test.xml @@ -87,7 +87,7 @@ resource="${output}/META-INF/INDEX.LIST"/> -