Search in sources :

Example 1 with IDebugEventSetListener

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

the class GenericServerBehaviour method setProcess.

protected void setProcess(final IProcess newProcess) {
    if (process != null)
        return;
    if (processListener != null)
        DebugPlugin.getDefault().removeDebugEventListener(processListener);
    if (newProcess == null)
        return;
    process = newProcess;
    processListener = new IDebugEventSetListener() {

        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                int size = events.length;
                for (int i = 0; i < size; i++) {
                    if (process != null && process.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) {
                        DebugPlugin.getDefault().removeDebugEventListener(this);
                        stopImpl();
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(processListener);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent)

Example 2 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 3 with IDebugEventSetListener

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

the class CDK3LaunchController method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    final IServer s = ServerUtil.getServer(configuration);
    if (s == null) {
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate server from launch configuration."));
    }
    final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
    beh.setServerStarting();
    String minishiftLoc = MinishiftBinaryUtility.getMinishiftLocation(s);
    if (minishiftLoc == null || !(new File(minishiftLoc).exists())) {
        beh.setServerStopped();
        if (minishiftLoc == null)
            throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate minishift command. Please set a correct value in the server editor."));
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of minishift command does not exist: " + minishiftLoc + "\nPlease set a correct value in the server editor."));
    }
    CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    boolean skipReg = cdkServer.skipRegistration();
    if (passCredentials && !skipReg) {
        handleCredentialsDuringLaunch(s, cdkServer, beh);
    }
    // Poll the server once more
    IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
    if (stat.isOK()) {
        beh.setServerStarted();
        ((Server) beh.getServer()).setMode("run");
        return;
    }
    String args = configuration.getAttribute(ATTR_ARGS, (String) null);
    // Add listener first
    IDebugEventSetListener debug = getDebugListener(launch);
    DebugPlugin.getDefault().addDebugEventListener(debug);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
    Process p = null;
    try {
        CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
        p = new CDKLaunchUtility().callMinishiftConsole(s, args, getStartupLaunchName(s), cdk.skipRegistration());
    } catch (IOException ioe) {
        CDKCoreActivator.pluginLog().logError(ioe);
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, ioe.getMessage(), ioe));
    }
    if (p == null) {
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to minishift up has failed."));
    }
    IProcess process = addProcessToLaunch(p, launch, s, false, minishiftLoc);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Server(org.eclipse.wst.server.core.internal.Server) CDK3Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK3Server) IServer(org.eclipse.wst.server.core.IServer) CDK32Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK32Server) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 4 with IDebugEventSetListener

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

the class CDKLaunchController method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    final IServer s = ServerUtil.getServer(configuration);
    verifyServer(s);
    final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
    beh.setServerStarting();
    String vagrantLoc = VagrantBinaryUtility.getVagrantLocation(s);
    if (vagrantLoc == null || !(new File(vagrantLoc).exists())) {
        beh.setServerStopped();
        if (vagrantLoc == null)
            throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate vagrant command. Please check the server's launch configuration on the 'Environment' tab to ensure that the command is available on your Path environment variable."));
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of vagrant command does not exist: " + vagrantLoc));
    }
    CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    boolean skipReg = cdkServer.skipRegistration();
    if (passCredentials && !skipReg) {
        setBehaviourUserAndPassword(s, beh, cdkServer);
    }
    // Poll the server once more
    IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
    if (stat.isOK()) {
        beh.setServerStarted();
        ((Server) beh.getServer()).setMode(ILaunchManager.RUN_MODE);
        return;
    }
    String args = configuration.getAttribute(ATTR_ARGS, (String) null);
    CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
    Process p = getProcess(s, beh, args, cdk.skipRegistration());
    if (p == null) {
        beh.setServerStopped();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to vagrant up has failed."));
    }
    IProcess process = addProcessToLaunch(p, launch, s, true);
    IDebugEventSetListener debug = getDebugListener(new IProcess[] { process }, launch);
    DebugPlugin.getDefault().addDebugEventListener(debug);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) IProcess(org.eclipse.debug.core.model.IProcess) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) IControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 5 with IDebugEventSetListener

use of org.eclipse.debug.core.IDebugEventSetListener in project mdw-designer by CenturyLinkCloud.

the class GherkinTestCaseLaunch method run.

@Override
public void run() {
    synchronized (lock) {
        try {
            launchConfig = getLaunchConfiguration();
            IDebugEventSetListener listener = new IDebugEventSetListener() {

                public void handleDebugEvents(DebugEvent[] events) {
                    for (DebugEvent event : events) {
                        if (event.getSource() instanceof IProcess) {
                            IProcess process = (IProcess) event.getSource();
                            if (event.getKind() == DebugEvent.CREATE) {
                                process.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {

                                    public void streamAppended(String text, IStreamMonitor monitor) {
                                        log.print(text);
                                        if (text.equals("===== execute case " + getTestCase().getCaseName() + "\r\n"))
                                            getTestCase().setStatus(TestCase.STATUS_RUNNING);
                                        getTestCase().setStartDate(new Date());
                                    }
                                });
                                process.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {

                                    public void streamAppended(String text, IStreamMonitor monitor) {
                                        log.print(text);
                                    }
                                });
                            } else if (event.getKind() == DebugEvent.TERMINATE && process.getLaunch().getLaunchConfiguration().equals(launchConfig) && process.isTerminated() && true) {
                                getTestCase().setEndDate(new Date());
                                try {
                                    if (process.getExitValue() == 0) {
                                        getTestCase().setStatus(TestCase.STATUS_PASS);
                                    } else {
                                        String exitMsg = "Cucumber exit code: " + process.getExitValue();
                                        log.println(exitMsg);
                                        // TODO why
                                        setMessage(exitMsg);
                                        // not
                                        // displayed?
                                        getTestCase().setStatus(TestCase.STATUS_FAIL);
                                    }
                                    if (log != System.out)
                                        log.close();
                                } catch (DebugException ex) {
                                    PluginMessages.log(ex);
                                    ex.printStackTrace(log);
                                    getTestCase().setStatus(TestCase.STATUS_ERROR);
                                    if (log != System.out)
                                        log.close();
                                }
                            }
                        }
                    }
                }
            };
            DebugPlugin.getDefault().addDebugEventListener(listener);
            DebugUITools.launch(launchConfig, ILaunchManager.RUN_MODE);
        } catch (Throwable ex) {
            PluginMessages.log(ex);
            ex.printStackTrace(log);
            getTestCase().setStatus(TestCase.STATUS_ERROR);
            getTestCase().setEndDate(new Date());
            if (log != System.out)
                log.close();
        }
    }
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) DebugException(org.eclipse.debug.core.DebugException) IProcess(org.eclipse.debug.core.model.IProcess) Date(java.util.Date)

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