conor 01/11/15 05:33:26
Modified: src/etc/testcases/taskdefs manifest.xml
src/main/org/apache/tools/ant/taskdefs Manifest.java
src/testcases/org/apache/tools/ant BuildFileTest.java
src/testcases/org/apache/tools/ant/taskdefs
ManifestTest.java
Added: src/etc/testcases/taskdefs/manifests test6.mf test7.mf
Log:
Added more tests for Manifests
Fixed problem with multiple class-path attributes. Hopefully Sun will
update their spec sometime.
PR: 4683
Revision Changes Path
1.2 +76 -0 jakarta-ant/src/etc/testcases/taskdefs/manifest.xml
Index: manifest.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/manifest.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- manifest.xml 2001/11/14 13:40:53 1.1
+++ manifest.xml 2001/11/15 13:33:25 1.2
@@ -24,6 +24,82 @@
<jar file="mftest5.jar" manifest="manifests/test5.mf"/>
</target>
+ <target name="test6">
+ <jar file="mftest6.jar" manifest="manifests/test6.mf"/>
+ </target>
+
+ <target name="test7">
+ <jar file="mftest7.jar" manifest="manifests/test7.mf"/>
+ </target>
+
+ <target name="test8">
+ <jar file="mftest8.jar">
+ <manifest>
+ <attribute name="Class-Path" value="fubar"/>
+ <section name="Test">
+ <attribute name="TestAttr" value="Test"/>
+ </section>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test9">
+ <jar file="mftest9.jar">
+ <manifest>
+ <attribute name="Class-Path" value="fubar"/>
+ <section name="Test">
+ <attribute name="Name" value="Test"/>
+ </section>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test10">
+ <jar file="mftest10.jar">
+ <manifest>
+ <attribute value="fubar"/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test11">
+ <jar file="mftest11.jar">
+ <manifest>
+ <attribute name="Test"/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test12">
+ <jar file="mftest12.jar">
+ <manifest>
+ <section>
+ <attribute name="TestAttr" value="Test"/>
+ </section>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test13">
+ <jar file="mftest13.jar">
+ <manifest>
+ <attribute name="Test" value="Test1"/>
+ <attribute name="Test" value="Test2"/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="test14">
+ <jar file="mftest14.jar">
+ <manifest>
+ <attribute name="Class-path" value="Test1"/>
+ <attribute name="Class-path" value="Test2"/>
+ <attribute name="Class-Path" value="Test3"/>
+ <attribute name="class-Path" value="Test4"/>
+ </manifest>
+ </jar>
+ </target>
+
<target name="clean">
<delete>
<fileset dir="." includes="mftest*.jar"/>
1.1 jakarta-ant/src/etc/testcases/taskdefs/manifests/test6.mf
Index: test6.mf
===================================================================
Manifest-Version: 1.0
Test: test6
Class-Path: fubar
1.1 jakarta-ant/src/etc/testcases/taskdefs/manifests/test7.mf
Index: test7.mf
===================================================================
Manifest-Version: 1.0
Class-Path: fubar
From: Jack
1.9 +58 -12
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java
Index: Manifest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -u -r1.8 -r1.9
--- Manifest.java 2001/11/14 13:40:53 1.8
+++ Manifest.java 2001/11/15 13:33:25 1.9
@@ -81,9 +81,12 @@
/** The Name Attribute is the first in a named section */
public final static String ATTRIBUTE_NAME = "Name";
- /** THe From Header is disallowed in a Manifest */
+ /** The From Header is disallowed in a Manifest */
public final static String ATTRIBUTE_FROM = "From";
+ /** The Class-Path Header is special - it can be duplicated */
+ public final static String ATTRIBUTE_CLASSPATH = "class-path";
+
/** Default Manifest version if one is not specified */
public final static String DEFAULT_MANIFEST_VERSION = "1.0";
@@ -321,9 +324,20 @@
for (Enumeration e = section.attributes.keys();
e.hasMoreElements();) {
String attributeName = (String)e.nextElement();
+ if (attributeName.equals(ATTRIBUTE_CLASSPATH) &&
+ attributes.containsKey(attributeName)) {
+ // classpath entries are vetors which are merged
+ Vector classpathAttrs =
(Vector)section.attributes.get(attributeName);
+ Vector ourClasspathAttrs =
(Vector)attributes.get(attributeName);
+ for (Enumeration e2 = classpathAttrs.elements();
e2.hasMoreElements();) {
+ ourClasspathAttrs.addElement(e2.nextElement());
+ }
+ }
+ else {
// the merge file always wins
attributes.put(attributeName,
section.attributes.get(attributeName));
}
+ }
// add in the warnings
for (Enumeration e = section.warnings.elements();
e.hasMoreElements();) {
@@ -344,9 +358,19 @@
nameAttr.write(writer);
}
for (Enumeration e = attributes.elements();
e.hasMoreElements();) {
- Attribute attribute = (Attribute)e.nextElement();
+ Object object = e.nextElement();
+ if (object instanceof Attribute) {
+ Attribute attribute = (Attribute)object;
attribute.write(writer);
}
+ else {
+ Vector attrList = (Vector)object;
+ for (Enumeration e2 = attrList.elements();
e2.hasMoreElements();) {
+ Attribute attribute = (Attribute)e2.nextElement();
+ attribute.write(writer);
+ }
+ }
+ }
writer.println();
}
@@ -359,11 +383,21 @@
* in the section
*/
public String getAttributeValue(String attributeName) {
- Attribute attribute =
(Attribute)attributes.get(attributeName.toLowerCase());
+ Object attribute = attributes.get(attributeName.toLowerCase());
if (attribute == null) {
return null;
}
- return attribute.getValue();
+ if (attribute instanceof Attribute) {
+ return ((Attribute)attribute).getValue();
+ }
+ else {
+ String value = "";
+ for (Enumeration e = ((Vector)attribute).elements();
e.hasMoreElements();) {
+ Attribute classpathAttribute =
(Attribute)e.nextElement();
+ value += classpathAttribute.getValue() + " ";
+ }
+ return value.trim();
+ }
}
/**
@@ -407,12 +441,24 @@
warnings.addElement("Manifest attributes should not start
with \"" +
ATTRIBUTE_FROM + "\" in \""
+attribute.getName() + ": " + attribute.getValue() + "\"");
}
- else if
(attributes.containsKey(attribute.getName().toLowerCase())) {
+ else {
+ // classpath attributes go into a vector
+ String attributeName = attribute.getName().toLowerCase();
+ if (attributeName.equals(ATTRIBUTE_CLASSPATH)) {
+ Vector classpathAttrs =
(Vector)attributes.get(attributeName);
+ if (classpathAttrs == null) {
+ classpathAttrs = new Vector();
+ attributes.put(attributeName, classpathAttrs);
+ }
+ classpathAttrs.addElement(attribute);
+ }
+ else if (attributes.containsKey(attributeName)) {
throw new ManifestException("The attribute \"" +
attribute.getName() + "\" may not " +
"occur more than once in the
same section");
}
else {
- attributes.put(attribute.getName().toLowerCase(), attribute);
+ attributes.put(attributeName, attribute);
+ }
}
return null;
}
1.4 +1 -1
jakarta-ant/src/testcases/org/apache/tools/ant/BuildFileTest.java
Index: BuildFileTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/BuildFileTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
1.2 +79 -2
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java
Index: ManifestTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- ManifestTest.java 2001/11/14 13:40:53 1.1
+++ ManifestTest.java 2001/11/15 13:33:26 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -116,4 +116,81 @@
boolean hasWarning = output.indexOf("Manifest warning: \"Name\"
attributes should not occur in the main section") != -1;
assertEquals("Expected warning about Name in main section", true,
hasWarning);
}
+
+ /**
+ * New Section not starting with Name attribute.
+ */
+ public void test6() {
+ expectBuildExceptionContaining("test6", "Manifest is invalid -
section starts with incorrect attribute",
+ "Invalid Manifest");
+ String output = getLog();
+ boolean hasWarning = output.indexOf("Manifest sections should start
with a \"Name\" attribute") != -1;
+ assertEquals("Expected warning about section not starting with Name:
attribute", true, hasWarning);
+ }
+
+ /**
+ * From attribute is illegal
+ */
+ public void test7() {
+ executeTarget("test7");
+
+ boolean hasWarning = getLog().indexOf("Manifest attributes should
not start with \"From\"") != -1;
+ assertEquals("Expected warning about From: attribute", true,
hasWarning);
+ }
+
+ /**
+ * Inline manifest - OK
+ */
+ public void test8() {
+ executeTarget("test8");
+ }
+
+ /**
+ * Inline manifest - Invalid since has a Name attribute in the section
element
+ */
+ public void test9() {
+ expectBuildExceptionContaining("test9", "Construction is invalid -
Name attribute should not be used",
+ "Specify the section name using the
\"name\" attribute of the <section> element");
+ }
+
+ /**
+ * Inline manifest - Invalid attribute without name
+ */
+ public void test10() {
+ expectBuildExceptionContaining("test10", "Attribute has no name",
+ "Attributes must have name and
value");
+ }
+
+ /**
+ * Inline manifest - Invalid attribute without value
+ */
+ public void test11() {
+ expectBuildExceptionContaining("test11", "Attribute has no value",
+ "Attributes must have name and
value");
+ }
+
+ /**
+ * Inline manifest - Invalid attribute without value
+ */
+ public void test12() {
+ expectBuildExceptionContaining("test12", "Section with no name",
+ "Sections must have a name");
+ }
+
+ /**
+ * Inline manifest - Duplicate attribute
+ */
+ public void test13() {
+ expectBuildExceptionContaining("test13", "Duplicate Attribute",
+ "The attribute \"Test\" may not occur
more than once in the same section");
+ }
+
+ /**
+ * Inline manifest - OK since classpath entries can be duplicated.
+ */
+ public void test14() {
+ executeTarget("test14");
+ }
+
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>