Class JarTreeShakeInput
- All Implemented Interfaces:
AutoCloseable
JarTreeShaker for reachability analysis.
Separates input collection (dependency walking, build item extraction, root identification)
from the BFS analysis itself.
Implements AutoCloseable because it owns OpenPathTree instances
whose lifecycle must extend until the analysis completes (bytecode suppliers hold
Path references into the open trees).
Use the collect(io.quarkus.deployment.pkg.TreeShakeConfig.TreeShakeMode, io.quarkus.bootstrap.model.ApplicationModel, java.util.List<io.quarkus.deployment.builditem.GeneratedClassBuildItem>, io.quarkus.deployment.builditem.TransformedClassesBuildItem, java.util.List<io.quarkus.deployment.builditem.nativeimage.ReflectiveClassConditionBuildItem>, java.util.List<io.quarkus.deployment.pkg.builditem.JarTreeShakeRootClassBuildItem>, java.util.List<io.quarkus.deployment.pkg.builditem.JarTreeShakeExcludedArtifactBuildItem>) factory method to build an instance from the application model
and build items, then pass it to JarTreeShaker.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classLazy bytecode loader that reads from aPathon demand. -
Field Summary
FieldsModifier and TypeFieldDescriptionUnion of dependency and generated class names, used for string-constant reference matching.Bytecode suppliers for application classes, keyed by dot-separated class name.(package private) final intJava feature version detected from application bytecode (e.g. 17, 21).Filesystem paths of the application artifact.Maps dot-separated dependency class names to their originating artifact.Map from condition class to classes that become roots when the condition is reachable.Bytecode suppliers for runtime dependency classes, keyed by dot-separated class name.Filesystem paths of resolved runtime dependency JARs.(package private) final Set<io.quarkus.maven.dependency.ArtifactKey> Artifacts excluded from tree-shaking viaJarTreeShakeExcludedArtifactBuildItem.Bytecode suppliers for build-time generated classes, keyed by dot-separated class name.Bytecode from multi-release entries targeting Java versions newer thanappJavaVersion.(package private) final Map<io.quarkus.maven.dependency.ArtifactKey, io.quarkus.paths.OpenPathTree> Open content trees for dependencies, kept alive untilclose().Dot-separated class names that are unconditionally reachable (BFS starting points).Service interface to consumer class names detected viaServiceLoader.load()calls.Service interface to provider class names parsed fromMETA-INF/services/files.Classes listed inMETA-INF/sisu/javax.inject.Namedfiles.Class names whose bytecode was replaced by a build-time transformation.(package private) final TreeShakeConfig.TreeShakeModeConfigured tree-shake mode controlling analysis aggressiveness. -
Constructor Summary
ConstructorsConstructorDescriptionJarTreeShakeInput(TreeShakeConfig.TreeShakeMode treeShakeMode, Set<String> roots, Map<String, Set<String>> conditionalRoots, Set<String> sisuNamedClasses, Map<String, Supplier<byte[]>> depBytecode, Map<String, Supplier<byte[]>> appBytecode, Map<String, Supplier<byte[]>> generatedBytecode, Map<String, io.quarkus.maven.dependency.ArtifactKey> classToDep, Map<String, Set<String>> serviceProviders, Map<String, Set<String>> serviceLoaderCalls, Set<String> allKnownClasses, int appJavaVersion, Map<io.quarkus.maven.dependency.ArtifactKey, io.quarkus.paths.OpenPathTree> openTrees, List<Path> depJarPaths, List<Path> appPaths, Set<String> transformedClassNames, Map<String, List<Supplier<byte[]>>> higherVersionBytecode, Set<io.quarkus.maven.dependency.ArtifactKey> excludedArtifacts) Creates a new tree-shake input with all collected data. -
Method Summary
Modifier and TypeMethodDescription(package private) static StringclassNameOf(String classResourceName) Converts a class resource path (e.g.(package private) static StringclassNameOf(String resourceName, int classNameStartIndex) Converts a class resource path to a dot-separated class name, starting from the given index (used for multi-release entries to skip theMETA-INF/versions/N/prefix).voidclose()Closes allOpenPathTreeinstances opened during input collection.(package private) static JarTreeShakeInputcollect(TreeShakeConfig.TreeShakeMode treeShakeMode, io.quarkus.bootstrap.model.ApplicationModel appModel, List<GeneratedClassBuildItem> generatedClasses, TransformedClassesBuildItem transformedClasses, List<ReflectiveClassConditionBuildItem> reflectiveClassConditions, List<JarTreeShakeRootClassBuildItem> rootClasses, List<JarTreeShakeExcludedArtifactBuildItem> excludedArtifactItems) Factory method that assembles all input for the tree-shake analysis.(package private) Supplier<byte[]> getBytecode(String name) Looks up the bytecode supplier for the given class name, checking generated, dependency, and application bytecode maps in priority order.(package private) booleanhasBytecode(String name) Returns true if bytecode is available for the given class name in any of the three bytecode maps.(package private) static booleanisClassEntry(String resourceName) Returnstrueif the resource name represents a regular class file, excludingmodule-info.classandpackage-info.class.(package private) byte[]readBytecode(String name) Reads bytecode for the given class.(package private) voidReleases all data structures.
-
Field Details
-
treeShakeMode
Configured tree-shake mode controlling analysis aggressiveness. -
roots
Dot-separated class names that are unconditionally reachable (BFS starting points). -
conditionalRoots
Map from condition class to classes that become roots when the condition is reachable. -
sisuNamedClasses
Classes listed inMETA-INF/sisu/javax.inject.Namedfiles. -
depBytecode
Bytecode suppliers for runtime dependency classes, keyed by dot-separated class name. -
appBytecode
Bytecode suppliers for application classes, keyed by dot-separated class name. -
generatedBytecode
Bytecode suppliers for build-time generated classes, keyed by dot-separated class name. -
classToDep
Maps dot-separated dependency class names to their originating artifact. -
serviceProviders
Service interface to provider class names parsed fromMETA-INF/services/files. -
serviceLoaderCalls
Service interface to consumer class names detected viaServiceLoader.load()calls. -
allKnownClasses
Union of dependency and generated class names, used for string-constant reference matching. -
appJavaVersion
final int appJavaVersionJava feature version detected from application bytecode (e.g. 17, 21). -
openTrees
Open content trees for dependencies, kept alive untilclose(). -
depJarPaths
Filesystem paths of resolved runtime dependency JARs. -
appPaths
Filesystem paths of the application artifact. -
transformedClassNames
Class names whose bytecode was replaced by a build-time transformation. -
higherVersionBytecode
Bytecode from multi-release entries targeting Java versions newer thanappJavaVersion. Keyed by dot-separated class name. These are not used for the main reachability analysis but their references must be traced after analysis to ensure classes they depend on are also marked reachable. -
excludedArtifacts
Artifacts excluded from tree-shaking viaJarTreeShakeExcludedArtifactBuildItem.
-
-
Constructor Details
-
JarTreeShakeInput
JarTreeShakeInput(TreeShakeConfig.TreeShakeMode treeShakeMode, Set<String> roots, Map<String, Set<String>> conditionalRoots, Set<String> sisuNamedClasses, Map<String, Supplier<byte[]>> depBytecode, Map<String, Supplier<byte[]>> appBytecode, Map<String, Supplier<byte[]>> generatedBytecode, Map<String, io.quarkus.maven.dependency.ArtifactKey> classToDep, Map<String, Set<String>> serviceProviders, Map<String, Set<String>> serviceLoaderCalls, Set<String> allKnownClasses, int appJavaVersion, Map<io.quarkus.maven.dependency.ArtifactKey, io.quarkus.paths.OpenPathTree> openTrees, List<Path> depJarPaths, List<Path> appPaths, Set<String> transformedClassNames, Map<String, List<Supplier<byte[]>>> higherVersionBytecode, Set<io.quarkus.maven.dependency.ArtifactKey> excludedArtifacts) Creates a new tree-shake input with all collected data. Prefer thecollect(io.quarkus.deployment.pkg.TreeShakeConfig.TreeShakeMode, io.quarkus.bootstrap.model.ApplicationModel, java.util.List<io.quarkus.deployment.builditem.GeneratedClassBuildItem>, io.quarkus.deployment.builditem.TransformedClassesBuildItem, java.util.List<io.quarkus.deployment.builditem.nativeimage.ReflectiveClassConditionBuildItem>, java.util.List<io.quarkus.deployment.pkg.builditem.JarTreeShakeRootClassBuildItem>, java.util.List<io.quarkus.deployment.pkg.builditem.JarTreeShakeExcludedArtifactBuildItem>)factory method, which assembles input from the application model and build items. This constructor is used internally bycollectand in tests.- Parameters:
treeShakeMode- configured tree-shake moderoots- unconditionally reachable class names (BFS starting points)conditionalRoots- condition class to classes that become roots when the condition is reachablesisuNamedClasses- classes fromMETA-INF/sisu/javax.inject.NameddepBytecode- bytecode suppliers for runtime dependency classesappBytecode- bytecode suppliers for application classesgeneratedBytecode- bytecode suppliers for build-time generated classesclassToDep- dependency class name to originating artifact mappingserviceProviders- service interface to provider class names fromMETA-INF/services/serviceLoaderCalls- service interface to consumer class names fromServiceLoader.load()callsallKnownClasses- union of dependency and generated class namesappJavaVersion- Java feature version detected from application bytecodeopenTrees- open content trees for dependencies, closed byclose()depJarPaths- filesystem paths of resolved runtime dependency JARsappPaths- filesystem paths of the application artifacttransformedClassNames- class names whose bytecode was replaced by a build-time transformationhigherVersionBytecode- multi-release bytecode for Java versions aboveappJavaVersionexcludedArtifacts- artifacts excluded from tree-shaking
-
-
Method Details
-
close
public void close()Closes allOpenPathTreeinstances opened during input collection.- Specified by:
closein interfaceAutoCloseable
-
getBytecode
Looks up the bytecode supplier for the given class name, checking generated, dependency, and application bytecode maps in priority order. -
hasBytecode
Returns true if bytecode is available for the given class name in any of the three bytecode maps. -
readBytecode
Reads bytecode for the given class. The returned byte[] is the only reference; once the caller drops it, the bytecode is eligible for GC. The supplier can re-read from disk if needed later. -
collect
static JarTreeShakeInput collect(TreeShakeConfig.TreeShakeMode treeShakeMode, io.quarkus.bootstrap.model.ApplicationModel appModel, List<GeneratedClassBuildItem> generatedClasses, TransformedClassesBuildItem transformedClasses, List<ReflectiveClassConditionBuildItem> reflectiveClassConditions, List<JarTreeShakeRootClassBuildItem> rootClasses, List<JarTreeShakeExcludedArtifactBuildItem> excludedArtifactItems) Factory method that assembles all input for the tree-shake analysis. Walks dependency and application JARs, collects bytecode, service provider metadata, and extracts root classes from generated classes, native-image build items, and string-constant class references.The caller must close the returned instance to release the opened dependency trees.
-
isClassEntry
Returnstrueif the resource name represents a regular class file, excludingmodule-info.classandpackage-info.class. -
classNameOf
Converts a class resource path (e.g.com/example/Foo.class) to a dot-separated class name (e.g.com.example.Foo). -
classNameOf
Converts a class resource path to a dot-separated class name, starting from the given index (used for multi-release entries to skip theMETA-INF/versions/N/prefix). -
releaseAnalysisData
void releaseAnalysisData()Releases all data structures. Must be called after stats computation is complete.
-