diff --git a/core/src/main/java/hudson/DescriptorExtensionList.java b/core/src/main/java/hudson/DescriptorExtensionList.java index 3a570dc023..d4bc87db21 100644 --- a/core/src/main/java/hudson/DescriptorExtensionList.java +++ b/core/src/main/java/hudson/DescriptorExtensionList.java @@ -164,5 +164,12 @@ public class DescriptorExtensionList, D extends Descrip }; } + /** + * Exposed just for the test harness. Clear legacy instances. + */ + public static void clearLegacyInstances() { + legacyDescriptors.clear(); + } + private static final Logger LOGGER = Logger.getLogger(DescriptorExtensionList.class.getName()); } diff --git a/core/src/main/java/hudson/ExtensionList.java b/core/src/main/java/hudson/ExtensionList.java index 06b412d0c6..65355cf7f7 100644 --- a/core/src/main/java/hudson/ExtensionList.java +++ b/core/src/main/java/hudson/ExtensionList.java @@ -229,4 +229,11 @@ public class ExtensionList extends AbstractList { return new CopyOnWriteArrayList(); } }; + + /** + * Exposed for the test harness to clear all legacy extension instances. + */ + public static void clearLegacyInstances() { + staticLegacyInstances.clear(); + } } diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 2752f7dc69..eae0243534 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -28,6 +28,8 @@ import hudson.FilePath; import hudson.Functions; import hudson.WebAppMain; import hudson.EnvVars; +import hudson.ExtensionList; +import hudson.DescriptorExtensionList; import hudson.Launcher.LocalLauncher; import hudson.matrix.MatrixProject; import hudson.matrix.MatrixBuild; @@ -214,23 +216,8 @@ public abstract class HudsonTestCase extends TestCase { hudson.cleanUp(); env.dispose(); - } - - private void cleanUpDescriptors(Iterable cont) { - ClassLoader base = getClass().getClassLoader(); - for (Iterator itr = cont.iterator(); itr.hasNext();) { - Descriptor d = itr.next(); - ClassLoader cl = d.getClass().getClassLoader(); - if(cl==base) continue; - - while(cl!=null) { - cl = cl.getParent(); - if(cl==base) { - itr.remove(); - break; - } - } - } + ExtensionList.clearLegacyInstances(); + DescriptorExtensionList.clearLegacyInstances(); } protected void runTest() throws Throwable { @@ -445,6 +432,15 @@ public abstract class HudsonTestCase extends TestCase { } } + /** + * Blocks until the ENTER key is hit. + * This is useful during debugging a test so that one can inspect the state of Hudson through the web browser. + */ + public void interactiveBreak() throws Exception { + System.out.println("Hudson is running at localhost:"+localPort); + new BufferedReader(new InputStreamReader(System.in)).readLine(); + } + /** * Returns the last item in the list. */