Search in sources :

Example 6 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder in project buck by facebook.

the class DefaultJavaPackageFinderTest method testSinglePathFromRoot.

@Test
public void testSinglePathFromRoot() {
    DefaultJavaPackageFinder javaPackageFinder = DefaultJavaPackageFinder.createDefaultJavaPackageFinder(ImmutableList.of("/java/"));
    assertEquals(Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/com/example/base/Base.java")));
    assertEquals("com.example.base", javaPackageFinder.findJavaPackage(Paths.get("java/com/example/base/Base.java")));
    assertEquals(Paths.get(""), javaPackageFinder.findJavaPackageFolder(Paths.get("java/Weird.java")));
    assertEquals("", javaPackageFinder.findJavaPackage(Paths.get("java/Weird.java")));
    assertEquals("When there is no match, the project root should be treated as a Java source root.", Paths.get("notjava/"), javaPackageFinder.findJavaPackageFolder(Paths.get("notjava/Weird.java")));
    assertEquals("When there is no match, the project root should be treated as a Java source root.", "notjava", javaPackageFinder.findJavaPackage(Paths.get("notjava/Weird.java")));
}
Also used : DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Example 7 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder 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);
}
Also used : Path(java.nio.file.Path) GenruleDescription(com.facebook.buck.shell.GenruleDescription) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 8 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder 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);
}
Also used : Path(java.nio.file.Path) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 9 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder in project buck by facebook.

the class DefaultJavaPackageFinderTest method testSinglePathElement.

@Test
public void testSinglePathElement() {
    DefaultJavaPackageFinder javaPackageFinder = DefaultJavaPackageFinder.createDefaultJavaPackageFinder(ImmutableList.of("src"));
    assertEquals(Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/main/src/com/example/base/Base.java")));
    assertEquals("When the path element appears more than once, use the rightmost instance as the base.", Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/main/src/other/project/src/com/example/base/Base.java")));
    assertEquals(Paths.get(""), javaPackageFinder.findJavaPackageFolder(Paths.get("src/Weird.java")));
    assertEquals("When there is no match, the project root should be treated as a Java source root.", Paths.get("notjava/"), javaPackageFinder.findJavaPackageFolder(Paths.get("notjava/Weird.java")));
}
Also used : DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Example 10 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder in project buck by facebook.

the class DefaultJavaPackageFinderTest method testMultiplePathElements.

@Test
public void testMultiplePathElements() {
    DefaultJavaPackageFinder javaPackageFinder = DefaultJavaPackageFinder.createDefaultJavaPackageFinder(ImmutableList.of("src", "src-gen"));
    assertEquals(Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/main/src-gen/other/project/src/com/example/base/Base.java")));
}
Also used : DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Aggregations

DefaultJavaPackageFinder (com.facebook.buck.jvm.java.DefaultJavaPackageFinder)15 Test (org.junit.Test)14 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)6 JavaLibraryDescription (com.facebook.buck.jvm.java.JavaLibraryDescription)5 BuildTarget (com.facebook.buck.model.BuildTarget)5 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 TargetGraph (com.facebook.buck.rules.TargetGraph)5 Path (java.nio.file.Path)4 JavaBuckConfig (com.facebook.buck.jvm.java.JavaBuckConfig)3 GenruleDescription (com.facebook.buck.shell.GenruleDescription)2 JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)1 DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)1 GenerateCodeCoverageReportStep (com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep)1 ResourcesRootPackageFinder (com.facebook.buck.jvm.java.ResourcesRootPackageFinder)1 BuildRule (com.facebook.buck.rules.BuildRule)1 TestRule (com.facebook.buck.rules.TestRule)1 TestStatusMessageEvent (com.facebook.buck.rules.TestStatusMessageEvent)1