bodewig 2003/04/02 22:41:51
Modified: . WHATSNEW src/main/org/apache/tools/ant/taskdefs Jar.java Log: Improve standards compliance of created index. PR: 16972 Revision Changes Path 1.387 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.386 retrieving revision 1.387 diff -u -r1.386 -r1.387 --- WHATSNEW 2 Apr 2003 16:01:15 -0000 1.386 +++ WHATSNEW 3 Apr 2003 06:41:50 -0000 1.387 @@ -84,6 +84,9 @@ * <jar index="on"> could include multiple index lists. Bugzilla 10262. +* The index created by <jar> 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 1.74 +28 -7 ant/src/main/org/apache/tools/ant/taskdefs/Jar.java Index: Jar.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- Jar.java 2 Apr 2003 16:01:15 -0000 1.73 +++ Jar.java 3 Apr 2003 06:41:51 -0000 1.74 @@ -67,6 +67,7 @@ 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 @@ */ 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 @@ 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 @@ + " 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 @@ 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(); } /**