Search in sources :

Example 1 with Ansi

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);
    }
}
Also used : ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) CommandMode(com.facebook.buck.util.environment.CommandMode) IOException(java.io.IOException) WatchmanWatcher(com.facebook.buck.util.WatchmanWatcher) InterruptionFailedException(com.facebook.buck.util.InterruptionFailedException) BuildId(com.facebook.buck.model.BuildId) BuckIsDyingException(com.facebook.buck.util.BuckIsDyingException) HumanReadableException(com.facebook.buck.util.HumanReadableException) Console(com.facebook.buck.util.Console) Ansi(com.facebook.buck.util.Ansi)

Example 2 with Ansi

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:"))));
}
Also used : Ansi(com.facebook.buck.util.Ansi) Test(org.junit.Test)

Example 3 with Ansi

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();
}
Also used : Optional(java.util.Optional) SourcePath(com.facebook.buck.rules.SourcePath) BuildResult(com.facebook.buck.rules.BuildResult) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) BuildRule(com.facebook.buck.rules.BuildRule) Ansi(com.facebook.buck.util.Ansi) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with Ansi

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));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Ansi(com.facebook.buck.util.Ansi) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Aggregations

Ansi (com.facebook.buck.util.Ansi)4 Test (org.junit.Test)2 BuildId (com.facebook.buck.model.BuildId)1 BuildResult (com.facebook.buck.rules.BuildResult)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleSuccessType (com.facebook.buck.rules.BuildRuleSuccessType)1 SourcePath (com.facebook.buck.rules.SourcePath)1 FakeTestResults (com.facebook.buck.test.FakeTestResults)1 TestCaseSummary (com.facebook.buck.test.TestCaseSummary)1 TestResultSummary (com.facebook.buck.test.TestResultSummary)1 TestResults (com.facebook.buck.test.TestResults)1 BuckIsDyingException (com.facebook.buck.util.BuckIsDyingException)1 Console (com.facebook.buck.util.Console)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 InterruptionFailedException (com.facebook.buck.util.InterruptionFailedException)1 WatchmanWatcher (com.facebook.buck.util.WatchmanWatcher)1 CommandMode (com.facebook.buck.util.environment.CommandMode)1 ImmutableList (com.google.common.collect.ImmutableList)1 ClassPath (com.google.common.reflect.ClassPath)1 IOException (java.io.IOException)1