use of com.intellij.execution.testframework.Printable in project intellij-community by JetBrains.
the class ExecutionHandler method processRunningAnt.
private static void processRunningAnt(final ProgressIndicator progress, final AntProcessHandler handler, final AntBuildMessageView errorView, final AntBuildFileBase buildFile, final long startTime, final AntBuildListener antBuildListener) {
final Project project = buildFile.getProject();
final StatusBar statusbar = WindowManager.getInstance().getStatusBar(project);
if (statusbar != null) {
statusbar.setInfo(AntBundle.message("ant.build.started.status.message"));
}
final CheckCancelTask checkCancelTask = new CheckCancelTask(progress, handler);
checkCancelTask.start(0);
final OutputParser parser = OutputParser2.attachParser(project, handler, errorView, progress, buildFile);
handler.addProcessListener(new ProcessAdapter() {
private final StringBuilder myUnprocessedStdErr = new StringBuilder();
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDERR) {
final String text = event.getText();
synchronized (myUnprocessedStdErr) {
myUnprocessedStdErr.append(text);
}
}
}
public void processTerminated(ProcessEvent event) {
final long buildTime = System.currentTimeMillis() - startTime;
checkCancelTask.cancel();
parser.setStopped(true);
final OutputPacketProcessor dispatcher = handler.getErr().getEventsDispatcher();
try {
if (event.getExitCode() != 0) {
// in case process exits abnormally, provide all unprocessed stderr content
final String unprocessed;
synchronized (myUnprocessedStdErr) {
unprocessed = myUnprocessedStdErr.toString();
myUnprocessedStdErr.setLength(0);
}
if (!unprocessed.isEmpty()) {
dispatcher.processOutput(new Printable() {
public void printOn(Printer printer) {
errorView.outputError(unprocessed, AntBuildMessageView.PRIORITY_ERR);
}
});
}
} else {
synchronized (myUnprocessedStdErr) {
myUnprocessedStdErr.setLength(0);
}
}
} finally {
errorView.buildFinished(progress != null && progress.isCanceled(), buildTime, antBuildListener, dispatcher);
}
}
});
handler.startNotify();
}
use of com.intellij.execution.testframework.Printable in project intellij-plugins by JetBrains.
the class FlexUnitExecutionTest method checkOutput.
private static void checkOutput(AbstractTestProxy testProxy, @Nullable FlexUnitRunnerParameters.OutputLogLevel logLevel) {
final StringBuilder stdout = new StringBuilder();
final StringBuilder stderr = new StringBuilder();
final StringBuilder system = new StringBuilder();
testProxy.printOn(new Printer() {
@Override
public void print(String text, ConsoleViewContentType contentType) {
if (contentType == ConsoleViewContentType.NORMAL_OUTPUT) {
stdout.append(text);
} else if (contentType == ConsoleViewContentType.ERROR_OUTPUT) {
stderr.append(text);
} else if (contentType == ConsoleViewContentType.SYSTEM_OUTPUT) {
system.append(text);
} else {
assert false;
}
}
@Override
public void onNewAvailable(@NotNull Printable printable) {
printable.printOn(this);
}
@Override
public void printHyperlink(String text, HyperlinkInfo info) {
}
@Override
public void mark() {
}
});
if (logLevel == null) {
Assert.assertTrue("Test std output should be empty but was '" + stdout + "'", stdout.length() == 0);
} else {
for (FlexUnitRunnerParameters.OutputLogLevel level : FlexUnitRunnerParameters.OutputLogLevel.values()) {
String message = LOG_MESSAGES.get(level);
if (message != null) {
if (level.ordinal() <= logLevel.ordinal()) {
Assert.assertTrue("Expected message '" + message + "' was not found in test output '" + stdout + "'", stdout.indexOf(message) != -1);
} else {
Assert.assertTrue("Message '" + message + "' was not expected in test output '" + stdout + "'", stdout.indexOf(message) == -1);
}
}
}
}
}
use of com.intellij.execution.testframework.Printable in project intellij-community by JetBrains.
the class AntBuildMessageView method buildFinished.
void buildFinished(boolean isProgressAborted, final long buildTimeInMilliseconds, @NotNull final AntBuildListener antBuildListener, OutputPacketProcessor dispatcher) {
final boolean aborted = isProgressAborted || myIsAborted;
dispatcher.processOutput(new Printable() {
@Override
public void printOn(Printer printer) {
if (!myProject.isDisposed()) {
// if not disposed
final String message = getFinishStatusText(aborted, buildTimeInMilliseconds);
addCommand(new FinishBuildCommand(message));
final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.setInfo(message);
}
final AntBuildFileBase buildFile = myBuildFile;
final boolean isBackground = buildFile != null && buildFile.isRunInBackground();
final boolean shouldActivate = !isBackground || getErrorCount() > 0;
UIUtil.invokeLaterIfNeeded(() -> {
final Runnable finishRunnable = () -> {
final int errorCount = getErrorCount();
try {
final AntBuildFileBase buildFile1 = myBuildFile;
if (buildFile1 != null) {
if (errorCount == 0 && buildFile1.isViewClosedWhenNoErrors()) {
close();
} else if (errorCount > 0) {
myTreeView.scrollToFirstError();
} else {
myTreeView.scrollToStatus();
}
} else {
myTreeView.scrollToLastMessage();
}
} finally {
VirtualFileManager.getInstance().asyncRefresh(() -> antBuildListener.buildFinished(aborted ? AntBuildListener.ABORTED : AntBuildListener.FINISHED_SUCCESSFULLY, errorCount));
}
};
if (shouldActivate) {
final ToolWindow toolWindow = !myProject.isDisposed() ? ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW) : null;
if (toolWindow != null) {
// can be null if project is closed
toolWindow.activate(finishRunnable, false);
} else {
finishRunnable.run();
}
} else {
finishRunnable.run();
}
});
}
}
});
ApplicationManager.getApplication().invokeLater(() -> flushWhenSmart(false), ModalityState.any(), myProject.getDisposed());
}
use of com.intellij.execution.testframework.Printable in project intellij-community by JetBrains.
the class SMTRunnerConsoleTest method testPrintTestProxy.
public void testPrintTestProxy() {
mySimpleTest.setPrinter(myMockResettablePrinter);
mySimpleTest.addLast(new Printable() {
@Override
public void printOn(final Printer printer) {
printer.print("std out", ConsoleViewContentType.NORMAL_OUTPUT);
printer.print("std err", ConsoleViewContentType.ERROR_OUTPUT);
printer.print("std sys", ConsoleViewContentType.SYSTEM_OUTPUT);
}
});
assertAllOutputs(myMockResettablePrinter, "std out", "std err", "std sys");
}
Aggregations