Class CachingMavenRecipeBundleResolver

java.lang.Object
org.openrewrite.maven.marketplace.CachingMavenRecipeBundleResolver
All Implemented Interfaces:
AutoCloseable, org.openrewrite.marketplace.RecipeBundleResolver

public class CachingMavenRecipeBundleResolver extends Object implements org.openrewrite.marketplace.RecipeBundleResolver
Deduplicates MavenRecipeBundleResolver instances per package coordinate so that repeated resolve(RecipeBundle) calls for the same package share one reader (and therefore one RecipeClassLoader).

Lifetime of handed-out readers. The readers (and the RecipeClassLoaders they own) returned by resolve(RecipeBundle) are intended to outlive this resolver. Once a

invalid reference
Recipe
has been prepared from a reader, the JVM's class cache contains classes defined by that classloader, and any later getResourceAsStream/inner-class load against those classes requires the classloader's URLClassPath jar handles to remain open.

For that reason close() only clears the deduplication cache. It does not close the cached inner MavenRecipeBundleResolvers -- doing so would close their readers, which would close the underlying URLClassLoaders while consumers still hold references. The visible failure mode is inner-class NoClassDefFoundError and silently-null getResourceAsStream returns on a classloader that == identity confirms is still alive (see customer-requests#2346).

Consumers that need deterministic cleanup must close the RecipeBundleReaders they retain (or rely on JVM exit for one-shot processes).

  • Constructor Details

    • CachingMavenRecipeBundleResolver

      public CachingMavenRecipeBundleResolver()
  • Method Details

    • getEcosystem

      public String getEcosystem()
      Specified by:
      getEcosystem in interface org.openrewrite.marketplace.RecipeBundleResolver
    • resolve

      public org.openrewrite.marketplace.RecipeBundleReader resolve(org.openrewrite.marketplace.RecipeBundle bundle)
      Specified by:
      resolve in interface org.openrewrite.marketplace.RecipeBundleResolver
    • resolverFor

      public org.openrewrite.marketplace.RecipeBundleResolver resolverFor(org.openrewrite.marketplace.RecipeBundle bundle)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.openrewrite.marketplace.RecipeBundleResolver