Search in sources :

Example 1 with HasClasspathEntries

use of com.facebook.buck.jvm.java.HasClasspathEntries in project buck by facebook.

the class AuditClasspathCommand method printJsonClasspath.

@VisibleForTesting
int printJsonClasspath(CommandRunnerParams params, TargetGraph targetGraph, ImmutableSet<BuildTarget> targets) throws IOException, NoSuchBuildTargetException, InterruptedException, VersionException {
    if (params.getBuckConfig().getBuildVersions()) {
        targetGraph = toVersionedTargetGraph(params, TargetGraphAndBuildTargets.of(targetGraph, targets)).getTargetGraph();
    }
    BuildRuleResolver resolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraph)).getResolver();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Multimap<String, String> targetClasspaths = LinkedHashMultimap.create();
    for (BuildTarget target : targets) {
        BuildRule rule = Preconditions.checkNotNull(resolver.requireRule(target));
        HasClasspathEntries hasClasspathEntries = getHasClasspathEntriesFrom(rule);
        if (hasClasspathEntries == null) {
            continue;
        }
        targetClasspaths.putAll(target.getFullyQualifiedName(), hasClasspathEntries.getTransitiveClasspaths().stream().map(pathResolver::getAbsolutePath).map(Object::toString).collect(MoreCollectors.toImmutableList()));
    }
    // Note: using `asMap` here ensures that the keys are sorted
    params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetClasspaths.asMap());
    return 0;
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) HasClasspathEntries(com.facebook.buck.jvm.java.HasClasspathEntries) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with HasClasspathEntries

use of com.facebook.buck.jvm.java.HasClasspathEntries in project buck by facebook.

the class AuditClasspathCommand method printClasspath.

@VisibleForTesting
int printClasspath(CommandRunnerParams params, TargetGraph targetGraph, ImmutableSet<BuildTarget> targets) throws NoSuchBuildTargetException, InterruptedException, VersionException {
    if (params.getBuckConfig().getBuildVersions()) {
        targetGraph = toVersionedTargetGraph(params, TargetGraphAndBuildTargets.of(targetGraph, targets)).getTargetGraph();
    }
    BuildRuleResolver resolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraph)).getResolver();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    SortedSet<Path> classpathEntries = Sets.newTreeSet();
    for (BuildTarget target : targets) {
        BuildRule rule = Preconditions.checkNotNull(resolver.requireRule(target));
        HasClasspathEntries hasClasspathEntries = getHasClasspathEntriesFrom(rule);
        if (hasClasspathEntries != null) {
            classpathEntries.addAll(pathResolver.getAllAbsolutePaths(hasClasspathEntries.getTransitiveClasspaths()));
        } else {
            throw new HumanReadableException(rule.getFullyQualifiedName() + " is not a java-based" + " build target");
        }
    }
    for (Path path : classpathEntries) {
        params.getConsole().getStdOut().println(path);
    }
    return 0;
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) HasClasspathEntries(com.facebook.buck.jvm.java.HasClasspathEntries) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HasClasspathEntries (com.facebook.buck.jvm.java.HasClasspathEntries)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRule (com.facebook.buck.rules.BuildRule)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 Path (java.nio.file.Path)1