git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277015 13f79535-47bb-0310-9956-ffa450edef68master
@@ -14,14 +14,24 @@ | |||||
<p>This task can be used to write a Manifest file, optionally | <p>This task can be used to write a Manifest file, optionally | ||||
replacing or updating an existing file.</p> | replacing or updating an existing file.</p> | ||||
<p> | |||||
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. | |||||
</p> | |||||
<p>Manifests are processed according to the | <p>Manifests are processed according to the | ||||
<a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html">Jar | |||||
<a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html">Jar | |||||
file specification.</a>. Specifically, a manifest element consists of | file specification.</a>. Specifically, a manifest element consists of | ||||
a set of attributes and sections. These sections in turn may contain | a set of attributes and sections. These sections in turn may contain | ||||
attributes. Note in particular that this may result in manifest lines | attributes. Note in particular that this may result in manifest lines | ||||
greater than 72 bytes being wrapped and continued on the next | greater than 72 bytes being wrapped and continued on the next | ||||
line.</p> | line.</p> | ||||
<h3>Parameters</h3> | <h3>Parameters</h3> | ||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
@@ -202,6 +202,17 @@ | |||||
</manifest> | </manifest> | ||||
</target> | </target> | ||||
<target name="testFrom"> | |||||
<manifest file="mftestfrom.mf" > | |||||
<section name="Test"> | |||||
<attribute name="before" value="before" /> | |||||
<attribute name="From" value="illegal"/> | |||||
<attribute name="after" value="after" /> | |||||
</section> | |||||
</manifest> | |||||
</target> | |||||
<target name="clean"> | <target name="clean"> | ||||
<delete> | <delete> | ||||
<fileset dir="." includes="mftest*"/> | <fileset dir="." includes="mftest*"/> | ||||
@@ -79,6 +79,8 @@ public class Manifest { | |||||
/** The End-Of-Line marker in manifests */ | /** The End-Of-Line marker in manifests */ | ||||
public static final String EOL = "\r\n"; | 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. | * An attribute for the manifest. | ||||
@@ -566,8 +568,7 @@ public class Manifest { | |||||
} | } | ||||
if (attribute.getKey().startsWith(ATTRIBUTE_FROM.toLowerCase())) { | 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() + "\""); | + attribute.getName() + ": " + attribute.getValue() + "\""); | ||||
} else { | } else { | ||||
// classpath attributes go into a vector | // classpath attributes go into a vector | ||||
@@ -24,9 +24,12 @@ import java.io.FileOutputStream; | |||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
import java.util.Enumeration; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.util.FileUtils; | |||||
import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
/** | /** | ||||
@@ -163,16 +166,16 @@ public class ManifestTask extends Task { | |||||
error = new BuildException("Failed to read " + manifestFile, | error = new BuildException("Failed to read " + manifestFile, | ||||
e, getLocation()); | e, getLocation()); | ||||
} finally { | } 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 { | try { | ||||
if (mode.getValue().equals("update") && manifestFile.exists()) { | if (mode.getValue().equals("update") && manifestFile.exists()) { | ||||
if (current != null) { | if (current != null) { | ||||
@@ -116,7 +116,7 @@ public class ManifestTest extends BuildFileTest { | |||||
public void test7() { | public void test7() { | ||||
executeTarget("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); | assertEquals("Expected warning about From: attribute", true, hasWarning); | ||||
} | } | ||||
@@ -286,6 +286,10 @@ public class ManifestTest extends BuildFileTest { | |||||
assertTrue(mfAsString.indexOf("Foo: Baz") > -1); | assertTrue(mfAsString.indexOf("Foo: Baz") > -1); | ||||
} | } | ||||
public void testFrom() { | |||||
expectLogContaining("testFrom", Manifest.ERROR_FROM_FORBIDDEN); | |||||
} | |||||
/** | /** | ||||
* Reads mftest.mf. | * Reads mftest.mf. | ||||
*/ | */ | ||||