From 718440998cfe5d88d9064ab9cdbada962048cca0 Mon Sep 17 00:00:00 2001 From: Markus Alexander Kuppe Date: Sun, 17 Mar 2013 20:31:56 +0100 Subject: [PATCH 1/1] NEW - bug 296599: Add ability to run e4 based tests using PDE's JUnit Plug-in Test https://bugs.eclipse.org/bugs/show_bug.cgi?id=296599 --- .../Eclipse UI/org/eclipse/ui/PlatformUI.java | 8 +++++++- .../org/eclipse/ui/internal/WorkbenchPlugin.java | 18 ++++++++++++++++++ .../org.eclipse.ui.workbench/META-INF/MANIFEST.MF | 2 +- bundles/org.eclipse.ui.workbench/pom.xml | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/PlatformUI.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/PlatformUI.java index 67fa4c2..5d3f8a1 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/PlatformUI.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/PlatformUI.java @@ -15,6 +15,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.internal.Workbench; import org.eclipse.ui.internal.WorkbenchMessages; +import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.testing.TestableObject; @@ -172,7 +173,12 @@ public final class PlatformUI { * @since 3.0 */ public static TestableObject getTestableObject() { - return Workbench.getWorkbenchTestable(); + // Try finding a pre-registered TO in the OSGi service registry + TestableObject testableObject = WorkbenchPlugin.getDefault().getTestableObject(); + if (testableObject == null) { + return Workbench.getWorkbenchTestable(); + } + return testableObject; } /** diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java index 6550ebf..41ee30e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java @@ -73,6 +73,7 @@ import org.eclipse.ui.internal.wizards.NewWizardRegistry; import org.eclipse.ui.operations.IWorkbenchOperationSupport; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.presentations.AbstractPresentationFactory; +import org.eclipse.ui.testing.TestableObject; import org.eclipse.ui.views.IViewRegistry; import org.eclipse.ui.wizards.IWizardRegistry; import org.osgi.framework.Bundle; @@ -197,6 +198,8 @@ public class WorkbenchPlugin extends AbstractUIPlugin { private ServiceTracker debugTracker = null; + private ServiceTracker testableTracker = null; + /** * Create an instance of the WorkbenchPlugin. The workbench plugin is * effectively the "application" for the workbench UI. The entire UI @@ -1146,6 +1149,10 @@ public class WorkbenchPlugin extends AbstractUIPlugin { debugTracker.close(); debugTracker = null; } + if (testableTracker != null) { + testableTracker.close(); + testableTracker = null; + } // TODO normally super.stop(*) would be the last statement in this // method super.stop(context); @@ -1524,4 +1531,15 @@ public class WorkbenchPlugin extends AbstractUIPlugin { } return (DebugOptions) debugTracker.getService(); } + + + public TestableObject getTestableObject() { + if (bundleContext == null) + return null; + if (testableTracker == null) { + testableTracker = new ServiceTracker(bundleContext, TestableObject.class.getName(), null); + testableTracker.open(); + } + return (TestableObject) testableTracker.getService(); + } } diff --git a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF index bcfb85d..4a1dcc8 100644 --- a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ui.workbench; singleton:=true -Bundle-Version: 3.105.0.qualifier +Bundle-Version: 3.106.0.qualifier Bundle-ClassPath: e4-workbench.jar, compatibility.jar, . diff --git a/bundles/org.eclipse.ui.workbench/pom.xml b/bundles/org.eclipse.ui.workbench/pom.xml index f7b715a..0ea3ed5 100644 --- a/bundles/org.eclipse.ui.workbench/pom.xml +++ b/bundles/org.eclipse.ui.workbench/pom.xml @@ -19,6 +19,6 @@ org.eclipse.ui org.eclipse.ui.workbench - 3.105.0-SNAPSHOT + 3.106.0-SNAPSHOT eclipse-plugin -- 1.7.10.4