Eclipse Papercut #4 – Modifying Eclipse PDE default launch configuration

In this episode of the Eclipse Papercut series I will change the default PDE launch configuration. During this process I show how to get and modify Eclipse PDE code.

Lets define the papercut:

One thing I always have to do during plugin and Eclipse RCP development is to make the following settings in the launch configuration:

  1. add -consoleLog in the arguments tab
  2. Select the flag “Validate plug-in automatically prio to launching” on the plug-ins tab

This papercut has two dimensions.

The first one is that for everybody who knows about these settings it is not a problem to set them up. It is just time-consuming and error prone. Sometimes I’m searching why something does not work and then I’m banging my head because I forgot to set -consoleLog.

The second dimension is that this default launch configuration makes it harder for new plugin and Eclipse RCP developers to get started. I frequently see questions in the Eclipse newsgroup and other places which can be answered by: “please set -consoleLog” or “press the Validate button”.

So I seek to change the current behavior.

Adding “-consoleLog” is easy. Go to preference, select the target platform, select “Edit” and add -consoleLog as a argument.

target10

target20

Of course this does not help the new developers but I come back to this later in this post.

To set the “Validate plug-in automatically prio to launching” flag we have to look into Eclipse PDE code.

A launch configuration is contributed by the extension point “org.eclipse.debug.core.launchConfigurationTypes”. To search through your existing plugins import your plugins into a new workspace. A plugin search reveals that “org.eclipse.pde.ui” contributes such an extension.

Eclipse PDE can be found in the Eclipse cvs via the repository path “/cvsroot/eclipse”. Search here for the folder “pde” which contains the pde plugins. Checkout the plugin “org.eclipse.pde.ui”.

Here we find quickly the right extension point.

pde10

After some pocking around the code and some debugging I found the class “AbstractPluginBlock” and the method “setDefaults”. The change is trivial:

public void setDefaults(ILaunchConfigurationWorkingCopy config) {
	config.setAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL, true);
	config.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true);
	config.setAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, true); // This has changed from false to true
	config.setAttribute(IPDELauncherConstants.SHOW_SELECTED_ONLY, false);
}

If you now run Eclipse with this adjusted plugin the flag “Validate…” will be flagged for a new runtime configuration.

Now lets return to the addtion of “-consoleLog” to the target platform. I argued earlier that the absence of “-consoleLog” makes it harder for beginner to get started with plugin and RCP development. Changing the target platform is not trivial for starters, so the better solution was if was part of the standard code.

We find the relevant code easily with a text seach for an existing launch parameter, e.g. “-arch”. The responsible class is “LaunchArgumentsHelper” and the method getInitialProgramArguments(). We add “-consoleLog” to the following line:


StringBuffer buffer = new StringBuffer("-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"); //$NON-NLS-1$

Thats it. By deploying the plugin into our Eclipse IDE we have the changed behavior.

I have submitted bugs and attached the patches. Bug Report for “Validate plug-in automatically prio to launching” and Bug Report for -consoleLog.

I hope that these patches will get accepted. If they would be accepted I believe it would be a little easier for new developers to get started.

If someone finds a reason why these settings should not always be the default I would suggest a new PDE preference page which contains the settings for these launch parameters.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse, Papercut and tagged , , , . Bookmark the permalink.