diff --git a/WHATSNEW b/WHATSNEW index ce5a822d4..18aa0c68c 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -84,6 +84,9 @@ Fixed bugs: * could include multiple index lists. Bugzilla 10262. +* The index created by didn't conform to the spec as it didn't + include the top-level entries. Bugzilla Report 16972. + Other changes: -------------- * Shipped XML parser is now Xerces 2.4.0 diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index 80a2f4ad8..b740409b3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -67,6 +67,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.util.Enumeration; +import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.tools.ant.BuildException; @@ -145,12 +146,24 @@ public class Jar extends Zip { */ private boolean createEmpty = false; + /** + * Stores all files that are in the root of the archive (i.e. that + * have a name that doesn't contain a slash) so they can get + * listed in the index. + * + * Will not be filled unless the user has asked for an index. + * + * @since Ant 1.6 + */ + private Vector rootEntries; + /** constructor */ public Jar() { super(); archiveType = "jar"; emptyBehavior = "create"; setEncoding("UTF8"); + rootEntries = new Vector(); } /** @@ -458,6 +471,11 @@ public class Jar extends Zip { writer.println(dir); } + enum = rootEntries.elements(); + while (enum.hasMoreElements()) { + writer.println(enum.nextElement()); + } + writer.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); @@ -480,6 +498,9 @@ public class Jar extends Zip { + " files include a META-INF/INDEX.LIST which will" + " be replaced by a newly generated one.", Project.MSG_WARN); } else { + if (index && vPath.indexOf("/") == -1) { + rootEntries.addElement(vPath); + } super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode); } } @@ -663,13 +684,13 @@ public class Jar extends Zip { super.cleanUp(); // we want to save this info if we are going to make another pass - if (! doubleFilePass || (doubleFilePass && ! skipWriting)) - { - manifest = null; - configuredManifest = savedConfiguredManifest; - filesetManifest = null; - originalManifest = null; - } + if (! doubleFilePass || (doubleFilePass && ! skipWriting)) { + manifest = null; + configuredManifest = savedConfiguredManifest; + filesetManifest = null; + originalManifest = null; + } + rootEntries.removeAllElements(); } /**