summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMarkus Kuppe2013-04-19 18:12:10 (EDT)
committer Curtis Windatt2013-04-19 18:12:10 (EDT)
commitf82277e9585abbc96c22dbcd8f867092c4451e80 (patch)
tree611d8eda4a55c6ff37f362c4e1da8085644d5dde
parentadf3ed92dd53e7bb103a3c3b08961a662e0eb1a9 (diff)
downloadeclipse.platform.ui-f82277e9585abbc96c22dbcd8f867092c4451e80.zip
eclipse.platform.ui-f82277e9585abbc96c22dbcd8f867092c4451e80.tar.gz
eclipse.platform.ui-f82277e9585abbc96c22dbcd8f867092c4451e80.tar.bz2
Bug 296599 - Add ability to run e4 based tests using PDE's JUnit Plug-in
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/PlatformUI.java15
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java44
2 files changed, 49 insertions, 10 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..db1e068 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -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;
@@ -166,13 +167,21 @@ public final class PlatformUI {
* <p>
* IMPORTANT: This method is only for use by the test harness.
* Applications and regular plug-ins should not call this method.
- * </p>
+ * </p><p>
+ * To avoid depending on the the Workbench a {@link TestableObject}
+ * can be obtained via OSGi service.
+ * </p>
*
* @return the testable object facade
* @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..32c77a4 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;
@@ -150,7 +151,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
private BundleContext bundleContext;
// The set of currently starting bundles
- private Collection startingBundles = new HashSet();
+ private Collection<Bundle> startingBundles = new HashSet<Bundle>();
/**
* Global workbench ui plugin flag. Only workbench implementation is allowed to use this flag
@@ -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,8 +1149,10 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
debugTracker.close();
debugTracker = null;
}
- // TODO normally super.stop(*) would be the last statement in this
- // method
+ if (testableTracker != null) {
+ testableTracker.close();
+ testableTracker = null;
+ }
super.stop(context);
}
@@ -1240,7 +1245,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
}
/**
- * @return
+ * @return the bundle listener for this plug-in
*/
private BundleListener getBundleListener() {
if (bundleListener == null) {
@@ -1363,7 +1368,8 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
}
/**
- * @param e4Context
+ * Initialized the workbench plug-in with the e4 context
+ * @param context the e4 context
*/
public void initializeContext(IEclipseContext context) {
e4Context = context;
@@ -1372,7 +1378,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
@Override
public Object compute(IEclipseContext context, String contextKey) {
if (perspRegistry == null) {
- perspRegistry = (PerspectiveRegistry) ContextInjectionFactory.make(
+ perspRegistry = ContextInjectionFactory.make(
PerspectiveRegistry.class, e4Context);
}
return perspRegistry;
@@ -1383,7 +1389,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
@Override
public Object compute(IEclipseContext context, String contextKey) {
if (viewRegistry == null) {
- viewRegistry = (ViewRegistry) ContextInjectionFactory.make(ViewRegistry.class,
+ viewRegistry = ContextInjectionFactory.make(ViewRegistry.class,
e4Context);
}
return viewRegistry;
@@ -1524,4 +1530,28 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
}
return (DebugOptions) debugTracker.getService();
}
+
+
+ /**
+ * Returns a {@link TestableObject} provided by a TestableObject
+ * service or <code>null</code> if a service implementation cannot
+ * be found. The TestableObject is used to hook tests into the
+ * application lifecycle.
+ * <p>
+ * It is recommended the testable object is obtained via service
+ * over {@link Workbench#getWorkbenchTestable()} to avoid the
+ * tests having a dependency on the Workbench.
+ * </p>
+ * @see PlatformUI#getTestableObject()
+ * @return TestableObject provided via service or <code>null</code>
+ */
+ 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();
+ }
}