Class-Path entries. More to come. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269912 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,32 @@ | |||||
<?xml version="1.0"?> | |||||
<!-- Manifest tests build file | |||||
author: Conor MacNeill --> | |||||
<project name="manifest-test" basedir="." default="test1"> | |||||
<target name="test1"> | |||||
<jar file="mftest1.jar" manifest="manifests/test1.mf"/> | |||||
</target> | |||||
<target name="test2"> | |||||
<jar file="mftest2.jar" manifest="manifests/test2.mf"/> | |||||
</target> | |||||
<target name="test3"> | |||||
<jar file="mftest3.jar" manifest="manifests/test3.mf"/> | |||||
</target> | |||||
<target name="test4"> | |||||
<jar file="mftest4.jar" manifest="manifests/test4.mf"/> | |||||
</target> | |||||
<target name="test5"> | |||||
<jar file="mftest5.jar" manifest="manifests/test5.mf"/> | |||||
</target> | |||||
<target name="clean"> | |||||
<delete> | |||||
<fileset dir="." includes="mftest*.jar"/> | |||||
</delete> | |||||
</target> | |||||
</project> |
@@ -0,0 +1 @@ | |||||
@@ -0,0 +1,2 @@ | |||||
Manifest-Version: 2.0 | |||||
@@ -0,0 +1,3 @@ | |||||
Manifest-Version: 1.0 | |||||
Header-without-colon maybe mistyped | |||||
@@ -0,0 +1,4 @@ | |||||
Manifest-Version: 1.0 | |||||
Can't start with a continuation line | |||||
@@ -0,0 +1,3 @@ | |||||
Manifest-Version: 1.0 | |||||
Name: test5 | |||||
@@ -149,7 +149,8 @@ public class Manifest { | |||||
public void parse(String line) throws ManifestException { | public void parse(String line) throws ManifestException { | ||||
int index = line.indexOf(": "); | int index = line.indexOf(": "); | ||||
if (index == -1) { | 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); | name = line.substring(0, index); | ||||
value = line.substring(index + 2); | value = line.substring(index + 2); | ||||
@@ -377,8 +378,8 @@ public class Manifest { | |||||
public void addConfiguredAttribute(Attribute attribute) throws ManifestException { | public void addConfiguredAttribute(Attribute attribute) throws ManifestException { | ||||
String check = addAttributeAndCheck(attribute); | String check = addAttributeAndCheck(attribute); | ||||
if (check != null) { | if (check != null) { | ||||
throw new BuildException("Use the \"name\" attribute of the <section> element rather than using " + | |||||
"the \"Name\" attribute"); | |||||
throw new BuildException("Specify the section name using the \"name\" attribute of the <section> element rather " + | |||||
"than using a \"Name\" manifest attribute"); | |||||
} | } | ||||
} | } | ||||
@@ -200,13 +200,26 @@ public abstract class BuildFileTest extends TestCase { | |||||
try { | try { | ||||
executeTarget(target); | executeTarget(target); | ||||
} catch (org.apache.tools.ant.BuildException ex) { | } 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; | return; | ||||
} | } | ||||
fail("Should throw BuildException because: " + cause); | 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 { | private class AntOutputStream extends java.io.OutputStream { | ||||
public void write(int b) { | public void write(int b) { | ||||
outBuffer.append((char)b); | outBuffer.append((char)b); | ||||
@@ -79,7 +79,7 @@ public class JarTest extends BuildFileTest { | |||||
} | } | ||||
public void test2() { | public void test2() { | ||||
expectBuildException("test2", "manifect file does not exist"); | |||||
expectBuildException("test2", "manifest file does not exist"); | |||||
} | } | ||||
public void test3() { | public void test3() { | ||||
@@ -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 | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
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 <conor@apache.org> | |||||
*/ | |||||
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); | |||||
} | |||||
} |