Search in sources :

Example 6 with JavaPackageFinder

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

the class ParsingJavaPackageFinderTest method testFileContentsOverConvention.

@Test
public void testFileContentsOverConvention() {
    JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, fakeProjectFilesystem, ImmutableSortedSet.of(mismatchPath), dummyPackageFinder);
    assertEquals("org.test.haha", parsingJavaPackageFinder.findJavaPackage(mismatchPath));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) Test(org.junit.Test)

Example 7 with JavaPackageFinder

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

the class ParsingJavaPackageFinderTest method testFallBackToDefaultFinder.

@Test
public void testFallBackToDefaultFinder() {
    JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, fakeProjectFilesystem, ImmutableSortedSet.of(placeholderPath), dummyPackageFinder);
    assertEquals("dummy", parsingJavaPackageFinder.findJavaPackage(placeholderPath));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) Test(org.junit.Test)

Example 8 with JavaPackageFinder

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

the class ParsingJavaPackageFinderTest method testFindsPackageFromFile.

@Test
public void testFindsPackageFromFile() {
    JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, fakeProjectFilesystem, ImmutableSortedSet.of(matchPath), dummyPackageFinder);
    assertEquals("org.test.package1", parsingJavaPackageFinder.findJavaPackage(matchPath));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) Test(org.junit.Test)

Example 9 with JavaPackageFinder

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

the class ParsingJavaPackageFinderTest method setUp.

@Before
public void setUp() throws IOException {
    matchPath = Paths.get("case1/org/test/package1/Match.java");
    mismatchPath = Paths.get("case1/org/test/package2/Mismatch.java");
    placeholderPath = Paths.get("case3/com/test/placeholder");
    fakeProjectFilesystem = new FakeProjectFilesystem(new FakeClock(0), Paths.get(".").toAbsolutePath(), ImmutableSet.of(matchPath, mismatchPath, placeholderPath));
    fakeProjectFilesystem.writeContentsToPath("package org.test.package1; \n class Match {} \n", matchPath);
    fakeProjectFilesystem.writeContentsToPath("package org.test.\nhaha; \n class Mismatch {} \n", mismatchPath);
    dummyPackageFinder = new JavaPackageFinder() {

        @Override
        public Path findJavaPackageFolder(Path pathRelativeToProjectRoot) {
            return Paths.get("dummy");
        }

        @Override
        public String findJavaPackage(Path pathRelativeToProjectRoot) {
            return "dummy";
        }

        @Override
        public String findJavaPackage(BuildTarget buildTarget) {
            return "dummy";
        }
    };
    javaFileParser = JavaFileParser.createJavaFileParser(JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS);
}
Also used : Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) BuildTarget(com.facebook.buck.model.BuildTarget) Before(org.junit.Before)

Example 10 with JavaPackageFinder

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

the class IjProject method write.

/**
   * Write the project to disk.
   *
   * @param runPostGenerationCleaner Whether or not the post-generation cleaner should be run.
   * @return set of {@link BuildTarget}s which should be built in order for the project to index
   *   correctly.
   * @throws IOException
   */
