Search in sources :

Example 91 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class JavaDepsFinder method createJavaDepsFinder.

public static JavaDepsFinder createJavaDepsFinder(BuckConfig buckConfig, final CellPathResolver cellNames, ObjectMapper objectMapper, BuildEngineBuildContext buildContext, ExecutionContext executionContext, BuildEngine buildEngine) {
    Optional<String> javaPackageMappingOption = buckConfig.getValue(BUCK_CONFIG_SECTION, "java-package-mappings");
    ImmutableSortedMap<String, BuildTarget> javaPackageMapping;
    if (javaPackageMappingOption.isPresent()) {
        Stream<Map.Entry<String, BuildTarget>> entries = Splitter.on(',').omitEmptyStrings().withKeyValueSeparator("=>").split(javaPackageMappingOption.get()).entrySet().stream().map(entry -> {
            String originalKey = entry.getKey().trim();
            boolean appearsToBeJavaPackage = !originalKey.endsWith(".") && CharMatcher.javaUpperCase().matchesNoneOf(originalKey);
            String key = appearsToBeJavaPackage ? originalKey + "." : originalKey;
            BuildTarget buildTarget = BuildTargetParser.INSTANCE.parse(entry.getValue().trim(), BuildTargetPatternParser.fullyQualified(), cellNames);
            return Maps.immutableEntry(key, buildTarget);
        });
        javaPackageMapping = ImmutableSortedMap.copyOf((Iterable<Map.Entry<String, BuildTarget>>) entries::iterator, Comparator.reverseOrder());
    } else {
        javaPackageMapping = ImmutableSortedMap.of();
    }
    JavaBuckConfig javaBuckConfig = buckConfig.getView(JavaBuckConfig.class);
    JavacOptions javacOptions = javaBuckConfig.getDefaultJavacOptions();
    JavaFileParser javaFileParser = JavaFileParser.createJavaFileParser(javacOptions);
    return new JavaDepsFinder(javaPackageMapping, javaFileParser, objectMapper, buildContext, executionContext, buildEngine);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) BuildTarget(com.facebook.buck.model.BuildTarget) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 92 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class JavaLibraryRules method getAbiInputs.

public static ImmutableSortedSet<SourcePath> getAbiInputs(BuildRuleResolver resolver, Iterable<BuildRule> inputs) throws NoSuchBuildTargetException {
    ImmutableSortedSet.Builder<SourcePath> abiRules = ImmutableSortedSet.naturalOrder();
    for (BuildRule dep : inputs) {
        if (dep instanceof HasJavaAbi) {
            Optional<BuildTarget> abiJarTarget = ((HasJavaAbi) dep).getAbiJar();
            if (abiJarTarget.isPresent()) {
                BuildRule abiJarRule = resolver.requireRule(abiJarTarget.get());
                abiRules.add(Preconditions.checkNotNull(abiJarRule.getSourcePathToOutput()));
            }
        }
    }
    return abiRules.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 93 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class JvmLibraryArg method addProcessors.

void addProcessors(AnnotationProcessingParams.Builder builder, BuildRuleResolver resolver, BuildTarget owner) {
    for (BuildTarget pluginTarget : plugins) {
        BuildRule pluginRule = resolver.getRule(pluginTarget);
        if (!(pluginRule instanceof JavaAnnotationProcessor)) {
            throw new HumanReadableException(String.format("%s: only java_annotation_processor rules can be specified as plugins. " + "%s is not a java_annotation_processor.", owner, pluginTarget));
        }
        JavaAnnotationProcessor plugin = (JavaAnnotationProcessor) pluginRule;
        builder.addProcessor(plugin.getProcessorProperties());
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildRule(com.facebook.buck.rules.BuildRule)

Example 94 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class AbstractIjModule method checkDependencyConsistency.

@Value.Check
protected void checkDependencyConsistency() {
    ImmutableSet<BuildTarget> buildTargets = getTargets().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
    for (Map.Entry<BuildTarget, DependencyType> entry : getDependencies().entrySet()) {
        BuildTarget depBuildTarget = entry.getKey();
        DependencyType dependencyType = entry.getValue();
        boolean isSelfDependency = buildTargets.contains(depBuildTarget);
        if (dependencyType.equals(DependencyType.COMPILED_SHADOW)) {
            Preconditions.checkArgument(isSelfDependency, "Target %s is a COMPILED_SHADOW dependency of module %s and therefore should be part" + "of its target set.", depBuildTarget, getName());
        } else {
            Preconditions.checkArgument(!isSelfDependency, "Target %s is a regular dependency of module %s and therefore should not be part of " + "its target set.", depBuildTarget, getName());
        }
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 95 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class IjModuleFactory method findConfiguredGeneratedSourcePaths.

private Set<Path> findConfiguredGeneratedSourcePaths(TargetNode<?, ?> targetNode) {
    ImmutableMap<String, String> depToGeneratedSourcesMap = projectConfig.getDepToGeneratedSourcesMap();
    BuildTarget buildTarget = targetNode.getBuildTarget();
    Set<Path> generatedSourcePaths = new HashSet<>();
    for (BuildTarget dependencyTarget : targetNode.getDeps()) {
        String buildTargetName = dependencyTarget.toString();
        String generatedSourceWithPattern = depToGeneratedSourcesMap.get(buildTargetName);
        if (generatedSourceWithPattern != null) {
            String generatedSource = generatedSourceWithPattern.replaceAll("%name%", buildTarget.getShortNameAndFlavorPostfix());
            Path generatedSourcePath = BuildTargets.getGenPath(projectFilesystem, buildTarget, generatedSource);
            generatedSourcePaths.add(generatedSourcePath);
        }
    }
    return generatedSourcePaths;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) HashSet(java.util.HashSet)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1045 Test (org.junit.Test)758 Path (java.nio.file.Path)323 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)289 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)254 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)248 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)226 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)216 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)209 BuildRule (com.facebook.buck.rules.BuildRule)196 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)178 SourcePath (com.facebook.buck.rules.SourcePath)163 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)161 TargetGraph (com.facebook.buck.rules.TargetGraph)156 PathSourcePath (com.facebook.buck.rules.PathSourcePath)116 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)108 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)90 ImmutableMap (com.google.common.collect.ImmutableMap)78 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)75