use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class JvmLibraryArgInterpreterTest method compilerArgWithPrebuiltJarValueReturnsJsr199Javac.
@Test
public void compilerArgWithPrebuiltJarValueReturnsJsr199Javac() throws Exception {
Path javacJarPath = Paths.get("langtools").resolve("javac.jar");
BuildTarget target = BuildTargetFactory.newInstance("//langtools:javac");
PrebuiltJarBuilder.createBuilder(target).setBinaryJar(javacJarPath).build(ruleResolver);
SourcePath sourcePath = new DefaultBuildTargetSourcePath(target);
Either<BuiltInJavac, SourcePath> either = Either.ofRight(sourcePath);
arg.compiler = Optional.of(either);
JavacOptions options = createJavacOptions(arg);
Javac javac = options.getJavac();
assertEquals(pathResolver.getRelativePath(sourcePath), pathResolver.getRelativePath(options.getJavacJarPath().get()));
assertEquals(Optional.empty(), options.getJavacPath());
assertTrue(javac.getClass().getName(), javac instanceof Jsr199Javac);
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class MavenUberJarTest method onlyJavaDepsIncluded.
@Test
public void onlyJavaDepsIncluded() throws NoSuchBuildTargetException {
BuildTarget pythonTarget = BuildTargetFactory.newInstance("//:python");
BuildTarget javaTarget = BuildTargetFactory.newInstance("//:java");
PythonLibraryBuilder pythonLibraryBuilder = PythonLibraryBuilder.createBuilder(pythonTarget);
JavaLibraryBuilder javaLibraryBuilder = JavaLibraryBuilder.createBuilder(javaTarget).addResource(new DefaultBuildTargetSourcePath(pythonTarget));
TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonLibraryBuilder.build(), javaLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PythonLibrary pythonLibrary = pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
JavaLibrary javaLibrary = javaLibraryBuilder.build(resolver, filesystem, targetGraph);
MavenUberJar buildRule = MavenUberJar.create(javaLibrary, javaLibraryBuilder.createBuildRuleParams(resolver, filesystem), Optional.of("com.facebook.buck.jvm.java:java:jar:42"), Optional.empty());
assertThat(buildRule.getDeps(), Matchers.not(Matchers.hasItem(pythonLibrary)));
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class JavaLibrarySymbolsFinderTest method extractSymbolsFromSrcs.
@Test
public void extractSymbolsFromSrcs() throws IOException {
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();
JavaLibrarySymbolsFinder finder = new JavaLibrarySymbolsFinder(srcs, javaFileParser, /* shouldRecordRequiredSymbols */
true);
Symbols symbols = finder.extractSymbols();
assertEquals(ImmutableSet.of("com.example.Example1", "com.example.Example2"), ImmutableSet.copyOf(symbols.provided));
assertEquals(ImmutableSet.of("com.example.other.Bar", "com.example.other.Foo"), ImmutableSet.copyOf(symbols.required));
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class JavaLibrarySymbolsFinderTest method onlyNonGeneratedSrcsShouldAffectRuleKey.
@Test
@SuppressWarnings("PMD.PrematureDeclaration")
public void onlyNonGeneratedSrcsShouldAffectRuleKey() throws IOException {
TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
final ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
Function<String, SourcePath> convert = src -> new PathSourcePath(projectFilesystem, Paths.get(src));
SourcePath example1 = convert.apply("Example1.java");
SourcePath example2 = convert.apply("Example2.java");
final BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//foo:GenEx.java");
SourcePath generated = new DefaultBuildTargetSourcePath(fakeBuildTarget);
final boolean shouldRecordRequiredSymbols = true;
JavaLibrarySymbolsFinder example1Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1), javaFileParser, shouldRecordRequiredSymbols);
JavaLibrarySymbolsFinder example2Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example2), javaFileParser, shouldRecordRequiredSymbols);
JavaLibrarySymbolsFinder example1AndGeneratedSrcFinder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1, generated), javaFileParser, shouldRecordRequiredSymbols);
// Mock out calls to a SourcePathResolver so we can create a legitimate
// DefaultRuleKeyFactory.
final SourcePathRuleFinder ruleFinder = createMock(SourcePathRuleFinder.class);
final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
expect(ruleFinder.getRule(anyObject(SourcePath.class))).andAnswer(() -> {
SourcePath input = (SourcePath) EasyMock.getCurrentArguments()[0];
if (input instanceof ExplicitBuildTargetSourcePath) {
return Optional.of(new FakeBuildRule(fakeBuildTarget, pathResolver));
} else {
return Optional.empty();
}
}).anyTimes();
// Calculates the RuleKey for a JavaSymbolsRule with the specified JavaLibrarySymbolsFinder.
final FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
final DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
Function<JavaLibrarySymbolsFinder, RuleKey> createRuleKey = finder -> {
JavaSymbolsRule javaSymbolsRule = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), finder, ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), projectFilesystem);
return ruleKeyFactory.build(javaSymbolsRule);
};
RuleKey key1 = createRuleKey.apply(example1Finder);
RuleKey key2 = createRuleKey.apply(example2Finder);
RuleKey key3 = createRuleKey.apply(example1AndGeneratedSrcFinder);
assertNotNull(key1);
assertNotNull(key2);
assertNotNull(key3);
assertNotEquals("Two instances of a JavaSymbolsRule with different srcs should change the RuleKey.", key1, key2);
assertEquals("Introducing an extra generated .java file to the srcs should not change the RuleKey.", key1, key3);
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class PrebuiltJarSymbolsFinderTest method createFinderForGeneratedJar.
private PrebuiltJarSymbolsFinder createFinderForGeneratedJar(String target) {
BuildTarget buildTarget = BuildTargetFactory.newInstance(target);
SourcePath sourcePath = new DefaultBuildTargetSourcePath(buildTarget);
return new PrebuiltJarSymbolsFinder(sourcePath);
}
Aggregations