From 1bff308e51b3dfe4bb1b3ee10cd92b78e9643a18 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Sun, 31 Aug 2008 15:38:38 +0000 Subject: [PATCH] Bugzilla 45098: update jar index with no other changes git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@690714 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++ .../org/apache/tools/ant/taskdefs/Jar.java | 33 +++++++++++- src/tests/antunit/taskdefs/jar-test.xml | 52 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/tests/antunit/taskdefs/jar-test.xml diff --git a/WHATSNEW b/WHATSNEW index 5ecb794d7..c18589518 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -316,6 +316,10 @@ Other changes: manual page for details. Bugzilla Report 37241. + * The Jar task now supports the addition of a jar index file in update mode. + Previously the absence of the index was not enough to trigger the rebuild; + some other update was necessary. Bugzilla report 45098. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index 080671315..92fa9213a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -340,6 +340,29 @@ public class Jar extends Zip { return newManifest; } + private boolean jarHasIndex(File jarFile) throws IOException { + ZipFile zf = null; + try { + zf = new ZipFile(jarFile); + Enumeration e = zf.entries(); + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + if (ze.getName().equalsIgnoreCase(INDEX_NAME)) { + return true; + } + } + return false; + } finally { + if (zf != null) { + try { + zf.close(); + } catch (IOException e) { + // XXX - log an error? throw an exception? + } + } + } + } + /** * Behavior when a Manifest is found in a zipfileset or zipgroupfileset file. * Valid values are "skip", "merge", and "mergewithoutmain". @@ -593,7 +616,7 @@ public class Jar extends Zip { } } else if (INDEX_NAME.equalsIgnoreCase(vPath) && index) { log("Warning: selected " + archiveType - + " files include a META-INF/INDEX.LIST which will" + + " files include a " + INDEX_NAME + " which will" + " be replaced by a newly generated one.", Project.MSG_WARN); } else { if (index && vPath.indexOf("/") == -1) { @@ -734,6 +757,14 @@ public class Jar extends Zip { } createEmpty = needsUpdate; + if (!needsUpdate && index) { + try { + needsUpdate = !jarHasIndex(zipFile); + } catch (IOException e) { + //if we couldn't read it, we might as well recreate it? + needsUpdate = true; + } + } return super.getResourcesToAdd(rcs, zipFile, needsUpdate); } diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml new file mode 100644 index 000000000..0b4483229 --- /dev/null +++ b/src/tests/antunit/taskdefs/jar-test.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +