I know what "discouraged access" is supposed to mean: you're making use of internal libraries, things that are not in a public API, and you're simply not really supposed to make use of it.
Now, as far as I know is the class EclipseStarter in the package "org.eclipse.osgi.util" a part of the public API. I quote:
This package specifies API to start the platform.
Clients may use the EclipseStarter loader class to start the platform.
The EclipseStarter class is the only defined API in this package.
The details page for the EclipseStarter class states this:
Special startup class for the Eclipse Platform. This class cannot be instantiated;
all functionality is provided by static methods.
Note that the fields on this class are not API.
I read: methods are open to be used?
My code:
import org.eclipse.core.runtime.adaptor.EclipseStarter;
This one already gives the warning "Discouraged access: The type EclipseStarter is not accessible due to restriction on required library [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar"
The code where I make use of the class:
try {
EclipseStarter.shutdown();
EclipseStarter.startup(null, null);
} catch (Exception e) {
e.printStackTrace();
}
Warning: Discouraged access: The type EclipseStarter is not accessible due to restriction on required library [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar
Warning: Discouraged access: The method shutdown() from the type EclipseStarter is not accessible due to restriction on required library [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar
Warning: Discouraged access: The method startup(String[], Runnable) from the type EclipseStarter is not accessible due to restriction on required library [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar
I know, I'm calling the startup methode right now with null-values which might not work but I'm just writing code now - not running yet. I don't like the warnings. Either I'm totally wrong on this (and EclipseStarter is not public), either something in my configuration is wrong...
I tried adjusting the classpath so that the plugin dependencies come first (before the internal JRE), but that doesn't work either. The library these warnings are talking about are in the dependencies, not in my JRE. I don't know what else I can try.
Either way, bottom line I'm actually searching for a nice way to restart my Eclipse programmatically. The plugin code first installs some extra plugins (no warnings, users have to accept the license agreemenets of all these plugins as well), and then should restart. I had been using PlatformUI.getWorkbench().restart();
until now, but that gives me an error upon restarting in the log ("event loop" or something).
Anyone that can point me in the right direction? Thanks!
Edit: the error that PlatformUI.getWorkbench().restart()
gives me is the following:
eclipse.buildId=M20120208-0800
java.version=1.6.0_43
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=nl_BE
Framework arguments: -product org.eclipse.epp.package.rcp.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product
org.eclipse.epp.package.rcp.product
Error
Thu Nov 07 12:34:11 CET 2013
Unhandled event loop exception
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.eclipse.swt.widgets.Tree.getItems(Tree.java:3249)
at org.eclipse.jface.viewers.TreeViewer.getChildren(TreeViewer.java:171)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalCollectExpandedItems(AbstractTreeViewer.java:1588)
at org.eclipse.jface.viewers.AbstractTreeViewer.getExpandedElements(AbstractTreeViewer.java:1180)
at org.eclipse.ui.internal.dialogs.NewWizardNewPage.storeExpandedCategories(NewWizardNewPage.java:626)
at org.eclipse.ui.internal.dialogs.NewWizardNewPage.saveWidgetValues(NewWizardNewPage.java:544)
at org.eclipse.ui.internal.dialogs.NewWizardSelectionPage.saveWidgetValues(NewWizardSelectionPage.java:99)
at org.eclipse.ui.internal.dialogs.NewWizard.performFinish(NewWizard.java:128)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:831)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:432)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ui.internal.handlers.WizardHandler$New.executeHandler(WizardHandler.java:257)
at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:277)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.internal.actions.CommandAction.runWithEvent(CommandAction.java:157)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Edit 2: I'm pretty sure the above error happens because this piece of code is wrong. How would I have to write the performFinish code so that that error doesn't happen? With asyncExec
?
@Override
public final boolean performFinish() {
if (getContainer().getCurrentPage().equals(myLastPage)) {
PlatformUI.getWorkbench().restart();
return true;
} else {
return false;
}
}
Edit 3: Well, I changed the performFinish code to use asyncExec
, but now I get this error:
!ENTRY org.eclipse.ui 4 0 2013-11-07 13:56:21.380
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.eclipse.swt.widgets.Text.setText(Text.java:1966)
at helper.CustomProgressMonitor$1.run(CustomProgressMonitor.java:64)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 23 more
This one returns for like 50 times, so obviously, he's trying to still execute something when the Widget has been disposed.
This is the new performFinish
code:
@Override
public final boolean performFinish() {
if (getContainer().getCurrentPage().equals(myLastPage)) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
PlatformUI.getWorkbench().restart();
}
});
return true;
} else {
return false;
}
}
Just to be complete: it all works now. There was another class (a helper class) where I didn't check if the Text-widget was disposed before accessing it. Once that solved it all works as a charm. Thanks to greg-449!
PlatformUI.getWorkbench().restart();
is the correct way to restart (unless you are running a pure 'e4' RCP). You need to look at what is causing the event loop error.
The package containing EclipseStarter
is marked in the org.eclipse.osgi
MANIFEST.MF
with x-friends="org.eclipse.core.runtime"
which means it is intended only to be used by org.eclipse.core.runtime
and all other plugins will get the discouraged access warning.