use of com.facebook.buck.query.QueryException in project buck by facebook.
the class QueryUtils method resolveDepQuery.
public static Stream<BuildRule> resolveDepQuery(BuildRuleParams params, Query query, BuildRuleResolver resolver, TargetGraph targetGraph) {
BuildTarget target = params.getBuildTarget();
Set<BuildTarget> declaredDeps = params.getDeclaredDeps().get().stream().map(BuildRule::getBuildTarget).collect(Collectors.toSet());
GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.of(resolver), Optional.of(targetGraph), params.getCellRoots(), BuildTargetPatternParser.forBaseName(target.getBaseName()), declaredDeps);
ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
try {
QueryExpression parsedExp = QueryExpression.parse(query.getQuery(), env);
Set<QueryTarget> queryTargets = parsedExp.eval(env, executorService);
return queryTargets.stream().map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget());
});
} catch (QueryException e) {
throw new RuntimeException("Error parsing/executing query from deps for " + target, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Error executing query from deps for " + target, e);
}
}
use of com.facebook.buck.query.QueryException 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