Class ClassPathTransform

java.lang.Object
io.micronaut.aot.bytecode.ClassPathTransform

@Internal public final class ClassPathTransform extends Object
Rewrites the class files of an application's runtime class path at build time, for the build plugins to package the result instead of the original jars.

It has two steps, which a request enables separately: desugaring the lambda and method-reference call sites of every entry (ClassPathTransform.Request.Builder.desugarLambdas(boolean)), and stripping the local-variable tables of the third-party jars a caller names (ClassPathTransform.Request.Builder.stripLocalVariables(Collection)). They run in one pass, in that order: each class is parsed, rewritten and verified once, against a model of the whole class path, never against the build tool's own class path; a class whose rewrite verifies worse than the original, or on which a step fails, is written without that step, or as it was. An entry with a rewritten class, a jar or a directory, is copied whole, under its own file name, into a directory of its own below the request's output directory; every other class path entry keeps its own path, its bytes and its hash. The transform never loads a class of the class path, and it logs nothing: the ClassPathTransform.Result carries a summary and warnings for the caller to log, and the counts of each entry as numbers, for the caller to report in its own format.

The rewritten bytes depend on the JDK that runs the transform: they are reproducible with the same JDK build, whatever the parallelism.

Since:
3.2.0
  • Method Details

    • run

      Rewrites what it can prove safe and leaves everything else as it is. It throws only when it cannot read a class path entry it rewrites, or cannot write its output, never because of a class it cannot rewrite.
      Parameters:
      request - what to rewrite
      Returns:
      the class path to package, and what was done
      Throws:
      IOException - if a jar to rewrite, or an entry of the class path, cannot be read, or a copy cannot be written