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