in src/com/facebook/buck/java/DefaultJavaLibraryRule.java [187:287]
protected DefaultJavaLibraryRule(BuildRuleParams buildRuleParams,
Set<String> srcs,
Set<? extends SourcePath> resources,
Optional<String> proguardConfig,
Set<BuildRule> exportedDeps,
JavacOptions javacOptions) {
super(buildRuleParams);
this.srcs = ImmutableSortedSet.copyOf(srcs);
this.resources = ImmutableSortedSet.copyOf(resources);
this.proguardConfig = Preconditions.checkNotNull(proguardConfig);
this.exportedDeps = ImmutableSortedSet.copyOf(exportedDeps);
this.javacOptions = Preconditions.checkNotNull(javacOptions);
if (!srcs.isEmpty() || !resources.isEmpty()) {
this.outputJar = Optional.of(getOutputJarPath(getBuildTarget()));
} else {
this.outputJar = Optional.absent();
}
// Note that both srcs and resources are sorted so that the list order is consistent even if
// the iteration order of the sets passed to the constructor changes. See
// AbstractBuildRule.getInputsToCompareToOutput() for details.
ImmutableList.Builder<String> builder = ImmutableList.<String>builder().addAll(this.srcs);
builder.addAll(SourcePaths.filterInputsToCompareToOutput(resources));
inputsToConsiderForCachingPurposes = builder.build();
outputClasspathEntriesSupplier =
Suppliers.memoize(new Supplier<ImmutableSetMultimap<JavaLibraryRule, String>>() {
@Override
public ImmutableSetMultimap<JavaLibraryRule, String> get() {
ImmutableSetMultimap.Builder<JavaLibraryRule, String> outputClasspathBuilder =
ImmutableSetMultimap.builder();
Iterable<JavaLibraryRule> javaExportedLibraryDeps = Iterables.filter(
getExportedDeps(),
JavaLibraryRule.class);
for (JavaLibraryRule rule : javaExportedLibraryDeps) {
outputClasspathBuilder.putAll(rule, rule.getOutputClasspathEntries().values());
// If we have any exported deps, add an entry mapping ourselves to to their,
// classpaths so when suggesting libraries to add we know that adding this library
// would pull in it's deps.
outputClasspathBuilder.putAll(DefaultJavaLibraryRule.this,
rule.getOutputClasspathEntries().values());
}
if (outputJar.isPresent()) {
outputClasspathBuilder.put(DefaultJavaLibraryRule.this, getPathToOutputFile());
}
return outputClasspathBuilder.build();
}
});
transitiveClasspathEntriesSupplier =
Suppliers.memoize(new Supplier<ImmutableSetMultimap<JavaLibraryRule, String>>() {
@Override
public ImmutableSetMultimap<JavaLibraryRule, String> get() {
final ImmutableSetMultimap.Builder<JavaLibraryRule, String> classpathEntries =
ImmutableSetMultimap.builder();
ImmutableSetMultimap<JavaLibraryRule, String> classpathEntriesForDeps =
Classpaths.getClasspathEntries(getDeps());
ImmutableSetMultimap<JavaLibraryRule, String> classpathEntriesForExportedsDeps =
Classpaths.getClasspathEntries(getExportedDeps());
classpathEntries.putAll(classpathEntriesForDeps);
// If we have any exported deps, add an entry mapping ourselves to to their classpaths,
// so when suggesting libraries to add we know that adding this library would pull in
// it's deps.
if (!classpathEntriesForExportedsDeps.isEmpty()) {
classpathEntries.putAll(DefaultJavaLibraryRule.this,
classpathEntriesForExportedsDeps.values());
}
// Only add ourselves to the classpath if there's a jar to be built.
if (outputJar.isPresent()) {
classpathEntries.putAll(DefaultJavaLibraryRule.this, getPathToOutputFile());
}
return classpathEntries.build();
}
});
declaredClasspathEntriesSupplier =
Suppliers.memoize(new Supplier<ImmutableSetMultimap<JavaLibraryRule, String>>() {
@Override
public ImmutableSetMultimap<JavaLibraryRule, String> get() {
final ImmutableSetMultimap.Builder<JavaLibraryRule, String> classpathEntries =
ImmutableSetMultimap.builder();
Iterable<JavaLibraryRule> javaLibraryDeps = Iterables.filter(getDeps(),
JavaLibraryRule.class);
for (JavaLibraryRule rule : javaLibraryDeps) {
classpathEntries.putAll(rule, rule.getOutputClasspathEntries().values());
}
return classpathEntries.build();
}
});
}