Class RewriteClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class RewriteClassLoader extends URLClassLoader
Rewrite uses jackson for serialization/deserialization. So do lots of other build plugins. Gradle plugins all share the same classpath at runtime.

This classloader exists to isolate rewrite's use of jackson from the rest of the build.

  • Constructor Details

  • Method Details

    • getPluginClassLoader

      public ClassLoader getPluginClassLoader()
    • loadClass

      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Load the named class. We want classes that extend org.openrewrite.Recipe to be loaded by this ClassLoader only. But we want classes required to run recipes to continue to be loaded by their parent ClassLoader to avoid ClassCastExceptions. In the case of Android Gradle plugin classes, we use the ClassLoader of the plugin.
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • shouldBeParentLoaded

      protected boolean shouldBeParentLoaded(String name)
    • shouldBePluginLoaded

      protected boolean shouldBePluginLoaded(String name)