My first Eclipse plugin
Greetings, dear habretchitel!
Some time ago, I had an interesting task - to write a plugin for Eclipse. Moreover, the plugin is not simple, but with a tricky idea.
I have never had an experience writing plugins for Eclipse, but it is necessary - it is so necessary, and what came of it - under the habrokat.
The cunning idea was formulated as follows (exact quote):
“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 write a client-server application and want to simultaneously launch 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 starting this composite configuration, all the 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 task, I started by what any normal person does when solving the problem - decomposition of the task.
Well, by and large I need: a plugin-time, how to make a launch-configuration - two.
These two articles were my starting point for developing the plugin:
After reading the articles, I downloaded the tools on which I will sculpt the plugin.
Downloaded here: https://www.eclipse.org/downloads .
You need to download not just anything, but what the “Plug-in Development Environment” contains.
Download - run.
Click File-> New-> Project-> Plugin project.
In the window that appears (see the figure below), click Next. A

window will appear:

We’ll drive the default settings into it and click Next.
A window will appear:

Here, too, everything is very standard, BUT you need to pay attention to the kryzh “This plug-in will make contributions to the UI” - we remove it if the UI is not needed and dialing. Click Next.
The following window will appear:

Here you can select the plugin template, and I just clicked the kryzh at the top and clicked Finish.
As a result, the plug-in project will be created and something similar will appear on the screen:

Here, on the Dependencies tab, we can add various plug-in dependencies, and the plugin.xml file plays a very important role in the development of the plug-in.
So, how to make a plugin we figured out.
Next we are interested in launch configurations and what they eat with.
So what is the beast launch configuration? In essence, this is simply a configuration for launching a program.
That is, setting the parameters with which the program will be launched.
You can read more about this here: http://wiki.eclipse.org/FAQ_What_is_a_launch_configuration%3F
How to make a launch configuration is described here: http://www.eclipse.org/articles/Article-Launch-Framework/launch.html
So, how to sculpt a plug-in and launch-configuration became clear.
Let's get started.
We will make two plugins:
After reading that in the links above, Cap hints that it would be necessary to implement the ILaunchConfigurationDelegate interface to implement the launch configuration.
Let's not be shy and implement the interface:
In parallel, we will make functionality that will allow us to verify that the composite configuration is not looped (some evil uncle will take the atom and make a configuration that will refer to itself, and we will do it by the hand :))
With the UI plug-in, everything is quite simple.
1. We need to make a bookmark that will contain the settings.
To do this, we can inherit from the AbstractLaunchConfigurationTab class.
2. Make a group of bookmarks, for this we need to inherit from the AbstractLaunchConfigurationTabGroup class.
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 are the ones that will be launched.
Some time ago, I had an interesting task - to write a plugin for Eclipse. Moreover, the plugin is not simple, but with a tricky idea.
I have never had an experience writing plugins for Eclipse, but it is necessary - it is so necessary, and what came of it - under the habrokat.
The cunning idea was formulated as follows (exact quote):
“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 write a client-server application and want to simultaneously launch 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 starting this composite configuration, all the 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 task, I started by what any normal person does when solving the problem - decomposition of the task.
Large decomposition
Well, by and large I need: a plugin-time, how to make a launch-configuration - two.
Plugin
These two articles were my starting point for developing the plugin:
- http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.rse.doc.isv%2Fguide%2Ftutorial%2FpdeProject.html
- http://www.vogella.com/tutorials/EclipsePlugIn/article.html
After reading the articles, I downloaded the tools on which I will sculpt the plugin.
Downloaded here: https://www.eclipse.org/downloads .
You need to download not just anything, but what the “Plug-in Development Environment” contains.
Download - run.
Click File-> New-> Project-> Plugin project.
In the window that appears (see the figure below), click Next. A
window will appear:
We’ll drive the default settings into it and click Next.
A window will appear:
Here, too, everything is very standard, BUT you need to pay attention to the kryzh “This plug-in will make contributions to the UI” - we remove it if the UI is not needed and dialing. Click Next.
The following window will appear:
Here you can select the plugin template, and I just clicked the kryzh at the top and clicked Finish.
As a result, the plug-in project will be created and something similar will appear on the screen:
Here, on the Dependencies tab, we can add various plug-in dependencies, and the plugin.xml file plays a very important role in the development of the plug-in.
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 essence, this is simply a configuration for launching a program.
That is, setting the parameters with which the program will be launched.
You can read more about this here: http://wiki.eclipse.org/FAQ_What_is_a_launch_configuration%3F
How to make a launch configuration is described here: http://www.eclipse.org/articles/Article-Launch-Framework/launch.html
Back to the task
So, how to sculpt a plug-in and launch-configuration became clear.
Let's get started.
We will make two plugins:
- andrey.compositelaunchconfig - here everything will be actually what is needed in order to launch several launch configurations. But without a UI. In the article cited above, they write that it is better to separate the logic and the UI in such a way, suddenly someone wants to launch this kind of cunningly somehow, and they do not need the UI.
- andrey.compositelaunchconfig.ui - here will be the actual ui of this case.
After reading that in the links above, Cap hints that it would be necessary to implement the ILaunchConfigurationDelegate interface to implement the launch configuration.
Let's not be shy and implement the 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 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 functionality that will allow us to verify that the composite configuration is not looped (some evil uncle will take the atom and make a configuration that will refer to itself, and we will do it by the hand :))
Make UI
With the UI plug-in, everything is quite simple.
1. We need to make a bookmark that will contain the settings.
To do this, we can inherit from the AbstractLaunchConfigurationTab class.
2. Make a group of bookmarks, for this we need to inherit from the AbstractLaunchConfigurationTabGroup class.
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 are the ones that will be launched.