Search in sources :

Example 1 with IStreamMonitor

use of org.eclipse.debug.core.model.IStreamMonitor in project erlide_eclipse by erlang.

the class Backend method assignStreamProxyListeners.

public void assignStreamProxyListeners() {
    if (data.getLaunch() == null) {
        return;
    }
    final IStreamsProxy proxy = getStreamsProxy();
    if (proxy != null) {
        final IStreamMonitor errorStreamMonitor = proxy.getErrorStreamMonitor();
        errorStreamMonitor.addListener(this);
        final IStreamMonitor outputStreamMonitor = proxy.getOutputStreamMonitor();
        outputStreamMonitor.addListener(this);
    }
}
Also used : IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy)

Example 2 with IStreamMonitor

use of org.eclipse.debug.core.model.IStreamMonitor in project titan.EclipsePlug-ins by eclipse.

the class CliExecutor method startSession.

/**
 * Initializes the Executor by starting the mctr_cli and connecting to it.
 *
 * @param arg2 the launch configuration to take the setup data from
 */
@Override
public void startSession(final ILaunch arg2) {
    ProcessBuilder pb = new ProcessBuilder();
    Map<String, String> env = pb.environment();
    if (!appendEnvironmentalVariables) {
        env.clear();
    }
    if (null != environmentalVariables) {
        try {
            EnvironmentHelper.resolveVariables(env, environmentalVariables);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    EnvironmentHelper.setTitanPath(env);
    EnvironmentHelper.set_LICENSE_FILE_PATH(env);
    String mctrCliPath = getMctrPath(env);
    List<String> command = new ArrayList<String>();
    command.add("sh");
    command.add("-c");
    if (addConfigFilePath(mctrCliPath, command)) {
        return;
    }
    printCommandToTitanConsole(command);
    pb.command(command);
    pb.redirectErrorStream(true);
    if (null != workingdirectoryPath) {
        File workingDir = new File(workingdirectoryPath);
        if (!workingDir.exists()) {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openError(null, "Execution failed", "The working directory `" + workingdirectoryPath + "' does not exist.");
                }
            });
        }
        pb.directory(workingDir);
    }
    Process proc;
    try {
        proc = pb.start();
        final InputStream inputstream = proc.getInputStream();
        if (inputstream.markSupported()) {
            inputstream.mark(40000);
        }
        BufferedReader stdout = new BufferedReader(new InputStreamReader(inputstream));
        processWelcomeScreen(stdout);
        if (inputstream.markSupported()) {
            inputstream.reset();
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        proc = null;
    }
    if (null != proc) {
        process = DebugPlugin.newProcess(arg2, proc, MAIN_CONTROLLER);
        IStreamsProxy proxy = process.getStreamsProxy();
        if (null != proxy) {
            IStreamMonitor outputStreamMonitor = proxy.getOutputStreamMonitor();
            IStreamListener outputListener = new IStreamListener() {

                @Override
                public void streamAppended(final String text, final IStreamMonitor monitor) {
                    processConsoleOutput(text);
                }
            };
            if (null != outputStreamMonitor) {
                processConsoleOutput(outputStreamMonitor.getContents());
                outputStreamMonitor.addListener(outputListener);
            }
        }
        info();
    }
    super.startSession(arg2);
    if (null == proc || null == process || process.isTerminated()) {
        terminate(true);
    }
    if (null != Activator.getMainView()) {
        Activator.getMainView().refreshAll();
    }
    if (null != thread) {
        thread.start();
    }
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) File(java.io.File)

Example 3 with IStreamMonitor

use of org.eclipse.debug.core.model.IStreamMonitor in project titan.EclipsePlug-ins by eclipse.

the class HostJob method run.

