use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.
the class AndroidLibraryDescriptionTest method rulesMatchingDepQueryBecomeFirstOrderDeps.
@Test
public void rulesMatchingDepQueryBecomeFirstOrderDeps() throws Exception {
// Set up target graph: rule -> lib -> sublib -> bottom
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> bottomNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:bottom")).build();
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> sublibNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:sublib")).addDep(bottomNode.getBuildTarget()).build();
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> libNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addDep(sublibNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(bottomNode, libNode, sublibNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeBuildRule bottomRule = resolver.addToIndex(new FakeBuildRule(bottomNode.getBuildTarget(), pathResolver));
FakeBuildRule sublibRule = resolver.addToIndex(new FakeBuildRule(sublibNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(bottomRule)));
FakeBuildRule libRule = resolver.addToIndex(new FakeBuildRule(libNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(sublibRule)));
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRule javaLibrary = AndroidLibraryBuilder.createBuilder(target).addDep(libNode.getBuildTarget()).setDepsQuery(Query.of("filter('.*lib', deps($declared_deps))")).build(resolver, targetGraph);
assertThat(javaLibrary.getDeps(), Matchers.hasItems(libRule, sublibRule));
// The bottom rule should be filtered since it does not match the regex
assertThat(javaLibrary.getDeps(), Matchers.not(Matchers.hasItem(bottomRule)));
}
use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.
the class IjModuleFactory method getSourceLevel.
private Optional<String> getSourceLevel(Iterable<TargetNode<?, ?>> targetNodes) {
Optional<String> result = Optional.empty();
for (TargetNode<?, ?> targetNode : targetNodes) {
if (!(targetNode.getDescription() instanceof JavaLibraryDescription)) {
continue;
}
JavacOptions defaultJavacOptions = projectConfig.getJavaBuckConfig().getDefaultJavacOptions();
String defaultSourceLevel = defaultJavacOptions.getSourceLevel();
String defaultTargetLevel = defaultJavacOptions.getTargetLevel();
JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) targetNode.getConstructorArg();
if (!defaultSourceLevel.equals(arg.source.orElse(defaultSourceLevel)) || !defaultTargetLevel.equals(arg.target.orElse(defaultTargetLevel))) {
result = arg.source;
}
}
if (result.isPresent()) {
result = Optional.of(JavaLanguageLevelHelper.normalizeSourceLevel(result.get()));
}
return result;
}
use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.
the class TestRunningTest method testMixedSourceFile.
/**
* If the source paths specified contains one source path to a non-generated file then
* we should return the correct source tmp corresponding to that non-generated source path.
* Especially when the generated file comes first in the ordered set.
*/
@Test
public void testMixedSourceFile() throws Exception {
BuildTarget genSrcTarget = BuildTargetFactory.newInstance("//:gensrc");
TargetNode<GenruleDescription.Arg, GenruleDescription> sourceGenerator = GenruleBuilder.newGenruleBuilder(genSrcTarget).setOut("com/facebook/GeneratedFile.java").build();
Path pathToNonGenFile1 = Paths.get("package/src/SourceFile1.java");
Path pathToNonGenFile2 = Paths.get("package/src-gen/SourceFile2.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile1).addSrc(pathToNonGenFile2).addSrcTarget(genSrcTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(sourceGenerator, javaLibraryNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);
DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot).times(2);
expect(defaultJavaPackageFinder.getPathElements()).andReturn(pathElements).times(2);
replay(defaultJavaPackageFinder);
ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
Path rootPath = javaLibrary.getProjectFilesystem().getRootPath();
ImmutableSet<String> expected = ImmutableSet.of(rootPath.resolve("package/src-gen").toString() + "/", rootPath.resolve("package/src").toString() + "/");
assertEquals("The non-generated source files are under two different source folders.", expected, result);
verify(defaultJavaPackageFinder);
}
use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.
the class TestRunningTest method testUnifiedSourceFile.
/**
* If the source paths specified are from the new unified source tmp then we should return
* the correct source tmp corresponding to the unified source path.
*/
@Test
public void testUnifiedSourceFile() throws Exception {
Path pathToNonGenFile = Paths.get("java/package/src/SourceFile1.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibraryNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);
DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot);
Object[] mocks = new Object[] { defaultJavaPackageFinder };
replay(mocks);
ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
assertEquals("All non-generated source files are under one source tmp.", ImmutableSet.of("java/"), result);
verify(mocks);
}
use of com.facebook.buck.jvm.java.JavaLibraryDescription in project buck by facebook.
the class KnownBuildRuleTypesTest method createJavaLibrary.
private DefaultJavaLibrary createJavaLibrary(KnownBuildRuleTypes buildRuleTypes) throws NoSuchBuildTargetException {
JavaLibraryDescription description = (JavaLibraryDescription) buildRuleTypes.getDescription(Description.getBuildRuleType(JavaLibraryDescription.class));
JavaLibraryDescription.Arg arg = new JavaLibraryDescription.Arg();
populateJavaArg(arg);
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
return (DefaultJavaLibrary) description.createBuildRule(TargetGraph.EMPTY, buildRuleParams, resolver, arg);
}
Aggregations