Class Retrofitter

java.lang.Object
org.objectweb.asm.tools.Retrofitter

public class Retrofitter extends Object
A tool to transform classes in order to make them compatible with Java 1.5, and to check that they use only the JDK 1.5 API and JDK 1.5 class file features. The original classes can either be transformed "in place", or be copied first to destination directory and transformed here (leaving the original classes unchanged).
  • Field Details

    • MODULE_INFO

      private static final String MODULE_INFO
      The name of the module-info file.
      See Also:
    • JAVA_BASE_MODULE

      private static final String JAVA_BASE_MODULE
      The name of the java.base module.
      See Also:
    • jdkApi

      private final HashSet<String> jdkApi
      The fields and methods of the JDK 1.5 API. Each string has the form "<owner><name><descriptor>".
    • jdkHierarchy

      private final HashMap<String,String> jdkHierarchy
      The class hierarchy of the JDK 1.5 API. Maps each class name to the name of its super class.
    • exports

      private final HashSet<String> exports
      The internal names of the packages exported by the retrofitted classes.
    • imports

      private final HashSet<String> imports
      The internal names of the packages imported by the retrofitted classes.
  • Constructor Details

    • Retrofitter

      public Retrofitter()
  • Method Details

    • main

      public static void main(String[] args) throws IOException
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5. Also generates a module-info class in this directory, with the given module version.
      Parameters:
      args - a directory containing compiled classes and the ASM release version.
      Throws:
      IOException - if a file can't be read or written.
    • retrofit

      public void retrofit(File classesDir, String version) throws IOException
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5. Also generates a module-info class in this directory, with the given module version.
      Parameters:
      classesDir - a directory containing compiled classes.
      version - the module-info version.
      Throws:
      IOException - if a file can't be read or written.
    • verify

      public void verify(File classesDir, String expectedVersion, List<String> expectedExports, List<String> expectedRequires) throws IOException
      Verify that the class files in the given directory only use JDK 1.5 APIs, and that a module-info class is present with the expected content.
      Parameters:
      classesDir - a directory containing compiled classes.
      expectedVersion - the expected module-info version.
      expectedExports - the expected module-info exported packages.
      expectedRequires - the expected module-info required modules.
      Throws:
      IOException - if a file can't be read.
      IllegalArgumentException - if the module-info class does not have the expected content.
    • getAllClasses

      private List<File> getAllClasses(File file, List<File> allClasses) throws IOException
      Throws:
      IOException
    • generateModuleInfoClass

      private void generateModuleInfoClass(File dstDir, String version) throws IOException
      Throws:
      IOException
    • verifyModuleInfoClass

      private void verifyModuleInfoClass(File dstDir, String expectedVersion, Set<String> expectedExports, Set<String> expectedRequires) throws IOException
      Throws:
      IOException
    • isAsmModule

      private static boolean isAsmModule(String packageName)
    • readJdkApi

      private void readJdkApi() throws IOException
      Throws:
      IOException