use of org.eclipse.debug.core.model.IStreamMonitor 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);
}
}
use of org.eclipse.debug.core.model.IStreamMonitor 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();
}
}
use of org.eclipse.debug.core.model.IStreamMonitor 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;
}
use of org.eclipse.debug.core.model.IStreamMonitor in project mdw-designer by CenturyLinkCloud.
the class GherkinTestCaseLaunch method run.
@Override
public void run() {
synchronized (lock) {
try {
launchConfig = getLaunchConfiguration();
IDebugEventSetListener listener = new IDebugEventSetListener() {
public void handleDebugEvents(DebugEvent[] events) {
for (DebugEvent event : events) {
if (event.getSource() instanceof IProcess) {
IProcess process = (IProcess) event.getSource();
if (event.getKind() == DebugEvent.CREATE) {
process.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {
public void streamAppended(String text, IStreamMonitor monitor) {
log.print(text);
if (text.equals("===== execute case " + getTestCase().getCaseName() + "\r\n"))
getTestCase().setStatus(TestCase.STATUS_RUNNING);
getTestCase().setStartDate(new Date());
}
});
process.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {
public void streamAppended(String text, IStreamMonitor monitor) {
log.print(text);
}
});
} else if (event.getKind() == DebugEvent.TERMINATE && process.getLaunch().getLaunchConfiguration().equals(launchConfig) && process.isTerminated() && true) {
getTestCase().setEndDate(new Date());
try {
if (process.getExitValue() == 0) {
getTestCase().setStatus(TestCase.STATUS_PASS);
} else {
String exitMsg = "Cucumber exit code: " + process.getExitValue();
log.println(exitMsg);
// TODO why
setMessage(exitMsg);
// not
// displayed?
getTestCase().setStatus(TestCase.STATUS_FAIL);
}
if (log != System.out)
log.close();
} catch (DebugException ex) {
PluginMessages.log(ex);
ex.printStackTrace(log);
getTestCase().setStatus(TestCase.STATUS_ERROR);
if (log != System.out)
log.close();
}
}
}
}
}
};
DebugPlugin.getDefault().addDebugEventListener(listener);
DebugUITools.launch(launchConfig, ILaunchManager.RUN_MODE);
} catch (Throwable ex) {
PluginMessages.log(ex);
ex.printStackTrace(log);
getTestCase().setStatus(TestCase.STATUS_ERROR);
getTestCase().setEndDate(new Date());
if (log != System.out)
log.close();
}
}
}
use of org.eclipse.debug.core.model.IStreamMonitor in project mdw-designer by CenturyLinkCloud.
the class CucumberLaunchListener method handleDebugEvents.
public void handleDebugEvents(DebugEvent[] events) {
for (DebugEvent event : events) {
if (event.getSource() instanceof IProcess) {
IProcess process = (IProcess) event.getSource();
if (event.getKind() == DebugEvent.CREATE) {
process.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {
public void streamAppended(String text, IStreamMonitor monitor) {
System.out.print(text);
if (!running) {
running = true;
start = new Date();
}
}
});
process.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {
public void streamAppended(String text, IStreamMonitor monitor) {
System.out.print(text);
}
});
} else if (event.getKind() == DebugEvent.TERMINATE && process.getLaunch().getLaunchConfiguration().equals(launchConfig) && process.isTerminated() && true) {
end = new Date();
try {
int exitCode = process.getExitValue();
if (exitCode == 0) {
status = TestCase.STATUS_PASS;
} else {
status = TestCase.STATUS_FAIL;
}
} catch (DebugException ex) {
PluginMessages.log(ex);
status = TestCase.STATUS_ERROR;
}
}
}
}
}
Aggregations