Skip to content

Commit

Permalink
Workbench restart is unavailable if '--launcher.noRestart' is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhendriks committed Jul 29, 2024
1 parent 8b4c0b6 commit 609b15d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -212,6 +219,22 @@ public boolean isRestart() {
return restart;
}

/**
* Returns whether the workbench can be {@link #restart() restarted}.
*
* <p>
* It can not be restarted if the <code>--launcher.noRestart</code> argument is
* given.
* </p>
*
* @return <code>true</code> 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 609b15d

Please sign in to comment.