Search in sources :

Example 16 with JavaPackageFinder

use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.

the class CopyResourcesStepTest method testAddResourceCommandsWithBuildFileParentOfSrcDirectory.

@Test
public void testAddResourceCommandsWithBuildFileParentOfSrcDirectory() {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    // Files:
    // android/java/BUCK
    // android/java/src/com/facebook/base/data.json
    // android/java/src/com/facebook/common/util/data.json
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//android/java:resources");
    JavaPackageFinder javaPackageFinder = createJavaPackageFinder();
    CopyResourcesStep step = new CopyResourcesStep(filesystem, resolver, ruleFinder, buildTarget, ImmutableSet.of(new FakeSourcePath(filesystem, "android/java/src/com/facebook/base/data.json"), new FakeSourcePath(filesystem, "android/java/src/com/facebook/common/util/data.json")), filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__resources__classes"), javaPackageFinder);
    List<? extends Step> expected = ImmutableList.of(new MkdirAndSymlinkFileStep(filesystem, filesystem.resolve("android/java/src/com/facebook/base/data.json"), filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__resources__classes/com/facebook/base/data.json")), new MkdirAndSymlinkFileStep(filesystem, filesystem.resolve("android/java/src/com/facebook/common/util/data.json"), filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__resources__classes/com/facebook/common/util/data.json")));
    assertEquals(expected, step.buildSteps());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) Test(org.junit.Test)

Example 17 with JavaPackageFinder

use of com.facebook.buck.jvm.core.JavaPackageFinder 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 18 with JavaPackageFinder

use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.

the class JavacErrorParserTest method setUp.

@Before
public void setUp() {
    projectFilesystem = new ProjectFilesystem(Paths.get(".").toAbsolutePath());
    JavaPackageFinder javaPackageFinder = DefaultJavaPackageFinder.createDefaultJavaPackageFinder(ImmutableSet.of("/src/"));
    javacErrorParser = new JavacErrorParser(projectFilesystem, javaPackageFinder);
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Before(org.junit.Before)

Example 19 with JavaPackageFinder

use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.

the class ParsingJavaPackageFinderTest method testCaching.

@Test
public void testCaching() {
    JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, fakeProjectFilesystem, ImmutableSortedSet.of(matchPath, mismatchPath), dummyPackageFinder);
    assertEquals("org.test.package1", parsingJavaPackageFinder.findJavaPackage(matchPath));
    assertEquals("org.test.haha", parsingJavaPackageFinder.findJavaPackage(mismatchPath));
    assertEquals("org.test.package3", parsingJavaPackageFinder.findJavaPackage(Paths.get("case1/org/test/package3/notfound")));
    assertEquals("org.test", parsingJavaPackageFinder.findJavaPackage(Paths.get("case1/org/test/notfound")));
    assertEquals("com", parsingJavaPackageFinder.findJavaPackage(Paths.get("case1/com/notfound")));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) Test(org.junit.Test)

Aggregations

JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)19 Test (org.junit.Test)11 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 BuildTarget (com.facebook.buck.model.BuildTarget)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 Path (java.nio.file.Path)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 BuildRule (com.facebook.buck.rules.BuildRule)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)4 MkdirAndSymlinkFileStep (com.facebook.buck.step.fs.MkdirAndSymlinkFileStep)3 ImmutableList (com.google.common.collect.ImmutableList)3 Before (org.junit.Before)3 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)2 SourceFolder (com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder)2 ActionGraph (com.facebook.buck.rules.ActionGraph)2 BuildContext (com.facebook.buck.rules.BuildContext)2