conor 01/09/13 05:17:18
Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_14_BRANCH
Jar.java
Log:
Fix up Jars so that the first two entries are always the META-INF directory
and the manifest itself. This is not really documented as a Jar requirement
that I am aware of but the JarInputStream code certainly requires this.
PR: 3287
Revision Changes Path
No revision
No revision
1.21.2.3 +24 -50
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
Index: Jar.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
retrieving revision 1.21.2.2
retrieving revision 1.21.2.3
diff -u -w -u -r1.21.2.2 -r1.21.2.3
--- Jar.java 2001/08/10 06:11:42 1.21.2.2
+++ Jar.java 2001/09/13 12:17:18 1.21.2.3
@@ -140,15 +140,24 @@
throws IOException, BuildException
{
try {
- // If no manifest is specified, add the default one.
- if (manifest == null) {
- execManifest = null;
- }
- else {
- execManifest = new Manifest();
+ execManifest = getDefaultManifest();
+
+ if (manifest != null) {
execManifest.merge(manifest);
}
+ for (Enumeration e = execManifest.getWarnings();
e.hasMoreElements(); ) {
+ log("Manifest warning: " + (String)e.nextElement(),
Project.MSG_WARN);
+ }
+
zipDir(null, zOut, "META-INF/");
+ // time to write the manifest
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter(baos);
+ execManifest.write(writer);
+ writer.flush();
+
+ ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
+ super.zipFile(bais, zOut, "META-INF/MANIFEST.MF",
System.currentTimeMillis());
super.initZipOutputStream(zOut);
}
catch (ManifestException e) {
@@ -174,28 +183,6 @@
}
}
- protected void finalizeZipOutputStream(ZipOutputStream zOut)
- throws IOException, BuildException {
-
- if (execManifest == null) {
- execManifest = getDefaultManifest();
- }
-
- for (Enumeration e = execManifest.getWarnings();
e.hasMoreElements(); ) {
- log("Manifest warning: " + (String)e.nextElement(),
Project.MSG_WARN);
- }
-
- // time to write the manifest
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintWriter writer = new PrintWriter(baos);
- execManifest.write(writer);
- writer.flush();
-
- ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
- super.zipFile(bais, zOut, "META-INF/MANIFEST.MF",
System.currentTimeMillis());
- super.finalizeZipOutputStream(zOut);
- }
-
/**
* Handle situation when we encounter a manifest file
*
@@ -222,30 +209,17 @@
protected void zipFile(File file, ZipOutputStream zOut, String vPath)
throws IOException
{
- // If the file being added is META-INF/MANIFEST.MF, we merge it with
the
- // current manifest
+ // If the file being added is META-INF/MANIFEST.MF, we warn if it's
not the
+ // one specified in the "manifest" attribute - or if it's being
added twice,
+ // meaning the same file is specified by the "manifeset" attribute
and in
+ // a <fileset> element.
if (vPath.equalsIgnoreCase("META-INF/MANIFEST.MF")) {
- InputStream is = null;
- try {
- is = new FileInputStream(file);
- zipManifestEntry(is);
- }
- catch (IOException e) {
- throw new BuildException("Unable to read manifest file: " +
file, e);
- }
- finally {
- if (is != null) {
- try {
- is.close();
- }
- catch (IOException e) {
- // do nothing
- }
- }
- }
+ log("Warning: selected "+archiveType+" files include a
META-INF/MANIFEST.MF which will be ignored " +
+ "(please use manifest attribute to "+archiveType+" task)",
Project.MSG_WARN);
} else {
super.zipFile(file, zOut, vPath);
}
+
}
protected void zipFile(InputStream is, ZipOutputStream zOut, String
vPath, long lastModified)