Search in sources :

Example 1 with BuildTargetPatternParser

use of com.facebook.buck.parser.BuildTargetPatternParser in project buck by facebook.

the class QueryUtils method extractBuildTargets.

public static Stream<BuildTarget> extractBuildTargets(CellPathResolver cellPathResolver, BuildTargetPatternParser<BuildTargetPattern> parserPattern, Query query) throws QueryException {
    GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.empty(), Optional.empty(), cellPathResolver, parserPattern, ImmutableSet.of());
    ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
    QueryExpression parsedExp = QueryExpression.parse(query.getQuery(), env);
    List<String> targetLiterals = new ArrayList<>();
    parsedExp.collectTargetPatterns(targetLiterals);
    return targetLiterals.stream().flatMap(pattern -> {
        try {
            return env.getTargetsMatchingPattern(pattern, executorService).stream();
        } catch (Exception e) {
            throw new RuntimeException("Error parsing target expression", e);
        }
    }).map(queryTarget -> {
        Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
        return ((QueryBuildTarget) queryTarget).getBuildTarget();
    });
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ImmutableSet(com.google.common.collect.ImmutableSet) CellPathResolver(com.facebook.buck.rules.CellPathResolver) QueryException(com.facebook.buck.query.QueryException) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) BuildRule(com.facebook.buck.rules.BuildRule) List(java.util.List) BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) Stream(java.util.stream.Stream) QueryExpression(com.facebook.buck.query.QueryExpression) BuildTargetPatternParser(com.facebook.buck.parser.BuildTargetPatternParser) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget) QueryTarget(com.facebook.buck.query.QueryTarget) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ArrayList(java.util.ArrayList) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) QueryExpression(com.facebook.buck.query.QueryExpression) QueryException(com.facebook.buck.query.QueryException) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetPattern (com.facebook.buck.model.BuildTargetPattern)1 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)1 QueryBuildTarget (com.facebook.buck.query.QueryBuildTarget)1 QueryException (com.facebook.buck.query.QueryException)1 QueryExpression (com.facebook.buck.query.QueryExpression)1 QueryTarget (com.facebook.buck.query.QueryTarget)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 CellPathResolver (com.facebook.buck.rules.CellPathResolver)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1