Search in sources :

Example 11 with DefaultJavaPackageFinder

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

the class DefaultJavaPackageFinderTest method testOverlappingPathsFromRoot.

@Test
public void testOverlappingPathsFromRoot() {
    DefaultJavaPackageFinder javaPackageFinder = DefaultJavaPackageFinder.createDefaultJavaPackageFinder(ImmutableList.of("/java", "/java/more/specific", "/javatests"));
    assertEquals(Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/com/example/base/Base.java")));
    assertEquals(Paths.get("base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("java/more/specific/base/Base.java")));
    assertEquals(Paths.get("com/example/base/"), javaPackageFinder.findJavaPackageFolder(Paths.get("javatests/com/example/base/BaseTest.java")));
}
Also used : DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Example 12 with DefaultJavaPackageFinder

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

the class JavaPackageFinderSerializerTest method testSerializingAndDeserializing.

@Test
public void testSerializingAndDeserializing() throws Exception {
    DefaultJavaPackageFinder defaultFinder = new DefaultJavaPackageFinder(ImmutableSortedSet.of("paths", "from", "root"), ImmutableSet.of("path", "elements"));
    ResourcesRootPackageFinder resourcesRootFinder = new ResourcesRootPackageFinder(Paths.get("/path/to/res/root"), defaultFinder);
    Map<String, Object> data = JavaPackageFinderSerializer.serialize(resourcesRootFinder);
    JavaPackageFinder result = JavaPackageFinderSerializer.deserialize(data);
    assertThat(result, Matchers.instanceOf(ResourcesRootPackageFinder.class));
    ResourcesRootPackageFinder outResFinder = (ResourcesRootPackageFinder) result;
    assertThat(outResFinder.getResourcesRoot(), Matchers.equalToObject(resourcesRootFinder.getResourcesRoot()));
    JavaPackageFinder chainedFinder = outResFinder.getFallbackFinder();
    assertThat(chainedFinder, Matchers.instanceOf(DefaultJavaPackageFinder.class));
    DefaultJavaPackageFinder outDefFinder = (DefaultJavaPackageFinder) chainedFinder;
    assertThat(outDefFinder.getPathElements(), Matchers.equalToObject(defaultFinder.getPathElements()));
    assertThat(outDefFinder.getPathsFromRoot(), Matchers.equalToObject(defaultFinder.getPathsFromRoot()));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) ResourcesRootPackageFinder(com.facebook.buck.jvm.java.ResourcesRootPackageFinder) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Example 13 with DefaultJavaPackageFinder

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

Example 14 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder 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);
}
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 15 with DefaultJavaPackageFinder

use of com.facebook.buck.jvm.java.DefaultJavaPackageFinder 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);
}
Also used : 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)

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