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;
}
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;
}
Aggregations