Search in sources :

Example 71 with DefaultBuildTargetSourcePath

use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.

the class JavaSymbolsRuleTest method ensureJsonFilesGetWritten.

@Test
public void ensureJsonFilesGetWritten() throws IOException, InterruptedException {
    TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
    ImmutableSortedSet<SourcePath> srcs = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(Stream.of("Example1.java", "Example2.java").map(Paths::get).map(p -> new PathSourcePath(projectFilesystem, p)).iterator()).add(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//foo:bar"))).build();
    JavaFileParser javaFileParser = JavaFileParser.createJavaFileParser(JavacOptions.builder().setSourceLevel("7").setTargetLevel("7").build());
    JavaLibrarySymbolsFinder symbolsFinder = new JavaLibrarySymbolsFinder(srcs, javaFileParser, /* shouldRecordRequiredSymbols */
    true);
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//:examples");
    JavaSymbolsRule javaSymbolsRule = new JavaSymbolsRule(buildTarget, symbolsFinder, /* generatedSymbols */
    ImmutableSortedSet.of("com.example.generated.Example"), ObjectMappers.newDefaultInstance(), projectFilesystem);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    resolver.addToIndex(javaSymbolsRule);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    List<Step> buildSteps = javaSymbolsRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), /* buildableContext */
    null);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    for (Step step : buildSteps) {
        step.execute(executionContext);
    }
    JsonNode jsonNode = objectMapper.readTree(projectFilesystem.resolve(BuildTargets.getGenPath(javaSymbolsRule.getProjectFilesystem(), buildTarget.withFlavors(JavaSymbolsRule.JAVA_SYMBOLS), "__%s__.json")).toFile());
    assertTrue(jsonNode instanceof ObjectNode);
    assertEquals(ImmutableSet.of("com.example.Example1", "com.example.Example2", "com.example.generated.Example"), StreamSupport.stream(jsonNode.get("provided").spliterator(), false).map(JsonNode::textValue).collect(MoreCollectors.toImmutableSet()));
    assertEquals(ImmutableSet.of("com.example.other.Bar", "com.example.other.Foo"), StreamSupport.stream(jsonNode.get("required").spliterator(), false).map(JsonNode::textValue).collect(MoreCollectors.toImmutableSet()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) JsonNode(com.fasterxml.jackson.databind.JsonNode) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) Step(com.facebook.buck.step.Step) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)71 Test (org.junit.Test)64 BuildTarget (com.facebook.buck.model.BuildTarget)53 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)26 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)25 SourcePath (com.facebook.buck.rules.SourcePath)25 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)21 TargetGraph (com.facebook.buck.rules.TargetGraph)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)18 Path (java.nio.file.Path)16 BuildRule (com.facebook.buck.rules.BuildRule)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5