use of com.facebook.buck.util.Ansi in project buck by facebook.
the class Main method runMainThenExit.
/* Define all error handling surrounding main command */
private void runMainThenExit(String[] args, Optional<NGContext> context, final long initTimestamp) {
installUncaughtExceptionHandler(context);
Path projectRoot = Paths.get(".");
int exitCode = FAIL_EXIT_CODE;
BuildId buildId = getBuildId(context);
// Only post an overflow event if Watchman indicates a fresh instance event
// after our initial query.
WatchmanWatcher.FreshInstanceAction watchmanFreshInstanceAction = daemon == null ? WatchmanWatcher.FreshInstanceAction.NONE : WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT;
// Get the client environment, either from this process or from the Nailgun context.
ImmutableMap<String, String> clientEnvironment = getClientEnvironment(context);
try {
CommandMode commandMode = CommandMode.RELEASE;
exitCode = runMainWithExitCode(buildId, projectRoot, context, clientEnvironment, commandMode, watchmanFreshInstanceAction, initTimestamp, args);
} catch (IOException e) {
if (e.getMessage().startsWith("No space left on device")) {
(new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)))).printBuildFailure(e.getMessage());
} else {
LOG.error(e);
}
} catch (HumanReadableException e) {
Console console = new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)));
console.printBuildFailure(e.getHumanReadableErrorMessage());
} catch (InterruptionFailedException e) {
// Command could not be interrupted.
if (context.isPresent()) {
// Exit process to halt command execution.
context.get().getNGServer().shutdown(true);
}
} catch (BuckIsDyingException e) {
LOG.warn(e, "Fallout because buck was already dying");
} catch (Throwable t) {
LOG.error(t, "Uncaught exception at top level");
} finally {
LOG.debug("Done.");
LogConfig.flushLogs();
// Exit explicitly so that non-daemon threads (of which we use many) don't
// keep the VM alive.
System.exit(exitCode);
}
}
use of com.facebook.buck.util.Ansi in project buck by facebook.
the class CxxErrorTransformerFactoryTest method shouldProperlyTransformColoredLinesInErrorMessages.
@Test
public void shouldProperlyTransformColoredLinesInErrorMessages() {
Ansi ansi = new Ansi(/* isAnsiTerminal */
true);
assertThat(transformer.transformLine(String.format("%s something bad", ansi.asErrorText(originalPath + ":"))), equalTo(String.format("%s something bad", ansi.asErrorText(expectedPath + ":"))));
assertThat(transformer.transformLine(String.format("%s something bad", ansi.asErrorText(originalPath + ":4:"))), equalTo(String.format("%s something bad", ansi.asErrorText(expectedPath + ":4:"))));
assertThat(transformer.transformLine(String.format("%s something bad", ansi.asErrorText(originalPath + ":4:2:"))), equalTo(String.format("%s something bad", ansi.asErrorText(expectedPath + ":4:2:"))));
}
use of com.facebook.buck.util.Ansi in project buck by facebook.
the class BuildReport method generateForConsole.
public String generateForConsole(Console console) {
Ansi ansi = console.getAnsi();
Map<BuildRule, Optional<BuildResult>> ruleToResult = buildExecutionResult.getResults();
StringBuilder report = new StringBuilder();
for (Map.Entry<BuildRule, Optional<BuildResult>> entry : ruleToResult.entrySet()) {
BuildRule rule = entry.getKey();
Optional<BuildRuleSuccessType> success = Optional.empty();
Optional<BuildResult> result = entry.getValue();
if (result.isPresent()) {
success = Optional.ofNullable(result.get().getSuccess());
}
String successIndicator;
String successType;
SourcePath outputFile;
if (success.isPresent()) {
successIndicator = ansi.asHighlightedSuccessText("OK ");
successType = success.get().name();
outputFile = rule.getSourcePathToOutput();
} else {
successIndicator = ansi.asHighlightedFailureText("FAIL");
successType = null;
outputFile = null;
}
report.append(String.format("%s %s%s%s\n", successIndicator, rule.getBuildTarget(), successType != null ? " " + successType : "", outputFile != null ? " " + pathResolver.getRelativePath(outputFile) : ""));
}
if (!buildExecutionResult.getFailures().isEmpty() && console.getVerbosity().shouldPrintCommand()) {
report.append("\n ** Summary of failures encountered during the build **\n");
for (BuildResult failureResult : buildExecutionResult.getFailures()) {
Throwable failure = Preconditions.checkNotNull(failureResult.getFailure());
report.append(String.format("Rule %s FAILED because %s.\n", failureResult.getRule().getFullyQualifiedName(), failure.getMessage()));
}
}
return report.toString();
}
use of com.facebook.buck.util.Ansi in project buck by facebook.
the class TestResultFormatterTest method shouldUseDecimalCommaForGerman.
@Test
public void shouldUseDecimalCommaForGerman() {
TestResultFormatter formatter = new TestResultFormatter(new Ansi(false), Verbosity.COMMANDS, TestResultSummaryVerbosity.of(false, false), Locale.GERMAN, Optional.of(logPath), TimeZone.getTimeZone("America/Los_Angeles"));
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(new TestResultSummary("com.example.FooTest", "successTest", ResultType.SUCCESS, 12300, /*message*/
null, /*stacktrace*/
null, "good stdout", "good stderr")));
TestResults results = FakeTestResults.of(ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.reportResult(builder, results);
assertEquals("PASS 12,3s 1 Passed 0 Skipped 0 Failed com.example.FooTest", toString(builder));
}
Aggregations