Search in sources :

Example 6 with IStreamsProxy

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

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

the class TomcatRuntime method checkForCompiler.

/**
 * Checks for the existence of the Java compiler in the given java
 * executable. A main program is run (<code>org.eclipse.jst.tomcat.core.
 * internal.ClassDetector</code>), that dumps a true or false value
 * depending on whether the compiler is found. This output is then
 * parsed and cached for future reference.
 *
 * @return true if the compiler was found
 */
protected boolean checkForCompiler() {
    // first try the cache
    File javaHome = getVMInstall().getInstallLocation();
    try {
        Boolean b = sdkMap.get(javaHome);
        return b.booleanValue();
    } catch (Exception e) {
    // ignore
    }
    // locate tomcatcore.jar - it contains the class detector main program
    File file = TomcatPlugin.getPlugin();
    if (file != null && file.exists()) {
        IVMRunner vmRunner = getVMInstall().getVMRunner(ILaunchManager.RUN_MODE);
        VMRunnerConfiguration config = new VMRunnerConfiguration("org.eclipse.jst.server.tomcat.core.internal.ClassDetector", new String[] { file.getAbsolutePath() });
        config.setProgramArguments(new String[] { "com.sun.tools.javac.Main" });
        ILaunch launch = new Launch(null, ILaunchManager.RUN_MODE, null);
        try {
            vmRunner.run(config, launch, null);
            for (int i = 0; i < 600; i++) {
                // wait no more than 30 seconds (600 * 50 mils)
                if (launch.isTerminated()) {
                    break;
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                // ignore
                }
            }
            IStreamsProxy streamsProxy = launch.getProcesses()[0].getStreamsProxy();
            String text = null;
            if (streamsProxy != null) {
                text = streamsProxy.getOutputStreamMonitor().getContents();
                if (text != null && text.length() > 0) {
                    boolean found = false;
                    if ("true".equals(text))
                        found = true;
                    sdkMap.put(javaHome, new Boolean(found));
                    return found;
                }
            }
        } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Error checking for JDK", e);
        } finally {
            if (!launch.isTerminated()) {
                try {
                    launch.terminate();
                } catch (Exception ex) {
                // ignore
                }
            }
        }
    }
    // log error that we were unable to check for the compiler
    TomcatPlugin.log(MessageFormat.format("Failed compiler check for {0}", (Object[]) new String[] { javaHome.getAbsolutePath() }));
    return false;
}
Also used : ILaunch(org.eclipse.debug.core.ILaunch) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) File(java.io.File) Launch(org.eclipse.debug.core.Launch) ILaunch(org.eclipse.debug.core.ILaunch) IOException(java.io.IOException)

Example 8 with IStreamsProxy

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

the class CliExecutor method executeNextTestElement.

/**
 * Executes the next testcase or control part whose name is stored in the execute list.
 */
private void executeNextTestElement() {
    if (JniExecutor.MC_READY != suspectedLastState) {
        createMainTestComponent();
        return;
    }
    if (executeList.isEmpty()) {
        return;
    }
    String testElement = executeList.remove(0);
    IStreamsProxy proxy = process.getStreamsProxy();
    if (proxy != null) {
        try {
            suspectedLastState = JniExecutor.MC_EXECUTING_TESTCASE;
            proxy.write(testElement);
            if ("smtc \n".equals(testElement)) {
                executingConfigFile = true;
            }
        } catch (IOException e) {
            ErrorReporter.logError(EXTERNAL_TERMINATION);
            terminate(true);
        }
    }
}
Also used : IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IOException(java.io.IOException)

Example 9 with IStreamsProxy

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

IStreamsProxy (org.eclipse.debug.core.model.IStreamsProxy)9 IOException (java.io.IOException)7 IStreamMonitor (org.eclipse.debug.core.model.IStreamMonitor)5 File (java.io.File)4 IStreamListener (org.eclipse.debug.core.IStreamListener)4 CoreException (org.eclipse.core.runtime.CoreException)3 ILaunch (org.eclipse.debug.core.ILaunch)3 IProcess (org.eclipse.debug.core.model.IProcess)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Launch (org.eclipse.debug.core.Launch)2 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)2 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Formatter (java.util.Formatter)1 IFile (org.eclipse.core.resources.IFile)1 LaunchElement (org.eclipse.titan.executor.views.executormonitor.LaunchElement)1 Notification (org.eclipse.titan.executor.views.notification.Notification)1 MessageConsole (org.eclipse.ui.console.MessageConsole)1