use of com.facebook.buck.jvm.java.JavaLibrary in project buck by facebook.
the class TestRunningTest method testNonGeneratedSourceFileWithoutPathElements.
@Test
public void testNonGeneratedSourceFileWithoutPathElements() throws Exception {
Path pathToNonGenFile = Paths.get("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);
expect(defaultJavaPackageFinder.getPathElements()).andReturn(ImmutableSet.of("/"));
replay(defaultJavaPackageFinder);
TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
verify(defaultJavaPackageFinder);
}
use of com.facebook.buck.jvm.java.JavaLibrary in project buck by facebook.
the class TestRunningTest method testNonGeneratedSourceFile.
/**
* If the source paths specified are all for non-generated files then we should return
* the correct source tmp corresponding to a non-generated source path.
*/
@Test
public void testNonGeneratedSourceFile() throws Exception {
Path pathToNonGenFile = Paths.get("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);
expect(defaultJavaPackageFinder.getPathElements()).andReturn(pathElements);
replay(defaultJavaPackageFinder);
ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
String expected = javaLibrary.getProjectFilesystem().getRootPath().resolve("package/src") + "/";
assertEquals("All non-generated source files are under one source tmp.", ImmutableSet.of(expected), result);
verify(defaultJavaPackageFinder);
}
use of com.facebook.buck.jvm.java.JavaLibrary in project buck by facebook.
the class TestRunningTest method testGeneratedSourceFile.
/**
* If the source paths specified are all generated files, then our path to source tmp
* should be absent.
*/
@Test
public void testGeneratedSourceFile() throws Exception {
BuildTarget genSrcTarget = BuildTargetFactory.newInstance("//:gensrc");
TargetNode<GenruleDescription.Arg, GenruleDescription> sourceGenerator = GenruleBuilder.newGenruleBuilder(genSrcTarget).setOut("com/facebook/GeneratedFile.java").build();
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:lib");
TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).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);
Object[] mocks = new Object[] { defaultJavaPackageFinder };
replay(mocks);
ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
assertThat("No path should be returned if the library contains only generated files.", result, Matchers.empty());
verify(mocks);
}
Aggregations