Class JarTreeShakeInput

java.lang.Object
io.quarkus.deployment.pkg.steps.JarTreeShakeInput
All Implemented Interfaces:
AutoCloseable

class JarTreeShakeInput extends Object implements AutoCloseable
Assembles all data needed by 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.

  • Field Details

    • treeShakeMode

      final TreeShakeConfig.TreeShakeMode treeShakeMode
      Configured tree-shake mode controlling analysis aggressiveness.
    • roots

      final Set<String> roots
      Dot-separated class names that are unconditionally reachable (BFS starting points).
    • conditionalRoots

      final Map<String,Set<String>> conditionalRoots
      Map from condition class to classes that become roots when the condition is reachable.
    • sisuNamedClasses

      final Set<String> sisuNamedClasses
      Classes listed in META-INF/sisu/javax.inject.Named files.
    • depBytecode

      final Map<String,Supplier<byte[]>> depBytecode
      Bytecode suppliers for runtime dependency classes, keyed by dot-separated class name.
    • appBytecode

      final Map<String,Supplier<byte[]>> appBytecode
      Bytecode suppliers for application classes, keyed by dot-separated class name.
    • generatedBytecode

      final Map<String,Supplier<byte[]>> generatedBytecode
      Bytecode suppliers for build-time generated classes, keyed by dot-separated class name.
    • classToDep

      final Map<String,io.quarkus.maven.dependency.ArtifactKey> classToDep
      Maps dot-separated dependency class names to their originating artifact.
    • serviceProviders

      final Map<String,Set<String>> serviceProviders
      Service interface to provider class names parsed from META-INF/services/ files.
    • serviceLoaderCalls

      final Map<String,Set<String>> serviceLoaderCalls
      Service interface to consumer class names detected via ServiceLoader.load() calls.
    • allKnownClasses

      final Set<String> allKnownClasses
      Union of dependency and generated class names, used for string-constant reference matching.
    • appJavaVersion

      final int appJavaVersion
      Java feature version detected from application bytecode (e.g. 17, 21).
    • openTrees

      final Map<io.quarkus.maven.dependency.ArtifactKey,io.quarkus.paths.OpenPathTree> openTrees
      Open content trees for dependencies, kept alive until close().
    • depJarPaths

      final List<Path> depJarPaths
      Filesystem paths of resolved runtime dependency JARs.
    • appPaths

      final List<Path> appPaths
      Filesystem paths of the application artifact.
    • transformedClassNames

      final Set<String> transformedClassNames
      Class names whose bytecode was replaced by a build-time transformation.
    • higherVersionBytecode

      final Map<String,List<Supplier<byte[]>>> higherVersionBytecode
      Bytecode from multi-release entries targeting Java versions newer than appJavaVersion. 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

      final Set<io.quarkus.maven.dependency.ArtifactKey> excludedArtifacts
      Artifacts excluded from tree-shaking via JarTreeShakeExcludedArtifactBuildItem.
  • Constructor Details

  • Method Details

    • close

      public void close()
      Closes all OpenPathTree instances opened during input collection.
      Specified by:
      close in interface AutoCloseable
    • getBytecode

      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.
    • hasBytecode

      boolean hasBytecode(String name)
      Returns true if bytecode is available for the given class name in any of the three bytecode maps.
    • readBytecode

      byte[] readBytecode(String name)
      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

      static boolean isClassEntry(String resourceName)
      Returns true if the resource name represents a regular class file, excluding module-info.class and package-info.class.
    • classNameOf

      static String classNameOf(String classResourceName)
      Converts a class resource path (e.g. com/example/Foo.class) to a dot-separated class name (e.g. com.example.Foo).
    • classNameOf

      static String classNameOf(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 the META-INF/versions/N/ prefix).
    • releaseAnalysisData

      void releaseAnalysisData()
      Releases all data structures. Must be called after stats computation is complete.