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();
}
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;
}
}
Aggregations