use of com.facebook.buck.model.BuildTargetPattern in project buck by facebook.
the class BuildTargetPatternParserTest method testParseRootPattern.
@Test
public void testParseRootPattern() throws NoSuchBuildTargetException {
BuildTargetPatternParser<BuildTargetPattern> buildTargetPatternParser = BuildTargetPatternParser.forVisibilityArgument();
assertEquals(new ImmediateDirectoryBuildTargetPattern(filesystem.getRootPath(), vfs.getPath("")), buildTargetPatternParser.parse(createCellRoots(filesystem), "//:"));
assertEquals(new SingletonBuildTargetPattern(filesystem.getRootPath(), "//:parser"), buildTargetPatternParser.parse(createCellRoots(filesystem), "//:parser"));
assertEquals(new SubdirectoryBuildTargetPattern(filesystem.getRootPath(), vfs.getPath("")), buildTargetPatternParser.parse(createCellRoots(filesystem), "//..."));
}
use of com.facebook.buck.model.BuildTargetPattern 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