Browse Source

Manifest task logs warnings: PR32190

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277015 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 20 years ago
parent
commit
c8d28da5f8
5 changed files with 40 additions and 11 deletions
  1. +11
    -1
      docs/manual/CoreTasks/manifest.html
  2. +11
    -0
      src/etc/testcases/taskdefs/manifest.xml
  3. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/Manifest.java
  4. +10
    -7
      src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
  5. +5
    -1
      src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java

+ 11
- 1
docs/manual/CoreTasks/manifest.html View File

@@ -14,14 +14,24 @@
<p>This task can be used to write a Manifest file, optionally
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
<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
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.</p>


<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>


+ 11
- 0
src/etc/testcases/taskdefs/manifest.xml View File

@@ -202,6 +202,17 @@
</manifest>
</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">
<delete>
<fileset dir="." includes="mftest*"/>


+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/Manifest.java View File

@@ -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


+ 10
- 7
src/main/org/apache/tools/ant/taskdefs/ManifestTask.java View File

@@ -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) {


+ 5
- 1
src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -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.
*/


Loading…
Cancel
Save