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);
}
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();
}
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());
}
}
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());
}
}
}
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;
}
Aggregations