Search in sources :

Example 1 with AssociatedTargetNodePredicate

use of com.facebook.buck.rules.AssociatedTargetNodePredicate 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);
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) BuildTarget(com.facebook.buck.model.BuildTarget) AssociatedTargetNodePredicate(com.facebook.buck.rules.AssociatedTargetNodePredicate) ProjectConfigDescription(com.facebook.buck.rules.ProjectConfigDescription)

Aggregations

XcodeWorkspaceConfigDescription (com.facebook.buck.apple.XcodeWorkspaceConfigDescription)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 AssociatedTargetNodePredicate (com.facebook.buck.rules.AssociatedTargetNodePredicate)1 ProjectConfigDescription (com.facebook.buck.rules.ProjectConfigDescription)1 TargetNode (com.facebook.buck.rules.TargetNode)1