Search in sources :

Example 1 with IStreamsProxy

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

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

the class PreviewLaunchConfigurationDelegate method getJavaExecutable.

/**
 * @return the File representing the Java Runtime's executable. A
 *         heuristic is used to avoid a hard dependency on JDT and its
 *         "Installed JREs" preferences. page.
 */
protected static File getJavaExecutable() {
    // $NON-NLS-1$
    String home = System.getProperty("java.home");
    if (Platform.getOS().equals(Constants.OS_MACOSX)) {
        /*
			 * See "Important Java Directories on Mac OS X", at
			 * https://developer.apple.com/library/content/qa/qa1170/_index.
			 * html
			 *
			 * The following is liberally borrowed from
			 * org.eclipse.jdt.internal.launching.LaunchingPlugin
			 */
        Process p = null;
        try {
            // $NON-NLS-1$
            p = DebugPlugin.exec(new String[] { "/usr/libexec/java_home" }, null, new String[0]);
            // $NON-NLS-1$
            IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Looking for the user's enabled and preferred JVMs");
            for (int i = 0; i < 600; i++) {
                // Wait no more than 30 seconds (600 * 50 milliseconds)
                if (process.isTerminated()) {
                    break;
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                // just keep sleeping
                }
            }
            IStreamsProxy streamsProxy = process.getStreamsProxy();
            String text = null;
            if (streamsProxy != null) {
                text = streamsProxy.getOutputStreamMonitor().getContents().trim();
            }
            if (text != null && text.length() > 0) {
                home = text;
            }
        } catch (CoreException ioe) {
        // fall through
        } finally {
            if (p != null) {
                p.destroy();
            }
        }
        if (home == null) {
            // $NON-NLS-1$
            home = "/Library/Java/Home";
        }
    }
    // retrieve the 'java.home' system property. If that directory doesn't exist, return null
    File javaHome;
    try {
        javaHome = new File(home).getCanonicalFile();
    } catch (IOException e) {
        return null;
    }
    if (!javaHome.exists())
        return null;
    // found, return null
    return findJavaExecutable(javaHome);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProcess(org.eclipse.debug.core.model.IProcess) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IOException(java.io.IOException) IProcess(org.eclipse.debug.core.model.IProcess) Launch(org.eclipse.debug.core.Launch) ILaunch(org.eclipse.debug.core.ILaunch) File(java.io.File)

Example 3 with IStreamsProxy

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

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

the class CliExecutor method createMainTestComponent.

/**
 * Creates the Main Test Component.
 */
private void createMainTestComponent() {
    createMTCRequested = true;
    switch(suspectedLastState) {
        case JniExecutor.MC_INACTIVE:
        case JniExecutor.MC_LISTENING:
        case JniExecutor.MC_LISTENING_CONFIGURED:
            startHostControllers();
            return;
        default:
            break;
    }
    IStreamsProxy proxy = process.getStreamsProxy();
    if (proxy != null) {
        try {
            proxy.write("cmtc \n");
            createMTCRequested = false;
        } catch (IOException e) {
            ErrorReporter.logError(EXTERNAL_TERMINATION);
            terminate(true);
        }
    }
}
Also used : IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IOException(java.io.IOException)

Example 5 with IStreamsProxy

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

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