Greetings, dear habrochiteli!
Some time ago I had an interesting task - to write a plugin for Eclipse. And the plugin is not simple, but with a sly idea.
I have never had any experience of writing plug-ins for Eclipse, but it’s necessary - it’s necessary, and what came out of it - under the habrokat.
The cunning idea was formulated as follows (exact quotation):
“In Eclipse, there is the concept of launch configurations — settings for launching projects from workspace. These launch configurations have different properties depending on the type of applications being launched (java application, Eclipse plugins, JUnit tests).
Sometimes there is a need to run several applications from one workspace - for example, we are writing a client-server application and want to simultaneously run both the server and the client. For such purposes, it would be convenient to have a new type of launch configurations - composite, which would allow you to create a new configuration that references existing ones. At the same time, when launching this composite configuration, all configurations to which it refers should be launched. The task is to implement eclipse-plugin ('s), adding such a new launch configuration. "
So, having received and understood this problem, I began by doing what any normal person does when solving a problem — decomposition of a problem.
Large decomposition
Well, by and large, I need: a plug-in once, how to make a launch configuration - two.
Plugin
My two starting points for developing the plugin were these two articles:
After reading the article I downloaded the toolkit on which I will sculpt the plugin.
Downloaded it here:
https://www.eclipse.org/downloads .
You need to download not anything, but what contains the “Plug-in Development Environment”.
Download - run.
Click File-> New-> Project-> Plugin project
In the appeared window (picture below) we click Next
')

A window will appear:

In it we drive in the standard settings and click Next.
A window will appear:

Here, too, everything is very standard, but it is necessary to pay attention to the “This plug-in” plug - in it - we remove it if the UI is not needed and set. Click Next.
The following window will appear:

Here you can choose a template for the plug-in, and I just clicked off the roof at the top and clicked Finish.
As a result, the plugin project will be created and something like this will appear on the screen:

Here we can add various plugin dependencies on the Dependencies tab, and the plugin.xml file plays a very important role in plugin development.
So, how to make a plugin we figured out.
Next we are interested in launch configurations and what they eat with.
Launch configuration
So what is the beast launch configuration? In fact, this is just the launch configuration of the program.
That is, setting the parameters with which the program will run.
Read more about it here:
http://wiki.eclipse.org/FAQ_What_is_a_launch_configuration%3FHow to make a launch configuration described here:
http://www.eclipse.org/articles/Article-Launch-Framework/launch.htmlBack to the problem
So, how to sculpt the plugin and the launch configuration has become clear.
Let's start.
We will make two plugins:
- andrey.compositelaunchconfig - here you will actually have everything you need in order to launch several launch configurations. But without UI. In the article cited above, they write that it is better to separate the logic and the UI in this way, all of a sudden, someone wants to start this tricky piece somehow, and doesn’t need the UI.
- andrey.compositelaunchconfig.ui - here is the actual ui of this case.
Having read that in the links above, Cap Cap hints that it would be necessary to implement the ILaunchConfigurationDelegate interface to implement the launch configuration.
Let's not be shy and let's interface:
public class CompositeLaunchConfigurationDelegate implements ILaunchConfigurationDelegate { private void launchInnerConfiguration(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { ILaunch configurationLaunch = configuration.launch(mode,monitor); for (IDebugTarget debugTarget : configurationLaunch.getDebugTargets()) { launch.addDebugTarget(debugTarget); } for (IProcess process : configurationLaunch.getProcesses()) { launch.addProcess(process); } } @Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { if(!Utils.isLaunchModeValid(mode)) throw new CoreException(new Status(IStatus.ERROR,Activator.getPluginId(),"launch mode is not valid")); if(!Utils.isConfigurationValid(configuration)) throw new CoreException(new Status(IStatus.ERROR,Activator.getPluginId(),"configuration is not valid")); try { List<ILaunchConfiguration> launchConfigurations = Utils.getInnerConfigurations(configuration); SubMonitor launchMonitor = SubMonitor.convert(monitor, configuration.getName(), launchConfigurations.size()); for (ILaunchConfiguration launchConfiguration : launchConfigurations) { if (!monitor.isCanceled()) { launchInnerConfiguration(launchConfiguration,mode,launch,launchMonitor.newChild(1)); } } } finally{ monitor.done(); } } }
In parallel, we will make the functionality that will allow you to verify that the composite configuration does not get stuck (atoms will take some evil uncle and make a configuration that will refer to itself, and so we have it on the arm :))
We do UI
With the UI plugin everything is quite simple.
1. We need to make a bookmark that will contain the settings.
To do this, we can inherit from the class AbstractLaunchConfigurationTab.
2. To create a group of bookmarks, for this we need to inherit from the class AbstractLaunchConfigurationTabGroup.
Total
As a result of all these simple manipulations, such a thing turned out:

On the left are all available configurations, and on the right those that will be launched.