use of com.facebook.buck.model.InMemoryBuildFileTree in project buck by facebook.
the class TargetsCommand method getMatchingNodes.
/**
* @param graph Graph used to resolve dependencies between targets and find all build files.
* @param referencedFiles If present, the result will be limited to the nodes that transitively
* depend on at least one of those.
* @param matchingBuildTargets If present, the result will be limited to the specified targets.
* @param buildRuleTypes If present, the result will be limited to targets with the specified
* types.
* @param detectTestChanges If true, tests are considered to be dependencies of the targets they
* are testing.
* @return A map of target names to target nodes.
*/
@VisibleForTesting
ImmutableSortedMap<String, TargetNode<?, ?>> getMatchingNodes(TargetGraph graph, Optional<ImmutableSet<Path>> referencedFiles, final Optional<ImmutableSet<BuildTarget>> matchingBuildTargets, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses, boolean detectTestChanges, String buildFileName) {
ImmutableSet<TargetNode<?, ?>> directOwners;
if (referencedFiles.isPresent()) {
BuildFileTree buildFileTree = new InMemoryBuildFileTree(graph.getNodes().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
directOwners = FluentIterable.from(graph.getNodes()).filter(new DirectOwnerPredicate(buildFileTree, referencedFiles.get(), buildFileName)).toSet();
} else {
directOwners = graph.getNodes();
}
Iterable<TargetNode<?, ?>> selectedReferrers = FluentIterable.from(getDependentNodes(graph, directOwners, detectTestChanges)).filter(targetNode -> {
if (matchingBuildTargets.isPresent() && !matchingBuildTargets.get().contains(targetNode.getBuildTarget())) {
return false;
}
if (descriptionClasses.isPresent() && !descriptionClasses.get().contains(targetNode.getDescription().getClass())) {
return false;
}
return true;
});
ImmutableSortedMap.Builder<String, TargetNode<?, ?>> matchingNodesBuilder = ImmutableSortedMap.naturalOrder();
for (TargetNode<?, ?> targetNode : selectedReferrers) {
matchingNodesBuilder.put(targetNode.getBuildTarget().getFullyQualifiedName(), targetNode);
}
return matchingNodesBuilder.build();
}
use of com.facebook.buck.model.InMemoryBuildFileTree in project buck by facebook.
the class ProjectTest method getModulesForActionGraph.
private ProjectWithModules getModulesForActionGraph(BuildRuleResolver ruleResolver, ImmutableSortedSet<ProjectConfig> projectConfigs, @Nullable JavaPackageFinder javaPackageFinder, @Nullable IntellijConfig intellijConfig) throws IOException {
if (javaPackageFinder == null) {
javaPackageFinder = new FakeJavaPackageFinder();
}
if (intellijConfig == null) {
intellijConfig = new IntellijConfig(FakeBuckConfig.builder().build());
}
// Create the Project.
ExecutionContext executionContext = TestExecutionContext.newInstance();
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
Properties keystoreProperties = new Properties();
keystoreProperties.put("key.alias", "androiddebugkey");
keystoreProperties.put("key.store.password", "android");
keystoreProperties.put("key.alias.password", "android");
try (OutputStream output = projectFilesystem.newFileOutputStream(Paths.get("keystore/debug.keystore.properties"))) {
keystoreProperties.store(output, "");
}
ImmutableMap<Path, String> basePathToAliasMap = ImmutableMap.of();
Project project = new Project(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver)), projectConfigs, basePathToAliasMap, javaPackageFinder, executionContext, new InMemoryBuildFileTree(Iterables.transform(ruleResolver.getBuildRules(), BuildRule::getBuildTarget)), projectFilesystem, /* pathToDefaultAndroidManifest */
Optional.empty(), intellijConfig, /* pathToPostProcessScript */
Optional.empty(), "python", ObjectMappers.newDefaultInstance(), true);
// Execute Project's business logic.
List<SerializableModule> modules = new ArrayList<>(project.createModulesForProjectConfigs());
return new ProjectWithModules(project, ImmutableList.copyOf(modules));
}
Aggregations