diff --git a/src/etc/testcases/taskdefs/manifest.xml b/src/etc/testcases/taskdefs/manifest.xml new file mode 100644 index 000000000..844766698 --- /dev/null +++ b/src/etc/testcases/taskdefs/manifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/etc/testcases/taskdefs/manifests/test1.mf b/src/etc/testcases/taskdefs/manifests/test1.mf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/etc/testcases/taskdefs/manifests/test1.mf @@ -0,0 +1 @@ + diff --git a/src/etc/testcases/taskdefs/manifests/test2.mf b/src/etc/testcases/taskdefs/manifests/test2.mf new file mode 100644 index 000000000..b8a88bd3f --- /dev/null +++ b/src/etc/testcases/taskdefs/manifests/test2.mf @@ -0,0 +1,2 @@ +Manifest-Version: 2.0 + diff --git a/src/etc/testcases/taskdefs/manifests/test3.mf b/src/etc/testcases/taskdefs/manifests/test3.mf new file mode 100644 index 000000000..6aa82ccaa --- /dev/null +++ b/src/etc/testcases/taskdefs/manifests/test3.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Header-without-colon maybe mistyped + diff --git a/src/etc/testcases/taskdefs/manifests/test4.mf b/src/etc/testcases/taskdefs/manifests/test4.mf new file mode 100644 index 000000000..27afb1890 --- /dev/null +++ b/src/etc/testcases/taskdefs/manifests/test4.mf @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 + + Can't start with a continuation line + diff --git a/src/etc/testcases/taskdefs/manifests/test5.mf b/src/etc/testcases/taskdefs/manifests/test5.mf new file mode 100644 index 000000000..0fb8deae4 --- /dev/null +++ b/src/etc/testcases/taskdefs/manifests/test5.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Name: test5 + diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index b75b38cc2..697724390 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -149,7 +149,8 @@ public class Manifest { public void parse(String line) throws ManifestException { int index = line.indexOf(": "); if (index == -1) { - throw new ManifestException("Manifest line \"" + line + "\" is not valid"); + throw new ManifestException("Manifest line \"" + line + "\" is not valid as it does not " + + "contain a name and a value separated by ': ' "); } name = line.substring(0, index); value = line.substring(index + 2); @@ -377,8 +378,8 @@ public class Manifest { public void addConfiguredAttribute(Attribute attribute) throws ManifestException { String check = addAttributeAndCheck(attribute); if (check != null) { - throw new BuildException("Use the \"name\" attribute of the
element rather than using " + - "the \"Name\" attribute"); + throw new BuildException("Specify the section name using the \"name\" attribute of the
element rather " + + "than using a \"Name\" manifest attribute"); } } diff --git a/src/testcases/org/apache/tools/ant/BuildFileTest.java b/src/testcases/org/apache/tools/ant/BuildFileTest.java index 930f9c55e..26d89989e 100644 --- a/src/testcases/org/apache/tools/ant/BuildFileTest.java +++ b/src/testcases/org/apache/tools/ant/BuildFileTest.java @@ -200,13 +200,26 @@ public abstract class BuildFileTest extends TestCase { try { executeTarget(target); } catch (org.apache.tools.ant.BuildException ex) { - if ((null != msg) && (ex.getMessage() != msg)) { - fail("Should throw BuildException because '" + cause + "' with message '" + msg + "' (received message '" + ex.getMessage() + "' instead)"); + if ((null != msg) && (!ex.getMessage().equals(msg))) { + fail("Should throw BuildException because '" + cause + "' with message '" + msg + "' (actual message '" + ex.getMessage() + "' instead)"); } return; } fail("Should throw BuildException because: " + cause); } + + protected void expectBuildExceptionContaining(String target, String cause, String contains) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) { + fail("Should throw BuildException because '" + cause + "' with message containing'" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + private class AntOutputStream extends java.io.OutputStream { public void write(int b) { outBuffer.append((char)b); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java index 863d06841..9350725bb 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java @@ -79,7 +79,7 @@ public class JarTest extends BuildFileTest { } public void test2() { - expectBuildException("test2", "manifect file does not exist"); + expectBuildException("test2", "manifest file does not exist"); } public void test3() { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java new file mode 100644 index 000000000..ec96fb481 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -0,0 +1,119 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.util.Date; +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for the Manifest class used in the jar task. + * + * @author Conor MacNeill + */ +public class ManifestTest extends BuildFileTest { + + public ManifestTest(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/taskdefs/manifest.xml"); + } + + public void tearDown() { + executeTarget("clean"); + } + + /** + * Empty manifest - is OK + */ + public void test1() { + executeTarget("test1"); + } + + /** + * Simple Manifest with version 2.0 + */ + public void test2() { + executeTarget("test2"); + } + + /** + * Malformed manifest - no : on the line + */ + public void test3() { + expectBuildExceptionContaining("test3", "Manifest is invalid - no colon on header line", + "Invalid Manifest"); + } + + /** + * Malformed manifest - starts with continuation line + */ + public void test4() { + expectBuildExceptionContaining("test4", "Manifest is invalid - section starts with continuation line", + "Invalid Manifest"); + } + + /** + * Malformed manifest - Name attribute in main section + */ + public void test5() { + executeTarget("test5"); + String output = getLog(); + 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); + } +}