Search in sources :

Example 6 with BuildTargetPattern

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), "//..."));
}
Also used : SubdirectoryBuildTargetPattern(com.facebook.buck.model.SubdirectoryBuildTargetPattern) ImmediateDirectoryBuildTargetPattern(com.facebook.buck.model.ImmediateDirectoryBuildTargetPattern) BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) SingletonBuildTargetPattern(com.facebook.buck.model.SingletonBuildTargetPattern) ImmediateDirectoryBuildTargetPattern(com.facebook.buck.model.ImmediateDirectoryBuildTargetPattern) SingletonBuildTargetPattern(com.facebook.buck.model.SingletonBuildTargetPattern) SubdirectoryBuildTargetPattern(com.facebook.buck.model.SubdirectoryBuildTargetPattern) Test(org.junit.Test)

Example 7 with BuildTargetPattern

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();
    });
}
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

BuildTargetPattern (com.facebook.buck.model.BuildTargetPattern)7 BuildTarget (com.facebook.buck.model.BuildTarget)4 Test (org.junit.Test)4 ImmediateDirectoryBuildTargetPattern (com.facebook.buck.model.ImmediateDirectoryBuildTargetPattern)3 SingletonBuildTargetPattern (com.facebook.buck.model.SingletonBuildTargetPattern)3 SubdirectoryBuildTargetPattern (com.facebook.buck.model.SubdirectoryBuildTargetPattern)3 CellPathResolver (com.facebook.buck.rules.CellPathResolver)3 QueryException (com.facebook.buck.query.QueryException)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Optional (java.util.Optional)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)1 QueryBuildTarget (com.facebook.buck.query.QueryBuildTarget)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 FakeCellPathResolver (com.facebook.buck.rules.FakeCellPathResolver)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1