Class JarDiff


  • public class JarDiff
    extends java.lang.Object
    A class to perform a diff between two jar files.
    Author:
    Antony Riley
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map depClassInfo
      A map containing information about classes which are dependencies.
      private java.net.URLClassLoader depLoader
      A class loader used for loading dependency classes.
      private java.net.URL[] deps
      An array of dependencies which are jar files, or urls.
      private ClassInfoVisitor infoVisitor
      Class info visitor, used to load information about classes.
      protected java.util.Map newClassInfo
      A map containing information about classes in the new jar file.
      private java.lang.String newVersion
      The name of the new version.
      protected java.util.Map oldClassInfo
      A map containing information about classes in the old jar file.
      private java.lang.String oldVersion
      The name of the old version.
    • Constructor Summary

      Constructors 
      Constructor Description
      JarDiff()
      Create a new JarDiff object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void diff​(DiffHandler handler, DiffCriteria criteria)
      Perform a diff sending the output to the specified handler, using the specified criteria to select diffs.
      java.net.URL[] getDependencies()
      Get the dependencies.
      java.lang.String getNewVersion()
      Get the name of the new version.
      java.lang.String getOldVersion()
      Get the name of the old version.
      private void loadClasses​(java.util.Map infoMap, java.io.File file)
      Load all the classes from the specified URL and store information about them in the specified map.
      private void loadClasses​(java.util.Map infoMap, java.net.URL path)
      Load all the classes from the specified URL and store information about them in the specified map.
      private ClassInfo loadClassInfo​(org.objectweb.asm.ClassReader reader)
      Load classinfo given a ClassReader.
      void loadNewClasses​(java.io.File file)
      Load new classes from the specified File.
      void loadNewClasses​(java.net.URL loc)
      Load new classes from the specified URL.
      void loadOldClasses​(java.io.File file)
      Load old classes from the specified File.
      void loadOldClasses​(java.net.URL loc)
      Load old classes from the specified URL.
      void setDependencies​(java.net.URL[] deps)
      Set the dependencies.
      void setNewVersion​(java.lang.String newVersion)
      Set the name of the new version.
      void setOldVersion​(java.lang.String oldVersion)
      Set the name of the old version.
      • Methods inherited from class java.lang.Object

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

      • depClassInfo

        protected java.util.Map depClassInfo
        A map containing information about classes which are dependencies. Keys are internal class names. Values are instances of ClassInfo.
      • oldClassInfo

        protected java.util.Map oldClassInfo
        A map containing information about classes in the old jar file. Keys are internal class names. Values are instances of ClassInfo.
      • newClassInfo

        protected java.util.Map newClassInfo
        A map containing information about classes in the new jar file. Keys are internal class names. Values are instances of ClassInfo.
      • deps

        private java.net.URL[] deps
        An array of dependencies which are jar files, or urls.
      • depLoader

        private java.net.URLClassLoader depLoader
        A class loader used for loading dependency classes.
      • oldVersion

        private java.lang.String oldVersion
        The name of the old version.
      • newVersion

        private java.lang.String newVersion
        The name of the new version.
      • infoVisitor

        private ClassInfoVisitor infoVisitor
        Class info visitor, used to load information about classes.
    • Constructor Detail

      • JarDiff

        public JarDiff()
        Create a new JarDiff object.
    • Method Detail

      • setOldVersion

        public void setOldVersion​(java.lang.String oldVersion)
        Set the name of the old version.
        Parameters:
        oldVersion - the name
      • getOldVersion

        public java.lang.String getOldVersion()
        Get the name of the old version.
        Returns:
        the name
      • setNewVersion

        public void setNewVersion​(java.lang.String newVersion)
        Set the name of the new version.
        Parameters:
        newVersion -
      • getNewVersion

        public java.lang.String getNewVersion()
        Get the name of the new version.
        Returns:
        the name
      • setDependencies

        public void setDependencies​(java.net.URL[] deps)
        Set the dependencies.
        Parameters:
        deps - an array of urls pointing to jar files or directories containing classes which are required dependencies.
      • getDependencies

        public java.net.URL[] getDependencies()
        Get the dependencies.
        Returns:
        the dependencies as an array of URLs
      • loadClassInfo

        private ClassInfo loadClassInfo​(org.objectweb.asm.ClassReader reader)
                                 throws java.io.IOException
        Load classinfo given a ClassReader.
        Parameters:
        reader - the ClassReader
        Returns:
        the ClassInfo
        Throws:
        java.io.IOException
      • loadClasses

        private void loadClasses​(java.util.Map infoMap,
                                 java.net.URL path)
                          throws DiffException
        Load all the classes from the specified URL and store information about them in the specified map. This currently only works for jar files, not directories which contain classes in subdirectories or in the current directory.
        Parameters:
        infoMap - the map to store the ClassInfo in.
        Throws:
        DiffException - if there is an exception reading info about a class.
      • loadClasses

        private void loadClasses​(java.util.Map infoMap,
                                 java.io.File file)
                          throws DiffException
        Load all the classes from the specified URL and store information about them in the specified map. This currently only works for jar files, not directories which contain classes in subdirectories or in the current directory.
        Parameters:
        infoMap - the map to store the ClassInfo in.
        file - the jarfile to load classes from.
        Throws:
        java.io.IOException - if there is an IOException reading info about a class.
        DiffException
      • loadOldClasses

        public void loadOldClasses​(java.net.URL loc)
                            throws DiffException
        Load old classes from the specified URL.
        Parameters:
        loc - The location of a jar file to load classes from.
        Throws:
        DiffException - if there is an IOException.
      • loadNewClasses

        public void loadNewClasses​(java.net.URL loc)
                            throws DiffException
        Load new classes from the specified URL.
        Parameters:
        loc - The location of a jar file to load classes from.
        Throws:
        DiffException - if there is an IOException.
      • loadOldClasses

        public void loadOldClasses​(java.io.File file)
                            throws DiffException
        Load old classes from the specified File.
        Parameters:
        file - The location of a jar file to load classes from.
        Throws:
        DiffException - if there is an IOException
      • loadNewClasses

        public void loadNewClasses​(java.io.File file)
                            throws DiffException
        Load new classes from the specified File.
        Parameters:
        file - The location of a jar file to load classes from.
        Throws:
        DiffExeption - if there is an IOException
        DiffException
      • diff

        public void diff​(DiffHandler handler,
                         DiffCriteria criteria)
                  throws DiffException
        Perform a diff sending the output to the specified handler, using the specified criteria to select diffs.
        Parameters:
        handler - The handler to receive and handle differences.
        criteria - The criteria we use to select differences.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException