Search in sources :

Example 1 with DirtyPrintStreamDecorator

use of com.facebook.buck.util.DirtyPrintStreamDecorator in project buck by facebook.

the class DoctorReportHelper method presentResponse.

public final void presentResponse(DoctorEndpointResponse response) {
    DirtyPrintStreamDecorator output = console.getStdOut();
    if (response.getErrorMessage().isPresent() && !response.getErrorMessage().get().isEmpty()) {
        LOG.warn(response.getErrorMessage().get());
        output.println("=> " + response.getErrorMessage().get());
        return;
    }
    if (response.getSuggestions().isEmpty()) {
        output.println(console.getAnsi().asWarningText("\n:: No available suggestions right now."));
    } else {
        output.println(console.getAnsi().asInformationText("\n:: Suggestions"));
        response.getSuggestions().forEach(this::prettyPrintSuggestion);
    }
    output.println();
}
Also used : DirtyPrintStreamDecorator(com.facebook.buck.util.DirtyPrintStreamDecorator)

Example 2 with DirtyPrintStreamDecorator

use of com.facebook.buck.util.DirtyPrintStreamDecorator in project buck by facebook.

the class AuditFlavorsCommand method printFlavors.

private void printFlavors(ImmutableList<TargetNode<?, ?>> targetNodes, CommandRunnerParams params) {
    DirtyPrintStreamDecorator stdout = params.getConsole().getStdOut();
    for (TargetNode<?, ?> node : targetNodes) {
        Description<?> description = node.getDescription();
        stdout.println(node.getBuildTarget().getFullyQualifiedName());
        if (description instanceof Flavored) {
            Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains = ((Flavored) description).flavorDomains();
            if (flavorDomains.isPresent()) {
                for (FlavorDomain<?> domain : flavorDomains.get()) {
                    ImmutableSet<UserFlavor> userFlavors = RichStream.from(domain.getFlavors().stream()).filter(UserFlavor.class).collect(MoreCollectors.toImmutableSet());
                    if (userFlavors.isEmpty()) {
                        continue;
                    }
                    stdout.printf(" %s\n", domain.getName());
                    for (UserFlavor flavor : userFlavors) {
                        String flavorLine = String.format("  %s", flavor.getName());
                        String flavorDescription = flavor.getDescription();
                        if (flavorDescription.length() > 0) {
                            flavorLine += String.format(" -> %s", flavorDescription);
                        }
                        flavorLine += "\n";
                        stdout.printf(flavorLine);
                    }
                }
            } else {
                stdout.println(" unknown");
            }
        } else {
            stdout.println(" no flavors");
        }
    }
}
Also used : Flavored(com.facebook.buck.model.Flavored) ImmutableSet(com.google.common.collect.ImmutableSet) UserFlavor(com.facebook.buck.model.UserFlavor) DirtyPrintStreamDecorator(com.facebook.buck.util.DirtyPrintStreamDecorator)

Example 3 with DirtyPrintStreamDecorator

use of com.facebook.buck.util.DirtyPrintStreamDecorator in project buck by facebook.

the class AuditFlavorsCommand method printJsonFlavors.

private void printJsonFlavors(ImmutableList<TargetNode<?, ?>> targetNodes, CommandRunnerParams params) throws IOException {
    DirtyPrintStreamDecorator stdout = params.getConsole().getStdOut();
    SortedMap<String, SortedMap<String, SortedMap<String, String>>> targetsJson = new TreeMap<>();
    for (TargetNode<?, ?> node : targetNodes) {
        Description<?> description = node.getDescription();
        SortedMap<String, SortedMap<String, String>> flavorDomainsJson = new TreeMap<>();
        if (description instanceof Flavored) {
            Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains = ((Flavored) description).flavorDomains();
            if (flavorDomains.isPresent()) {
                for (FlavorDomain<?> domain : flavorDomains.get()) {
                    ImmutableSet<UserFlavor> userFlavors = RichStream.from(domain.getFlavors().stream()).filter(UserFlavor.class).collect(MoreCollectors.toImmutableSet());
                    if (userFlavors.isEmpty()) {
                        continue;
                    }
                    SortedMap<String, String> flavorsJson = userFlavors.stream().collect(MoreCollectors.toImmutableSortedMap(UserFlavor::getName, UserFlavor::getDescription));
                    flavorDomainsJson.put(domain.getName(), flavorsJson);
                }
            } else {
                flavorDomainsJson.put("unknown", new TreeMap<>());
            }
        }
        String targetName = node.getBuildTarget().getFullyQualifiedName();
        targetsJson.put(targetName, flavorDomainsJson);
    }
    params.getObjectMapper().writeValue(stdout, targetsJson);
}
Also used : TreeMap(java.util.TreeMap) Flavored(com.facebook.buck.model.Flavored) ImmutableSet(com.google.common.collect.ImmutableSet) SortedMap(java.util.SortedMap) UserFlavor(com.facebook.buck.model.UserFlavor) DirtyPrintStreamDecorator(com.facebook.buck.util.DirtyPrintStreamDecorator)

Aggregations

DirtyPrintStreamDecorator (com.facebook.buck.util.DirtyPrintStreamDecorator)3 Flavored (com.facebook.buck.model.Flavored)2 UserFlavor (com.facebook.buck.model.UserFlavor)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1