From 9b24de8b3686dc36ac4d585d838a1c24590010f2 Mon Sep 17 00:00:00 2001 From: Umair Sair Date: Sat, 7 Oct 2023 02:07:14 +0500 Subject: [PATCH] Restarting workspace should take into account changes to eclipse.ini Background: =========== There are 3 return codes supported by Eclipse - 0 - Normal exit - 23 - Restart the eclipse with previous launcher arguments - 24 - Restart the eclipse with the arguments provided by Eclipse application itself The above mentioned problem is not with the exit code 23. The reason is that the eclipse launcher restarts itself in this case, hence eclipse.ini is also reloaded. However eclipse launcher does not restart itself in case of code 24 and parses the arguments provided by Eclipse application in shared memory and simply relaunches java, which means that eclipse.ini will not be reloaded. For restarts, eclipse should be using code 23 but we had to switch to code 24 to fix following issue. [[WorkbenchLauncher] Restart asks for the workspace to run](https://bugs.eclipse.org/bugs/show_bug.cgi?id=264072) And then the fix of following built up on it. [[Workspace chooser] "Older Workspace Version" dialog: "Cancel" button shouldn't close Eclipse but go back to workspace chooser](https://bugs.eclipse.org/bugs/show_bug.cgi?id=538830) Fix: ==== For code 24, the arguments in shared memory are for launcher, so instead of launcher just parsing the args and relaunching java, it should restart the launcher with appropriate arguments. With relaunching the launcher, eclipse.ini will be reloaded like its done for code 23. Eclipse launcher is updated to relaunch for code 24 as well. Moreover, there are 3 new launcher arguments introduced, 2 are internal to launcher and one is external to launcher and can be set by eclipse application as a relaunch argument. - `--launcher.oldUserArgsStart` and `--launcher.oldUserArgsEnd`: The user arguments passed to eclipse launcher for first start are tracked between these arguments during relaunches. E.g., if eclipse was started as `eclipse A B C` where A B C are some arguments to launcher and for relaunch, Eclipse application mentioned `X Y Z` arguments then relaunch command will be `eclipse --launcher.oldUserArgsStart A B C --launcher.oldUserArgsEnd A B C X Y Z`. Moreover, launcher relaunch will ignore all arguments between and including `--launcher.oldUserArgsStart` and `--launcher.oldUserArgsEnd`. - `--launcher.skipOldUserArgs`: If eclipse application wants to relaunch with provided arguments only and ignore the older user args then it can mention this argument. So for the case where eclipse was started as `eclipse A B C` and Eclipse application mentioned `X Y Z` as relaunch arguments along with `--launcher.skipOldUserArgs` then relaunch command will be `eclipse --launcher.oldUserArgsStart A B C --launcher.oldUserArgsEnd X Y Z` where launcher relaunch will ignore all arguments between and including `--launcher.oldUserArgsStart` and `--launcher.oldUserArgsEnd`. For restarts, Eclipse application just mentions the `-data` argument now as relaunch arguments instead of mentioning complete java args. However, user can still mention more arguments for relaunch and Eclipse restart will respect them as well and append the `-data` argument at the end of user arguments. --- .../org/eclipse/ui/internal/Workbench.java | 77 ++++--------------- .../ui/internal/WorkbenchMessages.java | 1 - .../eclipse/ui/internal/messages.properties | 5 +- 3 files changed, 16 insertions(+), 67 deletions(-) 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 25853abd436..aa76aa423bf 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 @@ -139,6 +139,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.Window; +import org.eclipse.osgi.internal.location.LocationHelper; import org.eclipse.osgi.service.runnable.StartupMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -290,12 +291,8 @@ public final class Workbench extends EventManager implements IWorkbench, org.ecl public static final String EDITOR_TAG = "Editor"; //$NON-NLS-1$ - private static final String PROP_VM = "eclipse.vm"; //$NON-NLS-1$ - private static final String PROP_VMARGS = "eclipse.vmargs"; //$NON-NLS-1$ - private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$ public static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$ private static final String CMD_DATA = "-data"; //$NON-NLS-1$ - private static final String CMD_VMARGS = "-vmargs"; //$NON-NLS-1$ private static final class StartupProgressBundleListener implements SynchronousBundleListener { @@ -2593,64 +2590,16 @@ public boolean restart(boolean useCurrrentWorkspace) { * is not set */ private static String buildCommandLine(String workspace) { - String property = System.getProperty(PROP_VM); - if (property == null) { - if (!Platform.inDevelopmentMode()) { - // Don't log this when in development mode, since 'eclipse.vm' - // is never set in this case - WorkbenchPlugin.log(NLS.bind(WorkbenchMessages.Workbench_missingPropertyMessage, PROP_VM)); - } - return null; - } - StringBuilder result = new StringBuilder(512); - result.append(property); - result.append('\n'); - // append the vmargs and commands. Assume that these already end in \n - String vmargs = System.getProperty(PROP_VMARGS); - if (vmargs != null) { - result.append(vmargs); - } + String userData = System.getProperty(IApplicationContext.EXIT_DATA_PROPERTY); + if (userData != null && !userData.isBlank()) + result.append(userData); - // append the rest of the args, replacing or adding -data as required - property = System.getProperty(PROP_COMMANDS); - if (property == null) { - result.append(CMD_DATA); - result.append('\n'); - result.append(workspace); - result.append('\n'); - } else { - // find the index of the arg to add/replace its value - int cmd_data_pos = property.lastIndexOf(CMD_DATA); - if (cmd_data_pos != -1) { - cmd_data_pos += CMD_DATA.length() + 1; - result.append(property.substring(0, cmd_data_pos)); - result.append(workspace); - // append from the next arg - int nextArg = property.indexOf("\n-", cmd_data_pos - 1); //$NON-NLS-1$ - if (nextArg != -1) { - result.append(property.substring(nextArg)); - } - } else { - result.append(CMD_DATA); - result.append('\n'); - result.append(workspace); - result.append('\n'); - result.append(property); - } - } - - // put the vmargs back at the very end (the eclipse.commands property - // already contains the -vm arg) - if (vmargs != null) { - if (result.charAt(result.length() - 1) != '\n') { - result.append('\n'); - } - result.append(CMD_VMARGS); - result.append('\n'); - result.append(vmargs); - } + result.append(CMD_DATA); + result.append('\n'); + result.append(workspace); + result.append('\n'); return result.toString(); } @@ -2662,13 +2611,15 @@ private static String buildCommandLine(String workspace) { * @param workspacePath the new workspace location * @return {@link IApplication#EXIT_OK} or {@link IApplication#EXIT_RELAUNCH} */ + @SuppressWarnings("restriction") public static Object setRestartArguments(String workspacePath) { - String property = System.getProperty(Workbench.PROP_VM); - if (property == null) { + if (Platform.inDevelopmentMode() + && !Platform.getInstanceLocation().getURL().equals(LocationHelper.buildURL(workspacePath, true))) { MessageDialog.openError(null, WorkbenchMessages.Workbench_problemsRestartErrorTitle, - NLS.bind(WorkbenchMessages.Workbench_problemsRestartErrorMessage, Workbench.PROP_VM)); - return IApplication.EXIT_OK; + WorkbenchMessages.Workbench_problemsRestartErrorMessage); + return null; } + String command_line = Workbench.buildCommandLine(workspacePath); if (command_line == null) { return IApplication.EXIT_OK; 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 d37b8fff5e9..9f48433c3e7 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 @@ -91,7 +91,6 @@ public class WorkbenchMessages extends NLS { public static String SaveAll_toolTip; public static String Workbench_revert; public static String Workbench_revertToolTip; - public static String Workbench_missingPropertyMessage; public static String Workbench_move; public static String Workbench_moveToolTip; 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 0323fecc052..2545f6e0987 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 @@ -57,7 +57,6 @@ SaveAll_text = Sav&e All SaveAll_toolTip = Save All Workbench_revert = Rever&t Workbench_revertToolTip = Revert -Workbench_missingPropertyMessage=Unable to relaunch the platform with the current workspace because the ''{0}'' property has not been set. Workbench_move = Mo&ve... Workbench_moveToolTip = Move Workbench_rename = Rena&me... @@ -693,8 +692,8 @@ Startup_Loading_Workbench=Loading Workbench Workbench_problemsSavingMsg=Could not save workbench layout. Workbench_problemsRestoring=Problems occurred restoring workbench. Workbench_problemsSaving=Problems occurred saving workbench. -Workbench_problemsRestartErrorTitle = Missing System Property -Workbench_problemsRestartErrorMessage = Unable to relaunch the workbench because the {0} property has not been set. +Workbench_problemsRestartErrorTitle = Restart with different workspace +Workbench_problemsRestartErrorMessage = Restarting with different workspace does not work in development mode. PageLayout_missingRefPart=Referenced part does not exist yet: {0}.