Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 45869 invoked from network); 27 Jul 2004 14:26:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Jul 2004 14:26:17 -0000 Received: (qmail 35222 invoked by uid 500); 27 Jul 2004 14:25:02 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 35034 invoked by uid 500); 27 Jul 2004 14:25:00 -0000 Mailing-List: contact dev-help@ant.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 dev@ant.apache.org Received: (qmail 34903 invoked by uid 500); 27 Jul 2004 14:24:59 -0000 Received: (qmail 34873 invoked by uid 99); 27 Jul 2004 14:24:59 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 27 Jul 2004 07:24:58 -0700 Received: (qmail 44789 invoked by uid 1146); 27 Jul 2004 14:24:57 -0000 Date: 27 Jul 2004 14:24:57 -0000 Message-ID: <20040727142457.44788.qmail@minotaur.apache.org> From: bodewig@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/testcases/org/apache/tools/ant AntClassLoaderDelegationTest.java AntClassLoaderTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N bodewig 2004/07/27 07:24:57 Modified: src/testcases/org/apache/tools/ant AntClassLoaderTest.java Added: src/testcases/org/apache/tools/ant AntClassLoaderDelegationTest.java Log: new tests fail if the tests themselves live on the system classloader Revision Changes Path 1.9 +0 -52 ant/src/testcases/org/apache/tools/ant/AntClassLoaderTest.java Index: AntClassLoaderTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/AntClassLoaderTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AntClassLoaderTest.java 27 Jul 2004 07:02:06 -0000 1.8 +++ AntClassLoaderTest.java 27 Jul 2004 14:24:57 -0000 1.9 @@ -82,56 +82,4 @@ fail("loader should not fail even if project finished"); } } - - /** Sample resource present in build/testcases/ */ - private static final String TEST_RESOURCE = "org/apache/tools/ant/IncludeTest.class"; - - public void testFindResources() throws Exception { - //System.err.println("loading from: " + AntClassLoader.class.getProtectionDomain().getCodeSource().getLocation()); - // See bug #30161. - // This path should contain the class files for these testcases: - String buildTestcases = System.getProperty("build.tests"); - assertNotNull("defined ${build.tests}", buildTestcases); - assertTrue("have a dir " + buildTestcases, new File(buildTestcases).isDirectory()); - Path path = new Path(p, buildTestcases); - // A special parent loader which is not the system class loader: - ClassLoader parent = new ParentLoader(); - // An AntClassLoader which is supposed to delegate to the parent and then to the disk path: - ClassLoader acl = new AntClassLoader(parent, p, path, true); - // The intended result URLs: - URL urlFromPath = new URL(FileUtils.newFileUtils().toURI(buildTestcases) + TEST_RESOURCE); - URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE); - assertEquals("correct resources (regular delegation order)", - Arrays.asList(new URL[] {urlFromParent, urlFromPath}), - enum2List(acl.getResources(TEST_RESOURCE))); - acl = new AntClassLoader(parent, p, path, false); - assertEquals("correct resources (reverse delegation order)", - Arrays.asList(new URL[] {urlFromPath, urlFromParent}), - enum2List(acl.getResources(TEST_RESOURCE))); - } - - private static List enum2List(Enumeration e) { - // JDK 1.4: return Collections.list(e); - List l = new ArrayList(); - while (e.hasMoreElements()) { - l.add(e.nextElement()); - } - return l; - } - - /** Special loader that just knows how to find TEST_RESOURCE. */ - private static final class ParentLoader extends ClassLoader { - - public ParentLoader() {} - - protected Enumeration findResources(String name) throws IOException { - if (name.equals(TEST_RESOURCE)) { - return Collections.enumeration(Collections.singleton(new URL("http://ant.apache.org/" + name))); - } else { - return Collections.enumeration(Collections.EMPTY_SET); - } - } - - } - } 1.1 ant/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java Index: AntClassLoaderDelegationTest.java =================================================================== /* * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.apache.tools.ant; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.List; import junit.framework.TestCase; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.FileUtils; /** * Test case for ant class loader * */ public class AntClassLoaderDelegationTest extends TestCase { private Project p; public AntClassLoaderDelegationTest(String name) { super(name); } public void setUp() { p = new Project(); p.init(); } /** Sample resource present in build/testcases/ */ private static final String TEST_RESOURCE = "org/apache/tools/ant/IncludeTest.class"; public void testFindResources() throws Exception { //System.err.println("loading from: " + AntClassLoader.class.getProtectionDomain().getCodeSource().getLocation()); // See bug #30161. // This path should contain the class files for these testcases: String buildTestcases = System.getProperty("build.tests"); assertNotNull("defined ${build.tests}", buildTestcases); assertTrue("have a dir " + buildTestcases, new File(buildTestcases).isDirectory()); Path path = new Path(p, buildTestcases); // A special parent loader which is not the system class loader: ClassLoader parent = new ParentLoader(); // An AntClassLoader which is supposed to delegate to the parent and then to the disk path: ClassLoader acl = new AntClassLoader(parent, p, path, true); // The intended result URLs: URL urlFromPath = new URL(FileUtils.newFileUtils().toURI(buildTestcases) + TEST_RESOURCE); URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE); assertEquals("correct resources (regular delegation order)", Arrays.asList(new URL[] {urlFromParent, urlFromPath}), enum2List(acl.getResources(TEST_RESOURCE))); acl = new AntClassLoader(parent, p, path, false); assertEquals("correct resources (reverse delegation order)", Arrays.asList(new URL[] {urlFromPath, urlFromParent}), enum2List(acl.getResources(TEST_RESOURCE))); } private static List enum2List(Enumeration e) { // JDK 1.4: return Collections.list(e); List l = new ArrayList(); while (e.hasMoreElements()) { l.add(e.nextElement()); } return l; } /** Special loader that just knows how to find TEST_RESOURCE. */ private static final class ParentLoader extends ClassLoader { public ParentLoader() {} protected Enumeration findResources(String name) throws IOException { if (name.equals(TEST_RESOURCE)) { return Collections.enumeration(Collections.singleton(new URL("http://ant.apache.org/" + name))); } else { return Collections.enumeration(Collections.EMPTY_SET); } } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org