@Override
protected IStatus run(final IProgressMonitor monitor) {
    IProcess process = DebugPlugin.newProcess(executor.getLaunchStarted(), proc, getName());
    final IStreamsProxy proxy = process.getStreamsProxy();
    if (null != proxy) {
        final IStreamMonitor outputStreamMonitor = proxy.getOutputStreamMonitor();
        final IStreamListener listener = new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor monitor) {
                processConsoleOutput(text);
            }
        };
        if (null != outputStreamMonitor) {
            final String temp = outputStreamMonitor.getContents();
            processConsoleOutput(temp);
            outputStreamMonitor.addListener(listener);
        }
    }
    final MessageConsoleStream stream = TITANConsole.getConsole().newMessageStream();
    String line;
    final BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    final BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    try {
        final int exitVal = proc.waitFor();
        if (0 == exitVal) {
            executor.addNotification(new Notification((new Formatter()).format(BaseExecutor.PADDEDDATETIMEFORMAT, new Date()).toString(), EMPTY, EMPTY, "Host Controller executed successfully"));
        } else {
            if (stderr.ready()) {
                final String tempDate = (new Formatter()).format(BaseExecutor.PADDEDDATETIMEFORMAT, new Date()).toString();
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "Host Controller execution failed"));
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "  returned with value:" + exitVal));
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "Sent the following error messages:"));
                line = stderr.readLine();
                while (null != line) {
                    executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, line));
                    line = stderr.readLine();
                }
            }
        }
        proc.destroy();
    } catch (IOException e) {
        stream.println("execution failed beacuse of interrupion");
        ErrorReporter.logExceptionStackTrace(e);
        return Status.CANCEL_STATUS;
    } catch (InterruptedException e) {
        stream.println("execution failed beacuse of interrupion");
        ErrorReporter.logExceptionStackTrace(e);
        return Status.CANCEL_STATUS;
    } finally {
        try {
            stdout.close();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
        try {
            stderr.close();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return Status.OK_STATUS;
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) InputStreamReader(java.io.InputStreamReader) Formatter(java.util.Formatter) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IOException(java.io.IOException) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) BufferedReader(java.io.BufferedReader) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IProcess(org.eclipse.debug.core.model.IProcess)

Example 4 with IStreamMonitor

use of org.eclipse.debug.core.model.IStreamMonitor 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)

Example 5 with IStreamMonitor

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

the class CucumberLaunchListener method handleDebugEvents.

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) {
                        System.out.print(text);
                        if (!running) {
                            running = true;
                            start = new Date();
                        }
                    }
                });
                process.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {

                    public void streamAppended(String text, IStreamMonitor monitor) {
                        System.out.print(text);
                    }
                });
            } else if (event.getKind() == DebugEvent.TERMINATE && process.getLaunch().getLaunchConfiguration().equals(launchConfig) && process.isTerminated() && true) {
                end = new Date();
                try {
                    int exitCode = process.getExitValue();
                    if (exitCode == 0) {
                        status = TestCase.STATUS_PASS;
                    } else {
                        status = TestCase.STATUS_FAIL;
                    }
                } catch (DebugException ex) {
                    PluginMessages.log(ex);
                    status = TestCase.STATUS_ERROR;
                }
            }
        }
    }
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) DebugEvent(org.eclipse.debug.core.DebugEvent) DebugException(org.eclipse.debug.core.DebugException) IProcess(org.eclipse.debug.core.model.IProcess) Date(java.util.Date)

Aggregations

IStreamMonitor (org.eclipse.debug.core.model.IStreamMonitor)10 IStreamListener (org.eclipse.debug.core.IStreamListener)9 IProcess (org.eclipse.debug.core.model.IProcess)5 IStreamsProxy (org.eclipse.debug.core.model.IStreamsProxy)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 CoreException (org.eclipse.core.runtime.CoreException)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 DebugEvent (org.eclipse.debug.core.DebugEvent)2 DebugException (org.eclipse.debug.core.DebugException)2 ILaunch (org.eclipse.debug.core.ILaunch)2 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 InputStream (java.io.InputStream)1 Formatter (java.util.Formatter)1 List (java.util.List)1