My first Eclipse plugin

Welcome, dear habrocerinae!
Some time ago I had the interesting task is to write a plugin for Eclipse. And the plugin is not simple, but with a cunning idea.
Experience writing plugins for Eclipse, I have never been, but it is necessary – so necessary, and what came of it – under abrogator.

A cunning idea was formulated as follows(exact quote):
"In Eclipse there is the concept of launch-configurations – configuration of running projects from workspace'. These launch configurations have different properties depending on the type of running applications (java application, Eclipse plugins, JUnit tests).
Sometimes there is a need to run multiple applications from one workspace'and – for example, we write a client server app and want to simultaneously run both the server and client. For such purposes it would be convenient to have a new type of launch-configurations – composite, which would allow us to create a new configuration that references the existing ones. When you run this composite configuration should run all the configurations to which it refers. The task is to implement an eclipse plugin('s) that adds a new launch configuration."
So, after understanding this challenge, I started with, that makes any normal person in solving the problem – the decomposition of the problem.

Large breakdown


Well, in the long run I need: a plugin-again, how to make a launch-configuration – two.

Plugin


My starting point for the development of the plugin was these two articles:
the
After reading the article, I downloaded the Toolkit, which will build a plugin.
Rocked here: https://www.eclipse.org/downloads.
To download it's not horrible, but something that contains “Plug-in Development Environment”.
Downloaded – run.
Click File-> New-> Project-> Plugin project
In the resulting window(shown below), click Next



A window will appear:



It beat the standard settings and click Next.
A window will appear:



Here, too, all very standard, BUT it is necessary to pay attention to kryzh “This plug-in will make contributions to the UI” – remove it, if the UI is not needed and Vice versa. Click "Next".
You will see the following window:



Here you can select the plugin template, and I just flicked the hoist at the top, and hit Finish.
As a result, the plug-in project is created and will appear on the screen something like this:



Here we can use the Dependencies tab to add dependencies of the plugin as a file plugin.xml plays a very important role in the development of the plugin.
So, how to make the plugin, we understand.
Further, we are interested in launch configuration and what they eat.

-Launch configuration


So that the beast launch configuration? In fact it's just a launch configuration.
That is, settings which program will be launched.
More information can be read 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 task


So, how to sculpt plugin and launch configuration has become clear.
Start.
We will make two plugin:
the
    the
  • andrey.compositelaunchconfig here is actually all that is necessary to run multiple launch configurations. But without UI. The article given above, write that it's better to separate the logic and UI, all of a sudden someone wants to run somehow cleverly is good, and the UI did not need.
  • the
  • andrey.compositelaunchconfig.ui – the ui here is actually the case.
  • Read what is in the reference given above, Cap kakby hints that it would be necessary to implement a launch-configuration to theimplementing interface ILaunchConfigurationDelegate.
    Not be shy and simplemente interface:

    the
    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);
    LaunchMonitor SubMonitor = 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 a functionality that will allow you to check that the composite configuration is not fixated(ATO, take some evil uncle and make a configuration that would refer to itself, and we – oops on the hand:))

    Do UI


    C UI-s ' plugin.
    1.We need to make a bookmark that will contain settings.
    For this we can unasledovala class AbstractLaunchConfigurationTab.
    2. To make a group of bookmarks, to do this we need to unasledovala class AbstractLaunchConfigurationTabGroup.
    Total
    As a result of these simple manipulation I made this thing:



    Left all the configurations available and the right ones that will run.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

The release of the new version of the module modLivestreet 0.3.0-rc

mSearch: search + filter for MODX Revolution

Emulator data from GNSS receiver NMEA