views:

401

answers:

1

I have a plugin that forces a restart of Eclipse by using:

Workbench.getInstance().restart();

However, I need this restart to include a new environment variable:

eclipse.refreshBundles=true

Is there any way to add such an environment variable for this next restart of Eclipse only?

+1  A: 

Eclipse has 2 modes for restarting: "restart" using the previous command line, or "relaunch" using a new command line. The launcher itself will remember the previous command line, so in order to add a new system property, you will need to do the relaunch.

The restart/relaunch is part of the IApplication API, the Workbench.restart() will cause the IDEApplication to return relaunch if you set the system property eclipse.exitcode=24.

For the relaunch, you need to put the new command line in the eclipse.exitdata system property. You will need to reconstruct the command line using the eclipse.commands and eclipse.vmargs system properties, and add a -Declipse.refreshBundles=true vm argument. For an example of this, take a look at OpenWorkspaceAction in org.eclipse.ui.ide which uses the relaunch to switch workspaces.

Note that in the restarted eclipse, the eclipse.refreshBundles will be part of the command line, and will remain there for further restarts unless you modify the system properties. It will be gone if you exit fully and start again.

Andrew Niefer
Thanks, Andrew. This is very helpful.I have already implemented a solution, but I like yours better. I am using p2 to add an Installable Unit that changes the vmargs of the launcher temporarily for one launch. Then I uninstall that installable unit and future restarts happen as normal.The problem with my solution is that it is slow to install and uninstall the IU. Furthermore, it feels like overkill for a seemingly simple problem.So, I will reimplement and try your solution.
Andrew Eisenberg
The advantage to the p2 IU approach is that it is more persistent. If the user has the option to just exit and then start again later, you will still have the vm argument. Also the above restart method requires the launcher, so won't work if someone starts using "java -jar" (ie a script, or self hosted workspace).
Andrew Niefer
I don't think that the issues you describe above are likely in my case. The use case is that someone is using Eclipse to program with one level of the compiler for our language, and needs to switch to another. So, this should not occur in headless mode, or when launched as a script (I don't believe many people work that way). This may make things more difficult to test, but since I am having problems with the p2 solution anyway, I think I need to move over to this relaunch option.
Andrew Eisenberg