Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 65025 invoked from network); 15 Nov 2001 13:47:11 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 15 Nov 2001 13:47:11 -0000 Received: (qmail 3514 invoked by uid 97); 15 Nov 2001 13:47:06 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 3497 invoked by uid 97); 15 Nov 2001 13:47:05 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 3486 invoked by uid 97); 15 Nov 2001 13:47:05 -0000 Date: 15 Nov 2001 13:33:26 -0000 Message-ID: <20011115133326.92910.qmail@icarus.apache.org> From: conor@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs ManifestTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 @@ + + + + + + + + + + + + +
+ +
+
+
+
+ + + + + +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + 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
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: For additional commands, e-mail: