use of com.facebook.buck.rules.ProjectConfigDescription in project buck by facebook.
the class AbstractProjectPredicates method forIde.
/**
* Creates a {@link ProjectPredicates} value type configured for
* the specified IDE.
*/
public static ProjectPredicates forIde(ProjectCommand.Ide targetIde) {
Predicate<TargetNode<?, ?>> projectRootsPredicate;
AssociatedTargetNodePredicate associatedProjectPredicate;
// Prepare the predicates to create the project graph based on the IDE.
switch(targetIde) {
case INTELLIJ:
projectRootsPredicate = input -> input.getDescription() instanceof ProjectConfigDescription;
associatedProjectPredicate = (targetNode, targetGraph) -> {
ProjectConfigDescription.Arg projectArg;
if (targetNode.getDescription() instanceof ProjectConfigDescription) {
projectArg = (ProjectConfigDescription.Arg) targetNode.getConstructorArg();
} else {
return false;
}
BuildTarget projectTarget = null;
if (projectArg.srcTarget.isPresent()) {
projectTarget = projectArg.srcTarget.get();
} else if (projectArg.testTarget.isPresent()) {
projectTarget = projectArg.testTarget.get();
}
return (projectTarget != null && targetGraph.getOptional(projectTarget).isPresent());
};
break;
case XCODE:
projectRootsPredicate = input -> input.getDescription() instanceof XcodeWorkspaceConfigDescription;
associatedProjectPredicate = (targetNode, targetGraph) -> false;
break;
default:
// unreachable
throw new IllegalStateException("'ide' should always be of type 'INTELLIJ' or 'XCODE'");
}
return ProjectPredicates.of(projectRootsPredicate, associatedProjectPredicate);
}
Aggregations