From 7f2456889917312606d26c68b9cbb32cbaba48b7 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Fri, 10 Jul 2009 14:24:29 +0000
Subject: [PATCH] add a new indexMetaInf attribute to . PR 47457.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@792960 13f79535-47bb-0310-9956-ffa450edef68
---
WHATSNEW | 4 +++
docs/manual/CoreTasks/ear.html | 14 +++++++++
docs/manual/CoreTasks/jar.html | 14 +++++++++
.../org/apache/tools/ant/taskdefs/Jar.java | 30 +++++++++++++++----
src/tests/antunit/taskdefs/jar-test.xml | 26 ++++++++++++++++
5 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 75010cf3a..613972d17 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -749,6 +749,10 @@ Other changes:
optional prefix and suffix attributes.
Bugzilla Report 45625
+ * has a new attribute to enable indexing of META-INF
+ directories which is desabled for backwards compatibility reasons.
+ Bugzilla Report 47457
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
diff --git a/docs/manual/CoreTasks/ear.html b/docs/manual/CoreTasks/ear.html
index 34c746e07..ea6768add 100644
--- a/docs/manual/CoreTasks/ear.html
+++ b/docs/manual/CoreTasks/ear.html
@@ -155,6 +155,20 @@ to a value other than its default, "add"
.
false.
No |
+
+ indexMetaInf |
+ whether to include META-INF and its children in
+ the index. Doesn't have any effect if index is
+ false.
+ Sun's jar implementation used to skip the META-INF directory and
+ Ant followed that example. The behavior has been changed with
+ Java
+ 5. In order to avoid problems with Ant generated jars on
+ Java 1.4 or earlier Ant will not include META-INF unless
+ explicitly asked to.
+ Ant 1.8.0 - Defaults to false. |
+ No |
+
update |
indicates whether to update or overwrite
diff --git a/docs/manual/CoreTasks/jar.html b/docs/manual/CoreTasks/jar.html
index d1eecac23..105f3b6c2 100644
--- a/docs/manual/CoreTasks/jar.html
+++ b/docs/manual/CoreTasks/jar.html
@@ -204,6 +204,20 @@ to a value other than its default, "add" .
false. |
No |
+
+ indexMetaInf |
+ whether to include META-INF and its children in
+ the index. Doesn't have any effect if index is
+ false.
+ Sun's jar implementation used to skip the META-INF directory and
+ Ant followed that example. The behavior has been changed with
+ Java
+ 5. In order to avoid problems with Ant generated jars on
+ Java 1.4 or earlier Ant will not include META-INF unless
+ explicitly asked to.
+ Ant 1.8.0 - Defaults to false. |
+ No |
+
manifestencoding |
The encoding used to read the JAR manifest, when a manifest file is specified. |
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java
index fb3d20971..a3e5b49f9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java
@@ -119,6 +119,9 @@ public class Jar extends Zip {
/** jar index is JDK 1.3+ only */
private boolean index = false;
+ /** Whether to index META-INF/ and its children */
+ private boolean indexMetaInf = false;
+
/**
* whether to really create the archive in createEmptyZip, will
* get set in getResourcesToAdd.
@@ -223,6 +226,25 @@ public class Jar extends Zip {
index = flag;
}
+ /**
+ * Set whether or not to add META-INF and its children to the index.
+ *
+ * Doesn't have any effect if index is false.
+ *
+ * Sun's jar implementation used to skip the META-INF directory
+ * and Ant followed that example. The behavior has been changed
+ * with Java 5. In order to avoid problems with Ant generated
+ * jars on Java 1.4 or earlier Ant will not include META-INF
+ * unless explicitly asked to.
+ *
+ * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526
+ * @since Ant 1.8.0
+ * @param flag a boolean
value, defaults to false
+ */
+ public void setIndexMetaInf(boolean flag) {
+ indexMetaInf = flag;
+ }
+
/**
* The character encoding to use in the manifest file.
*
@@ -972,7 +994,9 @@ public class Jar extends Zip {
// looks like nothing from META-INF should be added
// and the check is not case insensitive.
// see sun.misc.JarIndex
- if (dir.startsWith("META-INF")) {
+ // see also
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526
+ if (!indexMetaInf && dir.startsWith("META-INF")) {
continue;
}
// name newline
@@ -1064,9 +1088,6 @@ public class Jar extends Zip {
org.apache.tools.zip.ZipEntry ze =
(org.apache.tools.zip.ZipEntry) entries.nextElement();
String name = ze.getName();
- // META-INF would be skipped anyway, avoid index for
- // manifest-only jars.
- if (!name.startsWith("META-INF/")) {
if (ze.isDirectory()) {
dirSet.add(name);
} else if (name.indexOf("/") == -1) {
@@ -1079,7 +1100,6 @@ public class Jar extends Zip {
dirSet.add(name.substring(0,
name.lastIndexOf("/") + 1));
}
- }
}
dirs.addAll(dirSet);
} finally {
diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml
index bee7a6601..6678ef2f6 100644
--- a/src/tests/antunit/taskdefs/jar-test.xml
+++ b/src/tests/antunit/taskdefs/jar-test.xml
@@ -60,4 +60,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+