Search in sources :

Example 1 with DebugEvent

use of org.eclipse.debug.core.DebugEvent in project bndtools by bndtools.

the class AbstractOSGiLaunchDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) throws CoreException {
    // Register listener to clean up temp files on exit of launched JVM
    final ProjectLauncher launcher = getProjectLauncher();
    IDebugEventSetListener listener = new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            for (DebugEvent event : events) {
                if (event.getKind() == DebugEvent.TERMINATE) {
                    Object source = event.getSource();
                    if (source instanceof IProcess) {
                        ILaunch processLaunch = ((IProcess) source).getLaunch();
                        if (processLaunch == launch) {
                            // Not interested in any further events =>
                            // unregister this listener
                            DebugPlugin.getDefault().removeDebugEventListener(this);
                            // *may* cause LinkageErrors.
                            try {
                                launcher.cleanup();
                            } catch (Throwable t) {
                                logger.logError("Error cleaning launcher temporary files", t);
                            }
                            LaunchUtils.endRun((Run) launcher.getProject());
                        }
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(listener);
    // Now actually launch
    super.launch(configuration, mode, launch, monitor);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) ILaunch(org.eclipse.debug.core.ILaunch) ProjectLauncher(aQute.bnd.build.ProjectLauncher) IProcess(org.eclipse.debug.core.model.IProcess)

Example 2 with DebugEvent

use of org.eclipse.debug.core.DebugEvent in project bndtools by bndtools.

the class TerminationListener method handleDebugEvents.

public void handleDebugEvents(DebugEvent[] events) {
    for (DebugEvent event : events) {
        Object source = event.getSource();
        if (event.getKind() == DebugEvent.TERMINATE && (source instanceof IProcess) && ((IProcess) source).getLaunch() == launch) {
            terminatedProcesses.add((IProcess) source);
            boolean isTerminated = true;
            IProcess[] createdProcesses = launch.getProcesses();
            for (IProcess process : createdProcesses) {
                if (!terminatedProcesses.contains(process)) {
                    isTerminated = false;
                    break;
                }
            }
            if (isTerminated) {
                DebugPlugin.getDefault().removeDebugEventListener(this);
                onTerminate.run();
            }
        }
    }
}
Also used : DebugEvent(org.eclipse.debug.core.DebugEvent) IProcess(org.eclipse.debug.core.model.IProcess)

Aggregations

DebugEvent (org.eclipse.debug.core.DebugEvent)2 IProcess (org.eclipse.debug.core.model.IProcess)2 ProjectLauncher (aQute.bnd.build.ProjectLauncher)1 IDebugEventSetListener (org.eclipse.debug.core.IDebugEventSetListener)1 ILaunch (org.eclipse.debug.core.ILaunch)1