Community
Participate
Working Groups
Build Identifier: 20110615-0604 Problem ------- If an OSGi Bundle use EMF and is started before org.eclipse.ui is started then the Choose Workspace Dialog will not appear, because EcorePlugin>>start calls Platform.getWorkspace().getRoot(). Details ------- My Plugin/OSGi Bundle requires EMF but does not requires org.eclipse.ui. My Bundle will be started by org.eclipse.equinox.ds before org.eclipse.ui. Since my Bundle requires org.eclipse.emf.core the bundle org.eclipse.emf.core will be started and EcorePlugin>>start will be called. EcorePlugins>>start calls Platform.getWorkspace().getRoot() which will create a Workspace, if there is no Workpace available. The Bundle org.eclipse.ui starts after org.eclipse.emf.core. Since a workspace is already created by org.eclipse.emf.core no Choose Workspace Dialog will appear. Proposed Solution ----------------- EcorePlugins already checks if “org.eclipse.core.resources” is available. Extent this mechanism and check if “org.eclipse.ui” is available, too. If “org.eclipse.ui” is available initialize workspaceRoot after the Eclipse Workbench is initialized. See attached patch-gpf-01.txt. Reproducible: Always Steps to Reproduce: See attached ds.zip. In the Bundle ds.provided you will find a launch configuration (launch/ds.provider.ide.launch). Using this launch configuration no Choose Workspace Dialog will appear. If you disable the two bundle ds.provided and ds.consumer the Choose Workspace Dialog will appear.
Created attachment 205588 [details] ZIP to reproduce the problem
Created attachment 205589 [details] Patch with proposed solution
Sorry, I don't understand any of this so I'm reluctant to make changes I don't understand. It appears I'd be forcing the UI to start as well, which seems bad because nothing here relies on that and the next guy might complain that they want something even further downstream to be started before the UI or that they don't want the UI started at all, even though it's available. Hopefully John could comment on this. After all, E4 uses EMF and hasn't had this problem. Maybe this problem should be fixed in the UI or maybe the workspace needs to have an extension point the UI uses to ensure that what the UI wants to happen happens when the workspace starts. I don't know...
The proposed solution is an extension to the current code and is very similar to the existing code. The existing code in EMFPlugin checks if org.eclipse.core.resources is available: public static final boolean IS_RESOURCES_BUNDLE_AVAILABLE; static { // code to initialize IS_RESOURCES_BUNDLE_AVAILABLE ... } The proposed solution checks in addition if org.eclipse.ui is available: public static final boolean IS_ECLIPSE_UI_AVAILABLE; static { // code to initialize IS_ECLIPSE_UI_AVAILABLE (similar to existing code) .... } The existing code calls ResourcesPlugin.getWorkspace().getRoot() when "org.eclipse.core.resources" is available if (IS_RESOURCES_BUNDLE_AVAILABLE) { workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); } The proposed solution add an additional check: if (IS_RESOURCES_BUNDLE_AVAILABLE { if (IS_ECLIPSE_UI_AVAILABLE) { // If org.eclipse.ui is available // set workSpaceRoot after the workbench is initialized new WorkbenchTracker(context).open(); } else { workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); } } The WorkbenchTracker subclasses org.osgi.util.tracker.ServiceTracker and will never ever force any UI to start. It even has no dependency to "org.eclipse.ui". The WorkbenchTracker will be called when the Eclipse Workbench is initialized and will then initialize the static variable workspaceRoot (workspaceRoot = ResourcesPlugin.getWorkspace().getRoot())
Just discovered: Same problem occurs with Riena EMF Dynamic Views https://bugs.eclipse.org/bugs/show_bug.cgi?id=288063
Might it be simpler to move the code: private static IWorkspaceRoot workspaceRoot = null; /** * Returns the workspace root, or <code>null</code>, if the runtime environment is stand-alone. * @return the workspace root, or <code>null</code>. */ public static IWorkspaceRoot getWorkspaceRoot() { if (workspaceRoot == null && IS_RESOURCES_BUNDLE_AVAILABLE && System.getProperty("org.eclipse.emf.ecore.plugin.EcorePlugin.doNotLoadResourcesPlugin") == null) { workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); } return workspaceRoot; } This way the workspace is created on demand by anyone who needs it. I'd feel more comfortable with that because I understand it better and it's harder to imagine anyone even being able to notice...
Yes, this is much simpler. Since in my environment no bundle calls EcorePlugin>>getWorkspaceRoot during Eclipse startup it solves my problem. Thank you!
The change was committed to CVS for EMF 2.8.
The changes are available in builds.
*** Bug 288063 has been marked as a duplicate of this bug. ***