Search in sources :

Example 6 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener in project azure-tools-for-java by Microsoft.

the class MavenExecuteAction method launch.

public void launch(IContainer basecon, Callable<?> callback) throws CoreException {
    if (basecon == null) {
        return;
    }
    ILaunchConfiguration launchConfiguration = createLaunchConfiguration(basecon);
    if (launchConfiguration == null) {
        return;
    }
    ILaunch launch = launchConfiguration.launch(MVN_LAUNCH_MODE, new NullProgressMonitor(), true, true);
    DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            for (int i = 0; i < events.length; i++) {
                DebugEvent event = events[i];
                if (event.getSource() instanceof IProcess && event.getKind() == DebugEvent.TERMINATE) {
                    IProcess process = (IProcess) event.getSource();
                    if (launch == process.getLaunch()) {
                        DebugPlugin.getDefault().removeDebugEventListener(this);
                        try {
                            if (process.getExitValue() == 0) {
                                callback.call();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return;
                    }
                }
            }
        }
    });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) CoreException(org.eclipse.core.runtime.CoreException)

Example 7 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener 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 8 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener in project webtools.servertools by eclipse.

the class PreviewServerBehaviour method addProcessListener.

protected void addProcessListener(final IProcess newProcess) {
    if (processListener != null || newProcess == null)
        return;
    processListener = new IDebugEventSetListener() {

        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                for (DebugEvent event : events) {
                    if (newProcess != null && newProcess.equals(event.getSource()) && event.getKind() == DebugEvent.TERMINATE) {
                        stop(true);
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(processListener);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent)

Example 9 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener in project liferay-ide by liferay.

the class PortalServerBehavior method addProcessListener.

public void addProcessListener(final IProcess newProcess) {
    if (processListener != null || newProcess == null) {
        return;
    }
    processListener = new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                for (DebugEvent event : events) {
                    if (newProcess != null && newProcess.equals(event.getSource()) && event.getKind() == DebugEvent.TERMINATE) {
                        cleanup();
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(processListener);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent)

Example 10 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener in project jbosstools-openshift by jbosstools.

the class AbstractCDKShutdownController method shutdownViaLaunch.

private void shutdownViaLaunch() throws CoreException {
    String args = getShutdownArgs();
    String cmd = getCommandLocation();
    CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
    ILaunchConfiguration lc = getServer().getLaunchConfiguration(true, new NullProgressMonitor());
    ILaunchConfigurationWorkingCopy lc2 = new CDKLaunchUtility().createExternalToolsLaunch(getServer(), args, new Path(cmd).lastSegment(), lc, cmd, cdk.skipUnregistration());
    IProcess p = null;
    ILaunch launch = null;
    try {
        launch = lc2.launch("run", new NullProgressMonitor());
        IProcess[] all = launch.getProcesses();
        if (all.length > 0)
            p = all[0];
    } catch (CoreException ce) {
        CDKCoreActivator.pluginLog().logError(ce);
        getBehavior().setServerStarted();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, ce.getMessage(), ce));
    }
    if (p == null) {
        getBehavior().setServerStopped();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to shutdown command has failed."));
    }
    final IProcess myProcess = p;
    IDebugEventSetListener listener = (new IDebugEventSetListener() {

        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                int size = events.length;
                for (int i = 0; i < size; i++) {
                    if (myProcess != null && myProcess.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) {
                        processTerminated(getServer(), null);
                        DebugPlugin.getDefault().removeDebugEventListener(this);
                    }
                }
            }
        }
    });
    DebugPlugin.getDefault().addDebugEventListener(listener);
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) CoreException(org.eclipse.core.runtime.CoreException) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Aggregations

IDebugEventSetListener (org.eclipse.debug.core.IDebugEventSetListener)10 DebugEvent (org.eclipse.debug.core.DebugEvent)8 IProcess (org.eclipse.debug.core.model.IProcess)6 CoreException (org.eclipse.core.runtime.CoreException)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 ILaunch (org.eclipse.debug.core.ILaunch)3 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)3 File (java.io.File)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 IServer (org.eclipse.wst.server.core.IServer)2 Server (org.eclipse.wst.server.core.internal.Server)2 ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)2 ProjectLauncher (aQute.bnd.build.ProjectLauncher)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Path (org.eclipse.core.runtime.Path)1 DebugException (org.eclipse.debug.core.DebugException)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1