From c02f98b7e6f5917c966656460ac2298635bb3db3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 28 Oct 2011 09:48:59 -0700 Subject: [PATCH] More classpath mucking about in Sfl4jTestJarsRunner --- .../jetty/util/log/Slf4jTestJarsRunner.java | 96 ++++++++----------- 1 file changed, 41 insertions(+), 55 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jTestJarsRunner.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jTestJarsRunner.java index f8469236360..d59ef7f69d2 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jTestJarsRunner.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jTestJarsRunner.java @@ -24,63 +24,49 @@ public class Slf4jTestJarsRunner extends BlockJUnit4ClassRunner { private static class Slf4jTestClassLoader extends URLClassLoader { + private ClassLoader parent; + public Slf4jTestClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); + super(urls,parent); + this.parent = parent; } - @Override - protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException - { - System.err.printf("[slf4j.cl] loadClass(%s)%n", name); - - ClassNotFoundException ex= null; - Class c = null; - try - { - c = this.findClass(name); - if ( resolve ) - { - resolveClass(c); - } - return c; - - } - catch (ClassNotFoundException e) - { - ex= e; - } - - if ( c == null ) - { - try - { - c = super.loadClass(name,resolve); - } - catch (ClassNotFoundException e) - { - ex= e; - } - } - - throw ex; - - } - - - @Override public Class loadClass(String name) throws ClassNotFoundException { System.err.printf("[slf4j.cl] loadClass(%s)%n",name); - return super.loadClass(name); - } + Class c = null; + try + { + c = super.loadClass(name); + System.err.println("FOUND in slf4j classloader: " + name); + } + catch (ClassNotFoundException e) + { + System.err.println("Not found in slf4j classloader: " + name); + } - @Override - protected Class findClass(String name) throws ClassNotFoundException - { - System.err.printf("[slf4j.cl] findClass(%s)%n",name); - return super.findClass(name); + if (c == null) + { + try + { + c = parent.loadClass(name); + System.err.println("FOUND in parent classloader: " + name); + } + catch (ClassNotFoundException e) + { + System.err.println("Not found in parent classloader: " + name); + } + } + + if (c != null) + { + System.err.printf("[slf4j.cl] loadClass(%s) -> %s%n",name,c); + return c; + } + + throw new ClassNotFoundException(name); } } @@ -143,14 +129,14 @@ public class Slf4jTestJarsRunner extends BlockJUnit4ClassRunner System.out.println("Classpath entry: " + url); } - slf4jClassLoader = new Slf4jTestClassLoader(urls, original); + slf4jClassLoader = new Slf4jTestClassLoader(urls,original); } catch (MalformedURLException e) { throw new InitializationError(e); } } - + @Override protected Object createTest() throws Exception { @@ -158,13 +144,13 @@ public class Slf4jTestJarsRunner extends BlockJUnit4ClassRunner { Thread.currentThread().setContextClassLoader(slf4jClassLoader); TestClass testclass = getTestClass(); - + Class tc = slf4jClassLoader.loadClass(testclass.getName()); - - Constructor[] constructors= tc.getConstructors(); - Assert.assertEquals(1, constructors.length); + + Constructor[] constructors = tc.getConstructors(); + Assert.assertEquals(1,constructors.length); Constructor constructor = constructors[0]; - + return constructor.newInstance(); } finally