Search in sources :

Example 6 with IStreamListener

use of org.eclipse.debug.core.IStreamListener in project linuxtools by eclipse.

the class DockerComposeConsole method setDockerComposeProcess.

public void setDockerComposeProcess(final IProcess dockerComposeProcess) {
    this.dockerComposeProcess = dockerComposeProcess;
    // activate and clear the console if it has previous content
    activate();
    clearConsole();
    // catch up with the content that was already output by the Java Process
    writeContentInConsole(dockerComposeProcess.getStreamsProxy().getOutputStreamMonitor().getContents());
    // then follow the streams
    dockerComposeProcess.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {

        @Override
        public void streamAppended(final String text, final IStreamMonitor monitor) {
            writeContentInConsole(text);
        }
    });
    dockerComposeProcess.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {

        @Override
        public void streamAppended(final String text, final IStreamMonitor monitor) {
            writeContentInConsole(text);
        }
    });
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) StyledString(org.eclipse.jface.viewers.StyledString)

Example 7 with IStreamListener

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

the class ToolExecutor method run_0.

@Deprecated
public ToolResults run_0(final String cmd0, final String args, final String wdir, final ProgressCallback progressCallback, final BuildNotifier notifier) {
    final String cmd = new Path(cmd0).isAbsolute() ? cmd0 : ToolExecutor.getToolLocation(cmd0);
    if (cmd == null) {
        ErlLogger.warn("Tool '" + cmd0 + "' can't be found in $PATH");
        return new ToolResults();
    }
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    final ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE);
    if (type == null) {
        return null;
    }
    try {
        final ILaunchConfigurationWorkingCopy launchConfig = type.newInstance(null, launchManager.generateLaunchConfigurationName("erlTool"));
        launchConfig.setAttribute(IExternalToolConstants.ATTR_LOCATION, cmd);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, args);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, wdir);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
        launchConfig.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
        final ILaunch myLaunch = launchConfig.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor(), false, false);
        final ToolResults result = new ToolResults();
        if (myLaunch.getProcesses().length == 0) {
            ErlLogger.error("Tool process was not created?!");
            return null;
        }
        final IProcess process = myLaunch.getProcesses()[0];
        process.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor mon) {
                final List<String> lines = Arrays.asList(text.split("\n"));
                if (progressCallback != null) {
                    for (final String line : lines) {
                        progressCallback.stdout(line);
                    }
                }
            }
        });
        process.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor mon) {
                final List<String> lines = Arrays.asList(text.split("\n"));
                if (progressCallback != null) {
                    for (final String line : lines) {
                        progressCallback.stderr(line);
                    }
                }
            }
        });
        boolean done = false;
        try {
            Thread.sleep(60);
        } catch (final InterruptedException e1) {
        }
        final boolean canceled = notifier != null && notifier.isCanceled();
        while (!done && !canceled) {
            try {
                result.exit = process.getExitValue();
                done = true;
            } catch (final Exception e) {
                try {
                    Thread.sleep(60);
                } catch (final InterruptedException e1) {
                }
            }
        }
        if (canceled) {
            process.terminate();
        }
        return result;
    } catch (final CoreException e) {
        ErlLogger.error(e);
        return null;
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IStreamListener(org.eclipse.debug.core.IStreamListener) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) CoreException(org.eclipse.core.runtime.CoreException) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.eclipse.debug.core.model.IProcess)

Example 8 with IStreamListener

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

the class Backend method getShell.

@Override
public IBackendShell getShell(final String id) {
    final IBackendShell shell = shellManager.openShell(id);
    final IStreamsProxy proxy = getStreamsProxy();
    if (proxy != null) {
        final IStreamMonitor errorStreamMonitor = proxy.getErrorStreamMonitor();
        errorStreamMonitor.addListener(new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor monitor) {
                shell.add(text, IoRequestKind.STDERR);
            }
        });
        final IStreamMonitor outputStreamMonitor = proxy.getOutputStreamMonitor();
        outputStreamMonitor.addListener(new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor monitor) {
                shell.add(text, IoRequestKind.STDOUT);
            }
        });
    }
    return shell;
}
Also used : IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) IStreamListener(org.eclipse.debug.core.IStreamListener) IBackendShell(org.erlide.runtime.shell.IBackendShell) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy)

Example 9 with IStreamListener

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

the class SingleExecutor method createProcess.

/**
 * Executes the executable parameterized with the configuration file describing the test session.
 *
 *@param actualConfigPath the path of the configuration file to call the executable with.
 *
 * @see #startExecution(boolean)
 */
private void createProcess(final String actualConfigPath) {
    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);
        }
    }
    final File executableFile = new File(executablePath);
    if (!executableFile.exists()) {
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog.openError(null, "Execution failed", "The executable `" + executableFile + "' does not exist.");
            }
        });
    }
    EnvironmentHelper.setTitanPath(env);
    EnvironmentHelper.set_LICENSE_FILE_PATH(env);
    EnvironmentHelper.set_LD_LIBRARY_PATH(DynamicLinkingHelper.getProject(projectName), env);
    MessageConsole console = TITANDebugConsole.getConsole();
    List<String> command = new ArrayList<String>();
    command.add("sh");
    command.add("-c");
    command.add(" sleep 1; cd '" + PathConverter.convert(workingdirectoryPath, true, console) + "'; '" + PathConverter.convert(executablePath, true, console) + "' '" + PathConverter.convert(actualConfigPath, true, console) + "'");
    MessageConsoleStream stream = TITANConsole.getConsole().newMessageStream();
    for (String c : command) {
        stream.print(c + ' ');
    }
    stream.println();
    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);
    }
    try {
        proc = pb.start();
        if (null != mainControllerRoot) {
            ILaunch launch = ((LaunchElement) mainControllerRoot.parent()).launch();
            process = DebugPlugin.newProcess(launch, proc, MAIN_CONTROLLER);
        }
        IStreamsProxy proxy = process.getStreamsProxy();
        if (null != proxy) {
            IStreamMonitor outputstreammonitor = proxy.getOutputStreamMonitor();
            IStreamListener listener = new IStreamListener() {

                @Override
                public void streamAppended(final String text, final IStreamMonitor monitor) {
                    processConsoleOutput(text);
                }
            };
            if (null != outputstreammonitor) {
                String temp = outputstreammonitor.getContents();
                processConsoleOutput(temp);
                outputstreammonitor.addListener(listener);
            }
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        proc = null;
    }
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) MessageConsole(org.eclipse.ui.console.MessageConsole) ArrayList(java.util.ArrayList) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IOException(java.io.IOException) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) CoreException(org.eclipse.core.runtime.CoreException) ILaunch(org.eclipse.debug.core.ILaunch) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IFile(org.eclipse.core.resources.IFile) File(java.io.File) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement)

Aggregations

IStreamListener (org.eclipse.debug.core.IStreamListener)9 IStreamMonitor (org.eclipse.debug.core.model.IStreamMonitor)9 IProcess (org.eclipse.debug.core.model.IProcess)5 IStreamsProxy (org.eclipse.debug.core.model.IStreamsProxy)4 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