Browse Source

Improve standards compliance of created index.

PR: 16972


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274386 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
9ba0cb2f6d
2 changed files with 31 additions and 7 deletions
  1. +3
    -0
      WHATSNEW
  2. +28
    -7
      src/main/org/apache/tools/ant/taskdefs/Jar.java

+ 3
- 0
WHATSNEW View File

@@ -84,6 +84,9 @@ Fixed bugs:


* <jar index="on"> could include multiple index lists. Bugzilla 10262. * <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: Other changes:
-------------- --------------
* Shipped XML parser is now Xerces 2.4.0 * Shipped XML parser is now Xerces 2.4.0


+ 28
- 7
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -67,6 +67,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Reader; import java.io.Reader;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -145,12 +146,24 @@ public class Jar extends Zip {
*/ */
private boolean createEmpty = false; 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 */ /** constructor */
public Jar() { public Jar() {
super(); super();
archiveType = "jar"; archiveType = "jar";
emptyBehavior = "create"; emptyBehavior = "create";
setEncoding("UTF8"); setEncoding("UTF8");
rootEntries = new Vector();
} }


/** /**
@@ -458,6 +471,11 @@ public class Jar extends Zip {
writer.println(dir); writer.println(dir);
} }


enum = rootEntries.elements();
while (enum.hasMoreElements()) {
writer.println(enum.nextElement());
}

writer.flush(); writer.flush();
ByteArrayInputStream bais = ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray()); new ByteArrayInputStream(baos.toByteArray());
@@ -480,6 +498,9 @@ public class Jar extends Zip {
+ " files include a META-INF/INDEX.LIST which will" + " files include a META-INF/INDEX.LIST which will"
+ " be replaced by a newly generated one.", Project.MSG_WARN); + " be replaced by a newly generated one.", Project.MSG_WARN);
} else { } else {
if (index && vPath.indexOf("/") == -1) {
rootEntries.addElement(vPath);
}
super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode); super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
} }
} }
@@ -663,13 +684,13 @@ public class Jar extends Zip {
super.cleanUp(); super.cleanUp();


// we want to save this info if we are going to make another pass // 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();
} }


/** /**


Loading…
Cancel
Save