public ImmutableSet<BuildTarget> write(boolean runPostGenerationCleaner, boolean removeUnusedLibraries, boolean excludeArtifacts) throws IOException {
    final ImmutableSet.Builder<BuildTarget> requiredBuildTargets = ImmutableSet.builder();
    IjLibraryFactory libraryFactory = new DefaultIjLibraryFactory(new IjLibraryFactoryResolver() {

        @Override
        public Path getPath(SourcePath path) {
            Optional<BuildRule> rule = ruleFinder.getRule(path);
            if (rule.isPresent()) {
                requiredBuildTargets.add(rule.get().getBuildTarget());
            }
            return projectFilesystem.getRootPath().relativize(sourcePathResolver.getAbsolutePath(path));
        }

        @Override
        public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
            BuildRule rule = buildRuleResolver.getRule(targetNode.getBuildTarget());
            if (!(rule instanceof JavaLibrary)) {
                return Optional.empty();
            }
            if (rule instanceof AndroidPrebuiltAar) {
                AndroidPrebuiltAar aarRule = (AndroidPrebuiltAar) rule;
                return Optional.ofNullable(aarRule.getBinaryJar());
            }
            requiredBuildTargets.add(rule.getBuildTarget());
            return Optional.ofNullable(rule.getSourcePathToOutput());
        }
    });
    IjModuleFactoryResolver moduleFactoryResolver = new IjModuleFactoryResolver() {

        @Override
        public Optional<Path> getDummyRDotJavaPath(TargetNode<?, ?> targetNode) {
            BuildTarget dummyRDotJavaTarget = AndroidLibraryGraphEnhancer.getDummyRDotJavaTarget(targetNode.getBuildTarget());
            Optional<BuildRule> dummyRDotJavaRule = buildRuleResolver.getRuleOptional(dummyRDotJavaTarget);
            if (dummyRDotJavaRule.isPresent()) {
                requiredBuildTargets.add(dummyRDotJavaTarget);
                return Optional.of(DummyRDotJava.getRDotJavaBinFolder(dummyRDotJavaTarget, projectFilesystem));
            }
            return Optional.empty();
        }

        @Override
        public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return sourcePathResolver.getAbsolutePath(targetNode.getConstructorArg().manifest);
        }

        @Override
        public Optional<Path> getLibraryAndroidManifestPath(TargetNode<AndroidLibraryDescription.Arg, ?> targetNode) {
            Optional<SourcePath> manifestPath = targetNode.getConstructorArg().manifest;
            Optional<Path> defaultAndroidManifestPath = intellijConfig.getAndroidManifest().map(Path::toAbsolutePath);
            return manifestPath.map(sourcePathResolver::getAbsolutePath).map(Optional::of).orElse(defaultAndroidManifestPath);
        }

        @Override
        public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return targetNode.getConstructorArg().proguardConfig.map(this::getRelativePathAndRecordRule);
        }

        @Override
        public Optional<Path> getAndroidResourcePath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return AndroidResourceDescription.getResDirectoryForProject(buildRuleResolver, targetNode).map(this::getRelativePathAndRecordRule);
        }

        @Override
        public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return AndroidResourceDescription.getAssetsDirectoryForProject(buildRuleResolver, targetNode).map(this::getRelativePathAndRecordRule);
        }

        @Override
        public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg, ?> targetNode) {
            AnnotationProcessingParams annotationProcessingParams = targetNode.getConstructorArg().buildAnnotationProcessingParams(targetNode.getBuildTarget(), projectFilesystem, buildRuleResolver, ImmutableSet.of());
            if (annotationProcessingParams == null || annotationProcessingParams.isEmpty()) {
                return Optional.empty();
            }
            return Optional.ofNullable(annotationProcessingParams.getGeneratedSourceFolderName());
        }

        private Path getRelativePathAndRecordRule(SourcePath sourcePath) {
            requiredBuildTargets.addAll(OptionalCompat.asSet(ruleFinder.getRule(sourcePath).map(BuildRule::getBuildTarget)));
            return sourcePathResolver.getRelativePath(sourcePath);
        }
    };
    IjModuleGraph moduleGraph = IjModuleGraph.from(projectConfig, targetGraphAndTargets.getTargetGraph(), libraryFactory, new IjModuleFactory(projectFilesystem, moduleFactoryResolver, projectConfig, excludeArtifacts), aggregationMode);
    JavaPackageFinder parsingJavaPackageFinder = ParsingJavaPackageFinder.preparse(javaFileParser, projectFilesystem, IjProjectTemplateDataPreparer.createPackageLookupPathSet(moduleGraph), javaPackageFinder);
    IjProjectWriter writer = new IjProjectWriter(new IjProjectTemplateDataPreparer(parsingJavaPackageFinder, moduleGraph, projectFilesystem), projectConfig, projectFilesystem, moduleGraph);
    writer.write(runPostGenerationCleaner, removeUnusedLibraries);
    return requiredBuildTargets.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg) SourcePath(com.facebook.buck.rules.SourcePath) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) AndroidResourceDescription(com.facebook.buck.android.AndroidResourceDescription) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidBinaryDescription(com.facebook.buck.android.AndroidBinaryDescription) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Optional(java.util.Optional) AndroidLibraryDescription(com.facebook.buck.android.AndroidLibraryDescription) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) AndroidPrebuiltAar(com.facebook.buck.android.AndroidPrebuiltAar) AnnotationProcessingParams(com.facebook.buck.jvm.java.AnnotationProcessingParams)

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