diff --git a/docs/manual/CoreTasks/manifest.html b/docs/manual/CoreTasks/manifest.html index 17e78db0e..cfb5e8122 100644 --- a/docs/manual/CoreTasks/manifest.html +++ b/docs/manual/CoreTasks/manifest.html @@ -14,14 +14,24 @@

This task can be used to write a Manifest file, optionally replacing or updating an existing file.

+

+The Ant team regularly gets complaints that this task in generating invalid +manifests. By and large, this is not the case: we believe that we are following +the specification to the letter. The usual problem is that some third party +manifest reader is not following the same specification as well as they think +they should; we cannot generate invalid manifest files just because one +single application is broken. +

+

Manifests are processed according to the -Jar +Jar file specification.. Specifically, a manifest element consists of a set of attributes and sections. These sections in turn may contain attributes. Note in particular that this may result in manifest lines greater than 72 bytes being wrapped and continued on the next line.

+

Parameters

diff --git a/src/etc/testcases/taskdefs/manifest.xml b/src/etc/testcases/taskdefs/manifest.xml index 4c86fcada..34f23168c 100644 --- a/src/etc/testcases/taskdefs/manifest.xml +++ b/src/etc/testcases/taskdefs/manifest.xml @@ -202,6 +202,17 @@ + + + +
+ + + +
+
+
+ diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index e1d8af480..9d7f00711 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -79,6 +79,8 @@ public class Manifest { /** The End-Of-Line marker in manifests */ public static final String EOL = "\r\n"; + public static final String ERROR_FROM_FORBIDDEN = "Manifest attributes should not start " + + "with \"" + ATTRIBUTE_FROM + "\" in \""; /** * An attribute for the manifest. @@ -566,8 +568,7 @@ public class Manifest { } if (attribute.getKey().startsWith(ATTRIBUTE_FROM.toLowerCase())) { - warnings.addElement("Manifest attributes should not start " - + "with \"" + ATTRIBUTE_FROM + "\" in \"" + warnings.addElement(ERROR_FROM_FORBIDDEN + attribute.getName() + ": " + attribute.getValue() + "\""); } else { // classpath attributes go into a vector diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java index 730b07475..c6cc02d7f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java @@ -24,9 +24,12 @@ import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Enumeration; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.types.EnumeratedAttribute; /** @@ -163,16 +166,16 @@ public class ManifestTask extends Task { error = new BuildException("Failed to read " + manifestFile, e, getLocation()); } finally { - if (isr != null) { - try { - isr.close(); - } catch (IOException e) { - // ignore - } - } + FileUtils.close(isr); } } + //look for and print warnings + for (Enumeration e = nestedManifest.getWarnings(); + e.hasMoreElements();) { + log("Manifest warning: " + (String) e.nextElement(), + Project.MSG_WARN); + } try { if (mode.getValue().equals("update") && manifestFile.exists()) { if (current != null) { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java index 2bf900563..fa45d40b3 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -116,7 +116,7 @@ public class ManifestTest extends BuildFileTest { public void test7() { executeTarget("test7"); - boolean hasWarning = getLog().indexOf("Manifest attributes should not start with \"From\"") != -1; + boolean hasWarning = getLog().indexOf(Manifest.ERROR_FROM_FORBIDDEN) != -1; assertEquals("Expected warning about From: attribute", true, hasWarning); } @@ -286,6 +286,10 @@ public class ManifestTest extends BuildFileTest { assertTrue(mfAsString.indexOf("Foo: Baz") > -1); } + public void testFrom() { + expectLogContaining("testFrom", Manifest.ERROR_FROM_FORBIDDEN); + } + /** * Reads mftest.mf. */