Class Retrofitter


  • public class Retrofitter
    extends java.lang.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).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Retrofitter.ClassRetrofitter
      A ClassVisitor that retrofits classes to 1.5 version.
      (package private) class  Retrofitter.ClassVerifier
      A ClassVisitor checking that a class uses only JDK 1.5 class file features and the JDK 1.5 API.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashSet<java.lang.String> exports
      The internal names of the packages exported by the retrofitted classes.
      private java.util.HashSet<java.lang.String> imports
      The internal names of the packages imported by the retrofitted classes.
      private static java.lang.String JAVA_BASE_MODULE
      The name of the java.base module.
      private java.util.HashSet<java.lang.String> jdkApi
      The fields and methods of the JDK 1.5 API.
      private java.util.HashMap<java.lang.String,​java.lang.String> jdkHierarchy
      The class hierarchy of the JDK 1.5 API.
      private static java.lang.String MODULE_INFO
      The name of the module-info file.
    • Constructor Summary

      Constructors 
      Constructor Description
      Retrofitter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void generateModuleInfoClass​(java.io.File dstDir, java.lang.String version)  
      private java.util.List<java.io.File> getAllClasses​(java.io.File file, java.util.List<java.io.File> allClasses)  
      private static boolean isAsmModule​(java.lang.String packageName)  
      static void main​(java.lang.String[] args)
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5.
      private void readJdkApi()  
      void retrofit​(java.io.File classesDir, java.lang.String version)
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5.
      void verify​(java.io.File classesDir, java.lang.String expectedVersion, java.util.List<java.lang.String> expectedExports, java.util.List<java.lang.String> expectedRequires)
      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.
      private void verifyModuleInfoClass​(java.io.File dstDir, java.lang.String expectedVersion, java.util.Set<java.lang.String> expectedExports, java.util.Set<java.lang.String> expectedRequires)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MODULE_INFO

        private static final java.lang.String MODULE_INFO
        The name of the module-info file.
        See Also:
        Constant Field Values
      • JAVA_BASE_MODULE

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

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

        private final java.util.HashMap<java.lang.String,​java.lang.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 java.util.HashSet<java.lang.String> exports
        The internal names of the packages exported by the retrofitted classes.
      • imports

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

      • Retrofitter

        public Retrofitter()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.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:
        java.io.IOException - if a file can't be read or written.
      • retrofit

        public void retrofit​(java.io.File classesDir,
                             java.lang.String version)
                      throws java.io.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:
        java.io.IOException - if a file can't be read or written.
      • verify

        public void verify​(java.io.File classesDir,
                           java.lang.String expectedVersion,
                           java.util.List<java.lang.String> expectedExports,
                           java.util.List<java.lang.String> expectedRequires)
                    throws java.io.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:
        java.io.IOException - if a file can't be read.
        java.lang.IllegalArgumentException - if the module-info class does not have the expected content.
      • getAllClasses

        private java.util.List<java.io.File> getAllClasses​(java.io.File file,
                                                           java.util.List<java.io.File> allClasses)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • generateModuleInfoClass

        private void generateModuleInfoClass​(java.io.File dstDir,
                                             java.lang.String version)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • verifyModuleInfoClass

        private void verifyModuleInfoClass​(java.io.File dstDir,
                                           java.lang.String expectedVersion,
                                           java.util.Set<java.lang.String> expectedExports,
                                           java.util.Set<java.lang.String> expectedRequires)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • isAsmModule

        private static boolean isAsmModule​(java.lang.String packageName)
      • readJdkApi

        private void readJdkApi()
                         throws java.io.IOException
        Throws:
        java.io.IOException