diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java index 03d5972edee..58d2e62a542 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java @@ -20,6 +20,7 @@ import java.util.Hashtable; import java.util.List; import java.util.UUID; +import org.eclipse.core.runtime.ILog; import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -201,6 +202,12 @@ public boolean close() { @Override public boolean restart() { + if (!canRestart()) { + String message = "Can't restart the workbench. This application was started with the '--launcher.noRestart' argument. Shutdown and start again manually."; //$NON-NLS-1$ + ILog.get().error(message); + return false; + } + this.restart = true; return close(); } @@ -212,6 +219,22 @@ public boolean isRestart() { return restart; } + /** + * Returns whether the workbench can be {@link #restart() restarted}. + * + *
+ * It can not be restarted if the --launcher.noRestart
argument is
+ * given.
+ *
true
if the workbench can be restarted.
+ */
+ public static boolean canRestart() {
+ String commands = System.getProperty("eclipse.commands", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ String NO_RESTART_ARGUMENT = "--launcher.noRestart"; //$NON-NLS-1$
+ return commands.lines().map(String::strip).noneMatch(NO_RESTART_ARGUMENT::equals);
+ }
+
/**
* @return a context that can be used to lookup OSGi services
*/
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index a62cce27627..6e780e877a2 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -1404,6 +1404,11 @@ public boolean close() {
*/
/* package */
boolean close(int returnCode, final boolean force) {
+ if (returnCode == PlatformUI.RETURN_RESTART && !E4Workbench.canRestart()) {
+ informNoRestart();
+ return false;
+ }
+
this.returnCode = returnCode;
final boolean[] ret = new boolean[1];
BusyIndicator.showWhile(null, () -> ret[0] = busyClose(force));
@@ -2555,11 +2560,21 @@ public WorkbenchWindow openWorkbenchWindow(IAdaptable input, IPerspectiveDescrip
@Override
public boolean restart() {
+ if (!E4Workbench.canRestart()) {
+ informNoRestart();
+ return false;
+ }
+
return close(PlatformUI.RETURN_RESTART, false);
}
@Override
public boolean restart(boolean useCurrrentWorkspace) {
+ if (!E4Workbench.canRestart()) {
+ informNoRestart();
+ return false;
+ }
+
if (Platform.inDevelopmentMode()) {
// In development mode, command line parameters cannot be changed and restart
// will always be EXIT_RESTART. Also see setRestartArguments method
@@ -2583,6 +2598,18 @@ public boolean restart(boolean useCurrrentWorkspace) {
return close(PlatformUI.RETURN_RESTART, false);
}
+ /**
+ * Inform the user that the workbench can't be restarted. If the workbench UI is
+ * not available, this method does nothing.
+ */
+ public void informNoRestart() {
+ final Display display = getDisplay();
+ if (display != null && !display.isDisposed()) {
+ MessageDialog.openError(null, WorkbenchMessages.Workbench_CantRestart_Title,
+ WorkbenchMessages.Workbench_CantRestart_Message);
+ }
+ }
+
/**
* Create and return a string with command line options for eclipse.exe that
* will launch a new workbench that is the same as the currently running one,
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
index d0a2acb25ca..dbddbbb6b6b 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
@@ -586,6 +586,9 @@ public class WorkbenchMessages extends NLS {
public static String Workbench_NeedsClose_Title;
public static String Workbench_NeedsClose_Message;
+ public static String Workbench_CantRestart_Title;
+ public static String Workbench_CantRestart_Message;
+
public static String ErrorPreferencePage_errorMessage;
public static String ListSelection_title;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
index c0ffd410a32..d51bc7b5021 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
@@ -554,6 +554,10 @@ InstallationDialog_ShellTitle={0} Installation Details
Workbench_NeedsClose_Title = Restart Needed
Workbench_NeedsClose_Message = A required plug-in is no longer available and the Workbench needs to be restarted. You will be prompted to save if there is any unsaved work.
+Workbench_CantRestart_Title = Restart unavailable
+Workbench_CantRestart_Message = Can't restart the workbench. This application was started with the '--launcher.noRestart' argument.\n\
+Shutdown and start again manually.
+
ErrorPreferencePage_errorMessage = An error has occurred when creating this preference page.
ListSelection_title = Selection Needed