Search in sources :

Example 1 with JvmLibraryArg

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

the class IjModuleFactory method addAnnotationOutputIfNeeded.

@SuppressWarnings("unchecked")
private void addAnnotationOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<?, ?> targetNode, ModuleBuildContext context) {
    TargetNode<? extends JvmLibraryArg, ?> jvmLibraryTargetNode = (TargetNode<? extends JvmLibraryArg, ?>) targetNode;
    Optional<Path> annotationOutput = moduleFactoryResolver.getAnnotationOutputPath(jvmLibraryTargetNode);
    if (!annotationOutput.isPresent()) {
        return;
    }
    Path annotationOutputPath = annotationOutput.get();
    context.addGeneratedSourceCodeFolder(folderFactory.create(annotationOutputPath, false, ImmutableSortedSet.of(annotationOutputPath)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg)

Example 2 with JvmLibraryArg

use of com.facebook.buck.jvm.java.JvmLibraryArg 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)

Example 3 with JvmLibraryArg

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

the class IjModuleGraphTest method createModuleGraph.

public static IjModuleGraph createModuleGraph(ImmutableSet<TargetNode<?, ?>> targets, final ImmutableMap<TargetNode<?, ?>, SourcePath> javaLibraryPaths, final Function<? super TargetNode<?, ?>, Optional<Path>> rDotJavaClassPathResolver, AggregationMode aggregationMode) {
    final SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    IjLibraryFactoryResolver sourceOnlyResolver = new IjLibraryFactoryResolver() {

        @Override
        public Path getPath(SourcePath path) {
            return sourcePathResolver.getAbsolutePath(path);
        }

        @Override
        public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
            return Optional.ofNullable(javaLibraryPaths.get(targetNode));
        }
    };
    BuckConfig buckConfig = FakeBuckConfig.builder().build();
    IjProjectConfig projectConfig = IjProjectBuckConfig.create(buckConfig);
    IjModuleFactory moduleFactory = new IjModuleFactory(new FakeProjectFilesystem(), new IjModuleFactoryResolver() {

        @Override
        public Optional<Path> getDummyRDotJavaPath(TargetNode<?, ?> targetNode) {
            return rDotJavaClassPathResolver.apply(targetNode);
        }

        @Override
        public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return Paths.get("TestAndroidManifest.xml");
        }

        @Override
        public Optional<Path> getLibraryAndroidManifestPath(TargetNode<AndroidLibraryDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAndroidResourcePath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg, ?> targetNode) {
            return Optional.empty();
        }
    }, projectConfig, false);
    IjLibraryFactory libraryFactory = new DefaultIjLibraryFactory(sourceOnlyResolver);
    return IjModuleGraph.from(projectConfig, TargetGraphFactory.newInstance(targets), libraryFactory, moduleFactory, aggregationMode);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) Optional(java.util.Optional) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)

Aggregations

JvmLibraryArg (com.facebook.buck.jvm.java.JvmLibraryArg)3 SourcePath (com.facebook.buck.rules.SourcePath)3 TargetNode (com.facebook.buck.rules.TargetNode)3 Path (java.nio.file.Path)3 Optional (java.util.Optional)2 AndroidBinaryDescription (com.facebook.buck.android.AndroidBinaryDescription)1 AndroidLibraryDescription (com.facebook.buck.android.AndroidLibraryDescription)1 AndroidPrebuiltAar (com.facebook.buck.android.AndroidPrebuiltAar)1 AndroidResourceDescription (com.facebook.buck.android.AndroidResourceDescription)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)1 AnnotationProcessingParams (com.facebook.buck.jvm.java.AnnotationProcessingParams)1 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1