use of com.facebook.buck.query.QueryBuildTarget 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();
});
}
Aggregations