Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly end Eclipse launch configuration execution?

I am writing an Eclipse plugin contributing a new launch configuration type. It works perfectly expected that when the execution of a launch configuration for this new type is completed, the launch configuration button tooltip still indicates that my configuration is running.

This causes problem when I want to launch several of such configurations using launch groups, the second configuration waits indefinitely for the first one to complete (I am using the wait until termination option from the launch group). So I guess I am missing something to tell the platform that the execution of the launch config is completed.

like image 275
Manuel Selva Avatar asked Dec 27 '14 08:12

Manuel Selva


2 Answers

If I remember correctly, you need to start a new system Process when your launch configuration is launched (ILaunchConfigurationDelegate#launch) and then create a RuntimeProcess for this Process. The RuntimeProcess will then generate the necessary DebugEvents and notify the corresponding ILaunch when it was terminated.

You will usually create the RuntimeProcess by calling DebugPlugin#newProcess(ILaunch, Process, String) but it is also possible to instantiate it directly (e.g. if you want to extend the class RuntimeProcess).

like image 144
Balder Avatar answered Oct 01 '22 19:10

Balder


By looking at sample launch configurations (mainly the one provided by the Ant plugin), there is an org.eclipse.debug.core.model.ITerminate interface that is implemented in the process/debug targets that execute in the launch.

A org.eclipse.debug.core.IDebugEventSetListener is registered to handle terminate events which are triggered by calling the following statement:

DebugPlugin.getDefault().fireDebugEventSet(
                  new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)});

Sample code from the AntLaunchDelegate class:

final boolean[] terminated = new boolean[1];
terminated[0] = launch.isTerminated();
IDebugEventSetListener listener = new IDebugEventSetListener() {
    public void handleDebugEvents(DebugEvent[] events) {
        for (int i = 0; i < events.length; i++) {
            DebugEvent event = events[i];
            for (int j = 0, numProcesses = processes.length; j < numProcesses; j++) {
                if (event.getSource() == processes[j]
                        && event.getKind() == DebugEvent.TERMINATE) {
                    terminated[0] = true;
                    break;
                }
            }
        }
    }
};
DebugPlugin.getDefault().addDebugEventListener(listener);
monitor
        .subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
while (!monitor.isCanceled() && !terminated[0]) {
    try {
        Thread.sleep(50);
    } catch (InterruptedException e) {
    }
}
DebugPlugin.getDefault().removeDebugEventListener(listener);
like image 20
M A Avatar answered Oct 01 '22 17:10

M A