/** * Constructs an instance of this class and performs a setup of the classpath * * @param options the options used in the further processing */ public JarArchiveComparator(JarArchiveComparatorOptions options) { this.options = options; setupClasspaths(); setupCompatibilityChanges(options); }
private String setupClasspath(ClassPool classPool, List<String> classPathEntries) { String classPathAsString = appendUserDefinedClassPathEntries(classPool, classPathEntries); return appendSystemClassPath(classPool, classPathAsString); }
public JApiCmpArchive toJapicmpArchive() { return new JApiCmpArchive(file, version); } }
public void run(String[] args) { CliParser cliParser = new CliParser(); Options options = cliParser.parse(args); if (options.isHelpRequested()) { CliParser.printHelp(); return; } JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(JarArchiveComparatorOptions.of(options)); List<JApiClass> jApiClasses = jarArchiveComparator.compare(options.getOldArchives(), options.getNewArchives()); generateOutput(options, jApiClasses, jarArchiveComparator); }
private void setupClasspaths() { if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH) { commonClassPool = new ClassPool(); commonClassPathAsString = setupClasspath(commonClassPool, this.options.getClassPathEntries()); } else if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { oldClassPool = new ClassPool(); oldClassPathAsString = setupClasspath(oldClassPool, this.options.getOldClassPath()); newClassPool = new ClassPool(); newClassPathAsString = setupClasspath(newClassPool, this.options.getNewClassPath()); } else { throw new JApiCmpException(Reason.IllegalState, "Unknown classpath mode: " + this.options.getClassPathMode()); } }
public static JApiCmpException forClassLoading(String name, JarArchiveComparator jarArchiveComparator) { String classPathAsString = "(CLASSPATH=" + jarArchiveComparator.getCommonClasspathAsString() + ")"; if (jarArchiveComparator.getJarArchiveComparatorOptions().getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { classPathAsString = "(OLD CLASSPATH=" + jarArchiveComparator.getOldClassPathAsString() + " / NEW CLASSPATH=" + jarArchiveComparator.getNewClassPathAsString() + ")"; } return new JApiCmpException(JApiCmpException.Reason.ClassLoading, "Could not load '" + name + "'. Please make sure that all libraries have been added to the classpath " + classPathAsString + " or try the option '--ignore-missing-classes'."); } }
private void setupCompatibilityChanges(JarArchiveComparatorOptions options) { for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) { jApiCompatibility.resetOverrides(); } for (JarArchiveComparatorOptions.OverrideCompatibilityChange change : options.getOverrideCompatibilityChanges()) { JApiCompatibilityChange compatibilityChange = change.getCompatibilityChange(); for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) { if (jApiCompatibility == compatibilityChange) { jApiCompatibility.setBinaryCompatible(change.isBinaryCompatible()); jApiCompatibility.setSourceCompatible(change.isSourceCompatible()); jApiCompatibility.setSemanticVersionLevel(change.getSemanticVersionLevel()); } } } }
/** * Compares the two given archives. * * @param oldArchive the old version of the archive * @param newArchive the new version of the archive * @return a list which contains one instance of {@link japicmp.model.JApiClass} for each class found in one of the two archives * @throws JApiCmpException if the comparison fails */ public List<JApiClass> compare(JApiCmpArchive oldArchive, JApiCmpArchive newArchive) { return compare(Collections.singletonList(oldArchive), Collections.singletonList(newArchive)); }
private List<JApiClass> createAndCompareClassLists(List<File> oldArchives, List<File> newArchives) { List<CtClass> oldClasses; List<CtClass> newClasses; if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH) { oldClasses = createListOfCtClasses(oldArchives, commonClassPool); newClasses = createListOfCtClasses(newArchives, commonClassPool); return compareClassLists(options, oldClasses, newClasses); } else if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { oldClasses = createListOfCtClasses(oldArchives, oldClassPool); newClasses = createListOfCtClasses(newArchives, newClassPool); return compareClassLists(options, oldClasses, newClasses); } else { throw new JApiCmpException(Reason.IllegalState, "Unknown classpath mode: " + this.options.getClassPathMode()); } }
public void compare(List<CtClass> oldClassesArg, List<CtClass> newClassesArg) { classes = new LinkedList<>(); Map<String, CtClass> oldClassesMap = createClassMap(oldClassesArg); Map<String, CtClass> newClassesMap = createClassMap(newClassesArg); sortIntoLists(oldClassesMap, newClassesMap); }
/** * Compares the two given lists of archives. * * @param oldArchives the old versions of the archives * @param newArchives the new versions of the archives * @return a list which contains one instance of {@link japicmp.model.JApiClass} for each class found in one of the archives * @throws JApiCmpException if the comparison fails */ public List<JApiClass> compare(List<JApiCmpArchive> oldArchives, List<JApiCmpArchive> newArchives) { return createAndCompareClassLists(toFileList(oldArchives), toFileList(newArchives)); }
private void setupClasspaths() { if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH) { commonClassPool = new ClassPool(); commonClassPathAsString = setupClasspath(commonClassPool, this.options.getClassPathEntries()); } else if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { oldClassPool = new ClassPool(); oldClassPathAsString = setupClasspath(oldClassPool, this.options.getOldClassPath()); newClassPool = new ClassPool(); newClassPathAsString = setupClasspath(newClassPool, this.options.getNewClassPath()); } else { throw new JApiCmpException(Reason.IllegalState, "Unknown classpath mode: " + this.options.getClassPathMode()); } }
public static JApiCmpException forClassLoading(String name, JarArchiveComparator jarArchiveComparator) { String classPathAsString = "(CLASSPATH=" + jarArchiveComparator.getCommonClasspathAsString() + ")"; if (jarArchiveComparator.getJarArchiveComparatorOptions().getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { classPathAsString = "(OLD CLASSPATH=" + jarArchiveComparator.getOldClassPathAsString() + " / NEW CLASSPATH=" + jarArchiveComparator.getNewClassPathAsString() + ")"; } return new JApiCmpException(JApiCmpException.Reason.ClassLoading, "Could not load '" + name + "'. Please make sure that all libraries have been added to the classpath " + classPathAsString + " or try the option '--ignore-missing-classes'."); } }
private void setupCompatibilityChanges(JarArchiveComparatorOptions options) { for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) { jApiCompatibility.resetOverrides(); } for (JarArchiveComparatorOptions.OverrideCompatibilityChange change : options.getOverrideCompatibilityChanges()) { JApiCompatibilityChange compatibilityChange = change.getCompatibilityChange(); for (JApiCompatibilityChange jApiCompatibility : JApiCompatibilityChange.values()) { if (jApiCompatibility == compatibilityChange) { jApiCompatibility.setBinaryCompatible(change.isBinaryCompatible()); jApiCompatibility.setSourceCompatible(change.isSourceCompatible()); jApiCompatibility.setSemanticVersionLevel(change.getSemanticVersionLevel()); } } } }
/** * Compares the two given archives. * * @param oldArchive the old version of the archive * @param newArchive the new version of the archive * @return a list which contains one instance of {@link japicmp.model.JApiClass} for each class found in one of the two archives * @throws JApiCmpException if the comparison fails */ public List<JApiClass> compare(JApiCmpArchive oldArchive, JApiCmpArchive newArchive) { return compare(Collections.singletonList(oldArchive), Collections.singletonList(newArchive)); }
private List<JApiClass> createAndCompareClassLists(List<File> oldArchives, List<File> newArchives) { List<CtClass> oldClasses; List<CtClass> newClasses; if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH) { oldClasses = createListOfCtClasses(oldArchives, commonClassPool); newClasses = createListOfCtClasses(newArchives, commonClassPool); return compareClassLists(options, oldClasses, newClasses); } else if (this.options.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { oldClasses = createListOfCtClasses(oldArchives, oldClassPool); newClasses = createListOfCtClasses(newArchives, newClassPool); return compareClassLists(options, oldClasses, newClasses); } else { throw new JApiCmpException(Reason.IllegalState, "Unknown classpath mode: " + this.options.getClassPathMode()); } }
/** * Constructs an instance of this class and performs a setup of the classpath * * @param options the options used in the further processing */ public JarArchiveComparator(JarArchiveComparatorOptions options) { this.options = options; setupClasspaths(); setupCompatibilityChanges(options); }
private String setupClasspath(ClassPool classPool, List<String> classPathEntries) { String classPathAsString = appendUserDefinedClassPathEntries(classPool, classPathEntries); return appendSystemClassPath(classPool, classPathAsString); }
public static JApiCmpException forClassLoading(Exception e, String name, JarArchiveComparator jarArchiveComparator) { String classPathAsString = "(CLASSPATH=" + jarArchiveComparator.getCommonClasspathAsString() + ")"; if (jarArchiveComparator.getJarArchiveComparatorOptions().getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { classPathAsString = "(OLD CLASSPATH=" + jarArchiveComparator.getOldClassPathAsString() + " / NEW CLASSPATH=" + jarArchiveComparator.getNewClassPathAsString() + ")"; } return new JApiCmpException(JApiCmpException.Reason.ClassLoading, "Could not load '" + name + "': " + e.getMessage() + ". Please make sure that all libraries have been added to the classpath " + classPathAsString + " or try the option '--ignore-missing-classes'.", e); }
public static JApiCmpException forClassLoading(Exception e, String name, JarArchiveComparator jarArchiveComparator) { String classPathAsString = "(CLASSPATH=" + jarArchiveComparator.getCommonClasspathAsString() + ")"; if (jarArchiveComparator.getJarArchiveComparatorOptions().getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) { classPathAsString = "(OLD CLASSPATH=" + jarArchiveComparator.getOldClassPathAsString() + " / NEW CLASSPATH=" + jarArchiveComparator.getNewClassPathAsString() + ")"; } return new JApiCmpException(JApiCmpException.Reason.ClassLoading, "Could not load '" + name + "': " + e.getMessage() + ". Please make sure that all libraries have been added to the classpath " + classPathAsString + " or try the option '--ignore-missing-classes'.", e); }