public class DefaultJavaLibrary extends PipelinedModernBuildRule<JavacPipelineState,com.facebook.buck.jvm.java.DefaultJavaLibraryBuildable> implements JavaLibrary, ExportDependencies, InitializableFromDisk<JavaLibrary.Data>, AndroidPackageable, MaybeRequiredForSourceOnlyAbi, SupportsDependencyFileRuleKey, JavaLibraryWithTests
src/com/facebook/feed/BUCK
:
java_library( name = 'feed', srcs = [ 'FeedStoryRenderer.java', ], deps = [ '//src/com/facebook/feed/model:model', '//third-party/java/guava:guava', ], )Then this would compile
FeedStoryRenderer.java
against Guava and the classes generated
from the //src/com/facebook/feed/model:model
rule.JavaLibrary.Data
GWT_MODULE_FLAVOR, MAVEN_JAR, SRC_JAR
Modifier | Constructor and Description |
---|---|
protected |
DefaultJavaLibrary(BuildTarget buildTarget,
ProjectFilesystem projectFilesystem,
JarBuildStepsFactory jarBuildStepsFactory,
SourcePathRuleFinder ruleFinder,
Optional<SourcePath> proguardConfig,
SortedSet<BuildRule> firstOrderPackageableDeps,
com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarExportedDeps,
com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarProvidedDeps,
com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarExportedProvidedDeps,
com.google.common.collect.ImmutableSortedSet<BuildRule> runtimeDeps,
BuildTarget abiJar,
BuildTarget sourceOnlyAbiJar,
Optional<String> mavenCoords,
com.google.common.collect.ImmutableSortedSet<BuildTarget> tests,
boolean requiredForSourceOnlyAbi,
JavaBuckConfig.UnusedDependenciesAction unusedDependenciesAction,
Optional<UnusedDependenciesFinderFactory> unusedDependenciesFinderFactory,
CalculateSourceAbi sourceAbi,
boolean isDesugarEnabled,
boolean isInterfaceMethodsDesugarEnabled,
boolean neverMarkAsUnusedDependency) |
getPipelinedBuildSteps
compareTo, getBuildable, getBuildCellPathFactory, getBuildDeps, getBuildSteps, getOutputPathResolver, getSetupStepsForBuildable, getSourcePath, getSourcePaths, injectFieldsIfNecessary, inputBasedRuleKeyIsEnabled, recordOutputs, recordOutputs, recordOutputs, stepsForBuildable, stepsForBuildable, updateBuildRuleResolver
equals, getBuildTarget, getDependencies, getProjectFilesystem, getSourcePathOutputs, getType, hasBuildSteps, hashCode, injectFields, isCacheable, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isMavenCoordsPresent
compareTo, getBuildDeps, getBuildSteps, getBuildTarget, getFullyQualifiedName, getProjectFilesystem, hasBuildSteps, isCacheable, outputFileCanBeCopied, shouldRespectInputSizeLimitForRemoteExecution, toString, updateBuildRuleResolver
getDependencies, getSourcePathOutputs
getType
isSupported
isSupported
protected DefaultJavaLibrary(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, JarBuildStepsFactory jarBuildStepsFactory, SourcePathRuleFinder ruleFinder, Optional<SourcePath> proguardConfig, SortedSet<BuildRule> firstOrderPackageableDeps, com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarExportedDeps, com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarProvidedDeps, com.google.common.collect.ImmutableSortedSet<BuildRule> fullJarExportedProvidedDeps, com.google.common.collect.ImmutableSortedSet<BuildRule> runtimeDeps, @Nullable BuildTarget abiJar, @Nullable BuildTarget sourceOnlyAbiJar, Optional<String> mavenCoords, com.google.common.collect.ImmutableSortedSet<BuildTarget> tests, boolean requiredForSourceOnlyAbi, JavaBuckConfig.UnusedDependenciesAction unusedDependenciesAction, Optional<UnusedDependenciesFinderFactory> unusedDependenciesFinderFactory, @Nullable CalculateSourceAbi sourceAbi, boolean isDesugarEnabled, boolean isInterfaceMethodsDesugarEnabled, boolean neverMarkAsUnusedDependency)
public static DefaultJavaLibraryRules.Builder rulesBuilder(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, ToolchainProvider toolchainProvider, BuildRuleParams params, ActionGraphBuilder graphBuilder, ConfiguredCompilerFactory compilerFactory, @Nullable JavaBuckConfig javaBuckConfig, @Nullable JavaLibraryDescription.CoreArg args)
public com.google.common.collect.ImmutableSortedSet<BuildTarget> getTests()
getTests
in interface JavaLibraryWithTests
public boolean isDesugarEnabled()
HasDesugarSupport
Such as Lambda expressions, Method references, Repeating annotations
isDesugarEnabled
in interface HasDesugarSupport
public boolean isInterfaceMethodsDesugarEnabled()
HasDesugarSupport
isInterfaceMethodsDesugarEnabled
in interface HasDesugarSupport
public boolean getRequiredForSourceOnlyAbi()
getRequiredForSourceOnlyAbi
in interface MaybeRequiredForSourceOnlyAbi
public com.google.common.collect.ImmutableSortedSet<SourcePath> getJavaSrcs()
getJavaSrcs
in interface JavaLibrary
public com.google.common.collect.ImmutableSortedSet<SourcePath> getSources()
getSources
in interface HasSources
public com.google.common.collect.ImmutableSortedSet<SourcePath> getResources()
getResources
in interface JavaLibrary
public Optional<String> getResourcesRoot()
getResourcesRoot
in interface JavaLibrary
public boolean hasAnnotationProcessing()
hasAnnotationProcessing
in interface JavaLibrary
public Set<BuildRule> getDepsForTransitiveClasspathEntries()
getDepsForTransitiveClasspathEntries
in interface HasClasspathDeps
public com.google.common.collect.ImmutableSet<SourcePath> getTransitiveClasspaths()
getTransitiveClasspaths
in interface HasClasspathEntries
javac
's -classpath
flag
in order to build a jar associated with this rule.public com.google.common.collect.ImmutableSet<JavaLibrary> getTransitiveClasspathDeps()
getTransitiveClasspathDeps
in interface HasClasspathEntries
public com.google.common.collect.ImmutableSet<SourcePath> getImmediateClasspaths()
HasClasspathEntries
Used to generate the value of HasClasspathEntries.getTransitiveClasspaths()
.
getImmediateClasspaths
in interface HasClasspathEntries
public com.google.common.collect.ImmutableSet<SourcePath> getOutputClasspaths()
getOutputClasspaths
in interface HasClasspathEntries
javac
's
-classpath
flag in order to compile rules that depend on this rule. This is a
superset of getImmediateClasspaths
which also contains the classpath entries of any
exported deps.public com.google.common.collect.ImmutableSortedSet<SourcePath> getCompileTimeClasspathSourcePaths()
public Optional<SourcePath> getGeneratedAnnotationSourcePath()
getGeneratedAnnotationSourcePath
in interface JavaLibrary
public SortedSet<BuildRule> getExportedDeps()
getExportedDeps
in interface ExportDependencies
public SortedSet<BuildRule> getExportedProvidedDeps()
getExportedProvidedDeps
in interface ExportDependencies
public void invalidateInitializeFromDiskState()
invalidateInitializeFromDiskState
in interface InitializableFromDisk<JavaLibrary.Data>
public JavaLibrary.Data initializeFromDisk(SourcePathResolverAdapter pathResolver) throws IOException
initializeFromDisk
in interface InitializableFromDisk<JavaLibrary.Data>
pathResolver
- IOException
public BuildOutputInitializer<JavaLibrary.Data> getBuildOutputInitializer()
getBuildOutputInitializer
in interface InitializableFromDisk<JavaLibrary.Data>
public final Optional<BuildTarget> getAbiJar()
getAbiJar
in interface HasJavaAbi
SourcePath
representing the ABI Jar for this rule.public Optional<BuildTarget> getSourceOnlyAbiJar()
getSourceOnlyAbiJar
in interface HasJavaAbi
public JavaAbiInfo getAbiInfo()
getAbiInfo
in interface HasJavaAbi
public com.google.common.collect.ImmutableSortedMap<String,com.google.common.hash.HashCode> getClassNamesToHashes()
getClassNamesToHashes
in interface HasJavaClassHashes
.class
files in the output of this rule to
SHA-1 hashes of their contents.@Nullable public SourcePath getSourcePathToOutput()
getSourcePathToOutput
in interface BuildRule
getSourcePathToOutput
in class ModernBuildRule<com.facebook.buck.jvm.java.DefaultJavaLibraryBuildable>
public Iterable<AndroidPackageable> getRequiredPackageables(BuildRuleResolver ruleResolver)
AndroidPackageable
For example, an android_library will need all of its Java deps (except provided_deps), its resource deps, and its native library deps (even though it doesn't need the native library as a build-time dependency). An android_resource might need an android_library that declares a custom view that it references, as well as other android_resource rules that it references directly.
TODO(natthu): Once build rules and buildables are merged, replace this method with another
interface that lets an AndroidPackageable
override the default set which is all deps of
the type AndroidPackageable
.
getRequiredPackageables
in interface AndroidPackageable
AndroidPackageable
s that must be included along with this one.public java.util.stream.Stream<BuildTarget> getRuntimeDeps(BuildRuleResolver buildRuleResolver)
getRuntimeDeps
in interface HasRuntimeDeps
public Optional<String> getMavenCoords()
HasMavenCoordinates
getMavenCoords
in interface HasMavenCoordinates
public void addToCollector(AndroidPackageableCollector collector)
AndroidPackageable
Implementations should call methods on the collector specify what concrete content must be included in an Android package that includes this object. For example, an android_library will add Java classes, an ndk_library will add native libraries, and android_resource will add resource directories.
addToCollector
in interface AndroidPackageable
collector
- The AndroidPackageableCollector
that will receive the content.public boolean useDependencyFileRuleKeys()
useDependencyFileRuleKeys
in interface SupportsDependencyFileRuleKey
public java.util.function.Predicate<SourcePath> getCoveredByDepFilePredicate(SourcePathResolverAdapter pathResolver)
SupportsDependencyFileRuleKey
I.e. this predicate should return true only for source paths that *may* be returned from
SupportsDependencyFileRuleKey.getInputsAfterBuildingLocally(BuildContext, CellPathResolver)
. This information is
used by the rule key builder to infer that inputs *not* in this list should be included
unconditionally in the rule key. Inputs that *are* in this list should be included in the rule
key if and only if they are actually being used for the rule. I.e. if they are present in the
dep-file listed by SupportsDependencyFileRuleKey.getInputsAfterBuildingLocally(BuildContext, CellPathResolver)
.
getCoveredByDepFilePredicate
in interface SupportsDependencyFileRuleKey
public java.util.function.Predicate<SourcePath> getExistenceOfInterestPredicate(SourcePathResolverAdapter pathResolver)
SupportsDependencyFileRuleKey
The main purpose of this predicate is to support scenarios where compiler decides whether to use a file or not solely based on its path. Of course, if compiler decides to use the file, it should list it in the dep-file in which case both the path and the content will be included in the rule key. However, relying only on presence in the dep-file for such paths is not sufficient. The problem occurs when a new such file just gets added, in which case it won't be present in the dep-file produced in the previous build, and yet if we run a local build now the compiler may decide to use it. For that reason rule key needs to reflect existence of all such files and change when a such a file gets added or removed.
getExistenceOfInterestPredicate
in interface SupportsDependencyFileRuleKey
public com.google.common.collect.ImmutableList<SourcePath> getInputsAfterBuildingLocally(BuildContext context, CellPathResolver cellPathResolver)
SupportsDependencyFileRuleKey
getInputsAfterBuildingLocally
in interface SupportsDependencyFileRuleKey
public boolean useRulePipelining()
useRulePipelining
in interface SupportsPipelining<JavacPipelineState>
public RulePipelineStateFactory<JavacPipelineState> getPipelineStateFactory()
getPipelineStateFactory
in interface SupportsPipelining<JavacPipelineState>
@Nullable public SupportsPipelining<JavacPipelineState> getPreviousRuleInPipeline()
getPreviousRuleInPipeline
in interface SupportsPipelining<JavacPipelineState>
public JavaClassHashesProvider getClassHashesProvider()
getClassHashesProvider
in interface HasJavaClassHashes
public void setJavaClassHashesProvider(JavaClassHashesProvider javaClassHashesProvider)
public boolean neverMarkAsUnusedDependency()
neverMarkAsUnusedDependency
in interface JavaLibrary