001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant;
020:
021: import java.io.File;
022: import org.apache.tools.ant.types.Path;
023:
024: /**
025: * Test case for ant class loader
026: *
027: */
028: public class AntClassLoaderTest extends BuildFileTest {
029:
030: private Project p;
031:
032: public AntClassLoaderTest(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: p = new Project();
038: p.init();
039: configureProject("src/etc/testcases/core/antclassloader.xml");
040: getProject().executeTarget("setup");
041: }
042:
043: public void tearDown() {
044: getProject().executeTarget("cleanup");
045: }
046:
047: //test inspired by bug report 37085
048: public void testJarWithManifestInDirWithSpace() {
049: String mainjarstring = getProject().getProperty("main.jar");
050: String extjarstring = getProject().getProperty("ext.jar");
051: Path myPath = new Path(getProject());
052: myPath.setLocation(new File(mainjarstring));
053: getProject().setUserProperty("build.sysclasspath", "ignore");
054: AntClassLoader myLoader = getProject()
055: .createClassLoader(myPath);
056: String path = myLoader.getClasspath();
057: assertEquals(mainjarstring + File.pathSeparator + extjarstring,
058: path);
059: }
060:
061: public void testJarWithManifestInNonAsciiDir() {
062: String mainjarstring = getProject().getProperty(
063: "main.jar.nonascii");
064: String extjarstring = getProject().getProperty(
065: "ext.jar.nonascii");
066: Path myPath = new Path(getProject());
067: myPath.setLocation(new File(mainjarstring));
068: getProject().setUserProperty("build.sysclasspath", "ignore");
069: AntClassLoader myLoader = getProject()
070: .createClassLoader(myPath);
071: String path = myLoader.getClasspath();
072: assertEquals(mainjarstring + File.pathSeparator + extjarstring,
073: path);
074: }
075:
076: public void testCleanup() throws BuildException {
077: Path path = new Path(p, ".");
078: AntClassLoader loader = p.createClassLoader(path);
079: try {
080: // we don't expect to find this
081: loader.findClass("fubar");
082: fail("Did not expect to find fubar class");
083: } catch (ClassNotFoundException e) {
084: // ignore expected
085: }
086:
087: loader.cleanup();
088: try {
089: // we don't expect to find this
090: loader.findClass("fubar");
091: fail("Did not expect to find fubar class");
092: } catch (ClassNotFoundException e) {
093: // ignore expected
094: } catch (NullPointerException e) {
095: fail("loader should not fail even if cleaned up");
096: }
097:
098: // tell the build it is finished
099: p.fireBuildFinished(null);
100: try {
101: // we don't expect to find this
102: loader.findClass("fubar");
103: fail("Did not expect to find fubar class");
104: } catch (ClassNotFoundException e) {
105: // ignore expected
106: } catch (NullPointerException e) {
107: fail("loader should not fail even if project finished");
108: }
109: }
110: }
|