Package japicmp.cmp
Class JarArchiveComparator
- java.lang.Object
-
- japicmp.cmp.JarArchiveComparator
-
public class JarArchiveComparator extends java.lang.Object
This class provides the basic methods to compare the classes within to jar archives.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JarArchiveComparator.ArchiveType
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
commonClassPathAsString
private javassist.ClassPool
commonClassPool
private static java.util.logging.Logger
LOGGER
private java.lang.String
newClassPathAsString
private javassist.ClassPool
newClassPool
private java.lang.String
oldClassPathAsString
private javassist.ClassPool
oldClassPool
private JarArchiveComparatorOptions
options
-
Constructor Summary
Constructors Constructor Description JarArchiveComparator(JarArchiveComparatorOptions options)
Constructs an instance of this class and performs a setup of the classpath
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
appendSystemClassPath(javassist.ClassPool classPool, java.lang.String classPathAsString)
private java.lang.String
appendUserDefinedClassPathEntries(javassist.ClassPool classPool, java.util.List<java.lang.String> classPathEntries)
private java.util.List<javassist.CtClass>
applyFilter(JarArchiveComparatorOptions options, java.util.List<javassist.CtClass> ctClasses)
private void
checkBinaryCompatibility(java.util.List<JApiClass> classList)
private void
checkJavaObjectSerializationCompatibility(java.util.List<JApiClass> jApiClasses)
java.util.List<JApiClass>
compare(JApiCmpArchive oldArchive, JApiCmpArchive newArchive)
Compares the two given archives.java.util.List<JApiClass>
compare(java.util.List<JApiCmpArchive> oldArchives, java.util.List<JApiCmpArchive> newArchives)
Compares the two given lists of archives.(package private) java.util.List<JApiClass>
compareClassLists(JarArchiveComparatorOptions options, java.util.List<javassist.CtClass> oldClasses, java.util.List<javassist.CtClass> newClasses)
Compares the two lists with CtClass objects using the provided options instance.private java.util.List<JApiClass>
createAndCompareClassLists(java.util.List<java.io.File> oldArchives, java.util.List<java.io.File> newArchives)
private java.util.List<javassist.CtClass>
createListOfCtClasses(java.util.List<java.io.File> archives, javassist.ClassPool classPool)
java.lang.String
getCommonClasspathAsString()
Returns the common classpath used byJarArchiveComparator
javassist.ClassPool
getCommonClassPool()
Returns the javassist ClassPool instance that is used by this instance.JarArchiveComparatorOptions
getJarArchiveComparatorOptions()
Returns the instance ofJarArchiveComparatorOptions
that is used.java.lang.String
getNewClassPathAsString()
Returns the classpath for the new version as String.javassist.ClassPool
getNewClassPool()
Returns the javassist ClassPool that is used for the new version.java.lang.String
getOldClassPathAsString()
Returns the classpath for the old version as String.javassist.ClassPool
getOldClassPool()
Returns the javassist ClassPool that is used for the old version.Optional<javassist.CtClass>
loadClass(JarArchiveComparator.ArchiveType archiveType, java.lang.String name)
Loads a class either from the old, new or common classpath.private java.lang.String
setupClasspath(javassist.ClassPool classPool, java.util.List<java.lang.String> classPathEntries)
private void
setupClasspaths()
private void
setupCompatibilityChanges(JarArchiveComparatorOptions options)
private void
updatePackageFilter(javassist.CtClass ctClass)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
commonClassPool
private javassist.ClassPool commonClassPool
-
oldClassPool
private javassist.ClassPool oldClassPool
-
newClassPool
private javassist.ClassPool newClassPool
-
commonClassPathAsString
private java.lang.String commonClassPathAsString
-
oldClassPathAsString
private java.lang.String oldClassPathAsString
-
newClassPathAsString
private java.lang.String newClassPathAsString
-
options
private final JarArchiveComparatorOptions options
-
-
Constructor Detail
-
JarArchiveComparator
public JarArchiveComparator(JarArchiveComparatorOptions options)
Constructs an instance of this class and performs a setup of the classpath- Parameters:
options
- the options used in the further processing
-
-
Method Detail
-
setupCompatibilityChanges
private void setupCompatibilityChanges(JarArchiveComparatorOptions options)
-
compare
public java.util.List<JApiClass> compare(JApiCmpArchive oldArchive, JApiCmpArchive newArchive)
Compares the two given archives.- Parameters:
oldArchive
- the old version of the archivenewArchive
- the new version of the archive- Returns:
- a list which contains one instance of
JApiClass
for each class found in one of the two archives - Throws:
JApiCmpException
- if the comparison fails
-
compare
public java.util.List<JApiClass> compare(java.util.List<JApiCmpArchive> oldArchives, java.util.List<JApiCmpArchive> newArchives)
Compares the two given lists of archives.- Parameters:
oldArchives
- the old versions of the archivesnewArchives
- the new versions of the archives- Returns:
- a list which contains one instance of
JApiClass
for each class found in one of the archives - Throws:
JApiCmpException
- if the comparison fails
-
checkJavaObjectSerializationCompatibility
private void checkJavaObjectSerializationCompatibility(java.util.List<JApiClass> jApiClasses)
-
setupClasspaths
private void setupClasspaths()
-
setupClasspath
private java.lang.String setupClasspath(javassist.ClassPool classPool, java.util.List<java.lang.String> classPathEntries)
-
appendSystemClassPath
private java.lang.String appendSystemClassPath(javassist.ClassPool classPool, java.lang.String classPathAsString)
-
appendUserDefinedClassPathEntries
private java.lang.String appendUserDefinedClassPathEntries(javassist.ClassPool classPool, java.util.List<java.lang.String> classPathEntries)
-
getCommonClasspathAsString
public java.lang.String getCommonClasspathAsString()
Returns the common classpath used byJarArchiveComparator
- Returns:
- the common classpath as String
-
getOldClassPathAsString
public java.lang.String getOldClassPathAsString()
Returns the classpath for the old version as String.- Returns:
- the classpath for the old version
-
getNewClassPathAsString
public java.lang.String getNewClassPathAsString()
Returns the classpath for the new version as String.- Returns:
- the classpath for the new version
-
checkBinaryCompatibility
private void checkBinaryCompatibility(java.util.List<JApiClass> classList)
-
createAndCompareClassLists
private java.util.List<JApiClass> createAndCompareClassLists(java.util.List<java.io.File> oldArchives, java.util.List<java.io.File> newArchives)
-
compareClassLists
java.util.List<JApiClass> compareClassLists(JarArchiveComparatorOptions options, java.util.List<javassist.CtClass> oldClasses, java.util.List<javassist.CtClass> newClasses)
Compares the two lists with CtClass objects using the provided options instance.- Parameters:
options
- the options to useoldClasses
- a list of CtClasses that represent the old versionnewClasses
- a list of CtClasses that represent the new version- Returns:
- a list of
JApiClass
that represent the changes
-
applyFilter
private java.util.List<javassist.CtClass> applyFilter(JarArchiveComparatorOptions options, java.util.List<javassist.CtClass> ctClasses)
-
createListOfCtClasses
private java.util.List<javassist.CtClass> createListOfCtClasses(java.util.List<java.io.File> archives, javassist.ClassPool classPool)
-
updatePackageFilter
private void updatePackageFilter(javassist.CtClass ctClass)
-
getJarArchiveComparatorOptions
public JarArchiveComparatorOptions getJarArchiveComparatorOptions()
Returns the instance ofJarArchiveComparatorOptions
that is used.- Returns:
- an instance of
JarArchiveComparatorOptions
-
getCommonClassPool
public javassist.ClassPool getCommonClassPool()
Returns the javassist ClassPool instance that is used by this instance. This can be used in unit tests to define artificial CtClass instances for the same ClassPool.- Returns:
- an instance of ClassPool
-
getOldClassPool
public javassist.ClassPool getOldClassPool()
Returns the javassist ClassPool that is used for the old version.- Returns:
- an instance of ClassPool
-
getNewClassPool
public javassist.ClassPool getNewClassPool()
Returns the javassist ClassPool that is used for the new version.- Returns:
- an instance of ClassPool
-
loadClass
public Optional<javassist.CtClass> loadClass(JarArchiveComparator.ArchiveType archiveType, java.lang.String name)
Loads a class either from the old, new or common classpath.- Parameters:
archiveType
- specify if this class should be loaded from the old or new class pathname
- the name of the class (FQN)- Returns:
- the loaded class (if options are not set to ignore missing classes)
- Throws:
JApiCmpException
- if loading the class fails
-
-