Search in sources :

Example 11 with LaunchElement

use of org.eclipse.titan.executor.views.executormonitor.LaunchElement in project titan.EclipsePlug-ins by eclipse.

the class SingleExecutor method terminate.

@Override
public void terminate(final boolean external) {
    isrunning = false;
    startExecutionAction.setEnabled(false);
    if (mainControllerRoot != null) {
        mainControllerRoot.setTerminated();
        LaunchElement launchElement = null;
        boolean terminatedNaturally = false;
        for (Map.Entry<ILaunch, BaseExecutor> entry : ExecutorStorage.getExecutorMap().entrySet()) {
            if (entry.getValue().equals(mainControllerRoot.executor())) {
                terminatedNaturally = entry.getKey().isTerminated();
                if (LaunchStorage.getLaunchElementMap().containsKey(entry.getKey())) {
                    launchElement = LaunchStorage.getLaunchElementMap().get(entry.getKey());
                }
            }
        }
        if (launchElement != null && !terminatedNaturally && proc != null) {
            proc.destroy();
            try {
                process.terminate();
            } catch (DebugException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            launchElement.setTerminated();
        }
    }
    if (!keepTemporarilyGeneratedConfigFiles && temporalConfigFile != null) {
        boolean result = temporalConfigFile.delete();
        if (!result) {
            ErrorReporter.logError("The temporal configuration file " + temporalConfigFile.getName() + " could not be deleted");
            return;
        }
    }
    super.shutdownSession();
    temporalConfigFile = null;
    if (Activator.getMainView() != null) {
        Activator.getMainView().refreshAll();
    }
    saveLastTimeUsageInfo();
}
Also used : BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) ILaunch(org.eclipse.debug.core.ILaunch) DebugException(org.eclipse.debug.core.DebugException) Map(java.util.Map) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement)

Example 12 with LaunchElement

use of org.eclipse.titan.executor.views.executormonitor.LaunchElement 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

LaunchElement (org.eclipse.titan.executor.views.executormonitor.LaunchElement)12 BaseExecutor (org.eclipse.titan.executor.executors.BaseExecutor)7 ITreeLeaf (org.eclipse.titan.executor.executors.ITreeLeaf)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 MainControllerElement (org.eclipse.titan.executor.views.executormonitor.MainControllerElement)4 ILaunch (org.eclipse.debug.core.ILaunch)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 ISelection (org.eclipse.jface.viewers.ISelection)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 DebugException (org.eclipse.debug.core.DebugException)1