diff options
author | Timo Westkämper <[email protected]> | 2014-04-22 17:03:16 +0300 |
---|---|---|
committer | Timo Westkämper <[email protected]> | 2014-04-22 17:03:16 +0300 |
commit | 149be250f648162b79b0e73ab9dfa32d97ddaf97 (patch) | |
tree | 7de60eb4d601be75d213e53745e6577bf5e04832 /api | |
parent | 65ce1e5e8027f3b43905d18e2520e7c7307fe4de (diff) |
Use generics
Diffstat (limited to 'api')
8 files changed, 159 insertions, 212 deletions
diff --git a/api/src/main/java/org/osjava/jardiff/AbstractInfo.java b/api/src/main/java/org/osjava/jardiff/AbstractInfo.java index cae9cdf..bf892e6 100644 --- a/api/src/main/java/org/osjava/jardiff/AbstractInfo.java +++ b/api/src/main/java/org/osjava/jardiff/AbstractInfo.java @@ -261,7 +261,7 @@ public abstract class AbstractInfo * Well, it probably shouldn't be set on a class as it would make * no sense, it only really makes sense on fields and methods. * - * @return true if it is vargargs. + * @return true if it is varargs. */ public final boolean isVarargs() { return (this instanceof MethodInfo) && @@ -278,7 +278,7 @@ public abstract class AbstractInfo } /** - * Retrivie the access level for this class, method or field. + * Retrieve the access level for this class, method or field. * * @return the access level */ diff --git a/api/src/main/java/org/osjava/jardiff/ClassInfo.java b/api/src/main/java/org/osjava/jardiff/ClassInfo.java index 7803594..5058048 100644 --- a/api/src/main/java/org/osjava/jardiff/ClassInfo.java +++ b/api/src/main/java/org/osjava/jardiff/ClassInfo.java @@ -40,7 +40,7 @@ public final class ClassInfo extends AbstractInfo private String supername; /** - * An array of names of internal classnames of interfaces implmented + * An array of names of internal classnames of interfaces implemented * by the class. */ private String[] interfaces; @@ -49,13 +49,13 @@ public final class ClassInfo extends AbstractInfo * A map of method signature to MethodInfo, for the methods provided * by this class. */ - private Map methodMap; + private Map<String, MethodInfo> methodMap; /** * A map of field signature to FieldInfo, for the fields provided by * this class. */ - private Map fieldMap; + private Map<String, FieldInfo> fieldMap; /** * Create a new classinfo. @@ -70,8 +70,8 @@ public final class ClassInfo extends AbstractInfo * @param fieldMap a map of fields provided by this class. */ public ClassInfo(int version, int access, String name, String signature, - String supername, String[] interfaces, Map methodMap, - Map fieldMap) { + String supername, String[] interfaces, Map<String, MethodInfo> methodMap, + Map<String, FieldInfo> fieldMap) { super(access, name); this.version = version; this.signature = signature; @@ -122,7 +122,7 @@ public final class ClassInfo extends AbstractInfo * * @return a map with method signatures as keys, and MethodInfos as values. */ - public final Map getMethodMap() { + public final Map<String, MethodInfo> getMethodMap() { return methodMap; } @@ -131,7 +131,7 @@ public final class ClassInfo extends AbstractInfo * * @return a map with field signatures as keys, and FieldInfos as values. */ - public final Map getFieldMap() { + public final Map<String, FieldInfo> getFieldMap() { return fieldMap; } } diff --git a/api/src/main/java/org/osjava/jardiff/ClassInfoVisitor.java b/api/src/main/java/org/osjava/jardiff/ClassInfoVisitor.java index 690e97d..890b589 100644 --- a/api/src/main/java/org/osjava/jardiff/ClassInfoVisitor.java +++ b/api/src/main/java/org/osjava/jardiff/ClassInfoVisitor.java @@ -64,20 +64,20 @@ public class ClassInfoVisitor extends EmptyVisitor /** * A map of method signature to a MethodInfo describing the method. */ - private Map methodMap; + private Map<String, MethodInfo> methodMap; /** * A map of field signature to a FieldInfo describing the field. */ - private Map fieldMap; + private Map<String, FieldInfo> fieldMap; /** * Reset this ClassInfoVisitor so that it can be used to visit another * class. */ public void reset() { - methodMap = new HashMap(); - fieldMap = new HashMap(); + methodMap = new HashMap<String, MethodInfo>(); + fieldMap = new HashMap<String, FieldInfo>(); } /** diff --git a/api/src/main/java/org/osjava/jardiff/FieldInfo.java b/api/src/main/java/org/osjava/jardiff/FieldInfo.java index 60ffa8c..bf7f53e 100644 --- a/api/src/main/java/org/osjava/jardiff/FieldInfo.java +++ b/api/src/main/java/org/osjava/jardiff/FieldInfo.java @@ -43,7 +43,7 @@ public final class FieldInfo extends AbstractInfo * * @param access The access flags. * @param name The name of the field. - * @param desc The field discriptor. + * @param desc The field descriptor. * @param signature The signature of this field. * @param value The initial value of the field. */ diff --git a/api/src/main/java/org/osjava/jardiff/JarDiff.java b/api/src/main/java/org/osjava/jardiff/JarDiff.java index dcf6454..432993a 100644 --- a/api/src/main/java/org/osjava/jardiff/JarDiff.java +++ b/api/src/main/java/org/osjava/jardiff/JarDiff.java @@ -15,21 +15,17 @@ * limitations under the License. */ package org.osjava.jardiff; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; + +import java.io.*; import java.net.URL; import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeSet; -import java.util.TreeMap; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.Opcodes; + /* import javax.xml.transform.ErrorListener; import javax.xml.transform.Transformer; @@ -41,11 +37,6 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; */ - - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.Opcodes; - /** * A class to perform a diff between two jar files. * @@ -65,14 +56,14 @@ public class JarDiff * Keys are internal class names. * Values are instances of ClassInfo. */ - protected Map oldClassInfo = new TreeMap(); + protected Map<String, ClassInfo> oldClassInfo = new TreeMap<String, ClassInfo>(); /** * A map containing information about classes in the new jar file. * Keys are internal class names. * Values are instances of ClassInfo. */ - protected Map newClassInfo = new TreeMap(); + protected Map<String, ClassInfo> newClassInfo = new TreeMap<String, ClassInfo>(); /** * An array of dependencies which are jar files, or urls. @@ -166,7 +157,7 @@ public class JarDiff * @param reader the ClassReader * @return the ClassInfo */ - private synchronized ClassInfo loadClassInfo(ClassReader reader) + public synchronized ClassInfo loadClassInfo(ClassReader reader) throws IOException { infoVisitor.reset(); @@ -297,125 +288,107 @@ public class JarDiff diff(handler, criteria, oldVersion, newVersion, oldClassInfo, newClassInfo); } - private void diff(DiffHandler handler, DiffCriteria criteria, + public void diff(DiffHandler handler, DiffCriteria criteria, String oldVersion, String newVersion, - Map oldClassInfo, Map newClassInfo) throws DiffException + Map<String, ClassInfo> oldClassInfo, Map<String, ClassInfo> newClassInfo) throws DiffException { // TODO: Build the name from the MANIFEST rather than the filename handler.startDiff(oldVersion, newVersion); - Iterator i; handler.startOldContents(); - i = oldClassInfo.entrySet().iterator(); - while(i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - ClassInfo ci = (ClassInfo) entry.getValue(); - if(criteria.validClass(ci)) { + for (ClassInfo ci : oldClassInfo.values()) { + if (criteria.validClass(ci)) { handler.contains(ci); } } handler.endOldContents(); handler.startNewContents(); - i = newClassInfo.entrySet().iterator(); - while(i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - ClassInfo ci = (ClassInfo) entry.getValue(); - if(criteria.validClass(ci)) { + for (ClassInfo ci : newClassInfo.values()) { + if (criteria.validClass(ci)) { handler.contains(ci); } } handler.endNewContents(); - java.util.Set onlyOld = new TreeSet(oldClassInfo.keySet()); - java.util.Set onlyNew = new TreeSet(newClassInfo.keySet()); - java.util.Set both = new TreeSet(oldClassInfo.keySet()); + Set<String> onlyOld = new TreeSet<String>(oldClassInfo.keySet()); + Set<String> onlyNew = new TreeSet<String>(newClassInfo.keySet()); + Set<String> both = new TreeSet<String>(oldClassInfo.keySet()); onlyOld.removeAll(newClassInfo.keySet()); onlyNew.removeAll(oldClassInfo.keySet()); both.retainAll(newClassInfo.keySet()); + handler.startRemoved(); - i = onlyOld.iterator(); - while (i.hasNext()) { - String s = (String) i.next(); - ClassInfo ci = (ClassInfo) oldClassInfo.get(s); - if (criteria.validClass(ci)) + for (String s : onlyOld) { + ClassInfo ci = oldClassInfo.get(s); + if (criteria.validClass(ci)) { handler.classRemoved(ci); + } } handler.endRemoved(); + handler.startAdded(); - i = onlyNew.iterator(); - while (i.hasNext()) { - String s = (String) i.next(); - ClassInfo ci = (ClassInfo) newClassInfo.get(s); - if (criteria.validClass(ci)) + for (String s : onlyNew) { + ClassInfo ci = newClassInfo.get(s); + if (criteria.validClass(ci)) { handler.classAdded(ci); + } } handler.endAdded(); - java.util.Set removedMethods = new TreeSet(); - java.util.Set removedFields = new TreeSet(); - java.util.Set addedMethods = new TreeSet(); - java.util.Set addedFields = new TreeSet(); - java.util.Set changedMethods = new TreeSet(); - java.util.Set changedFields = new TreeSet(); + + Set<String> removedMethods = new TreeSet<String>(); + Set<String> removedFields = new TreeSet<String>(); + Set<String> addedMethods = new TreeSet<String>(); + Set<String> addedFields = new TreeSet<String>(); + Set<String> changedMethods = new TreeSet<String>(); + Set<String> changedFields = new TreeSet<String>(); + handler.startChanged(); - i = both.iterator(); - while (i.hasNext()) { - String s = (String) i.next(); - ClassInfo oci = (ClassInfo) oldClassInfo.get(s); - ClassInfo nci = (ClassInfo) newClassInfo.get(s); + for (String s : both) { + ClassInfo oci = oldClassInfo.get(s); + ClassInfo nci = newClassInfo.get(s); if (criteria.validClass(oci) || criteria.validClass(nci)) { - Map oldMethods = oci.getMethodMap(); - Map oldFields = oci.getFieldMap(); - Map newMethods = nci.getMethodMap(); - Map newFields = nci.getFieldMap(); + Map<String, MethodInfo> oldMethods = oci.getMethodMap(); + Map<String, FieldInfo> oldFields = oci.getFieldMap(); + Map<String, MethodInfo> newMethods = nci.getMethodMap(); + Map<String, FieldInfo> newFields = nci.getFieldMap(); - Map extNewMethods = new HashMap(newMethods); - Map extNewFields = new HashMap(newFields); + Map<String, MethodInfo> extNewMethods = new HashMap<String, MethodInfo>(newMethods); + Map<String, FieldInfo> extNewFields = new HashMap<String, FieldInfo>(newFields); String superClass = nci.getSupername(); while (superClass != null && newClassInfo.containsKey(superClass)) { - ClassInfo sci = (ClassInfo) newClassInfo.get(superClass); - Iterator j = sci.getFieldMap().entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (!((FieldInfo)entry.getValue()).isPrivate() - && !extNewFields.containsKey(entry.getKey())) { + ClassInfo sci = newClassInfo.get(superClass); + for (Map.Entry<String, FieldInfo> entry : sci.getFieldMap().entrySet()) { + if (!(entry.getValue()).isPrivate() + && !extNewFields.containsKey(entry.getKey())) { extNewFields.put(entry.getKey(), entry.getValue()); } } - j = sci.getMethodMap().entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (!((MethodInfo)entry.getValue()).isPrivate() - && !extNewMethods.containsKey(entry.getKey())) { + for (Map.Entry<String, MethodInfo> entry : sci.getMethodMap().entrySet()) { + if (!(entry.getValue()).isPrivate() + && !extNewMethods.containsKey(entry.getKey())) { extNewMethods.put(entry.getKey(), entry.getValue()); } } superClass = sci.getSupername(); } - Iterator j = oldMethods.entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (criteria.validMethod((MethodInfo) entry.getValue())) + for (Map.Entry<String, MethodInfo> entry : oldMethods.entrySet()) { + if (criteria.validMethod(entry.getValue())) removedMethods.add(entry.getKey()); } - j = oldFields.entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (criteria.validField((FieldInfo) entry.getValue())) + for (Map.Entry<String, FieldInfo> entry : oldFields.entrySet()) { + if (criteria.validField(entry.getValue())) removedFields.add(entry.getKey()); } - j = newMethods.entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (criteria.validMethod((MethodInfo) entry.getValue())) + + for (Map.Entry<String, MethodInfo> entry : newMethods.entrySet()) { + if (criteria.validMethod(entry.getValue())) addedMethods.add(entry.getKey()); } - j = newFields.entrySet().iterator(); - while (j.hasNext()) { - Map.Entry entry = (Map.Entry) j.next(); - if (criteria.validField((FieldInfo) entry.getValue())) + for (Map.Entry<String, FieldInfo> entry : newFields.entrySet()) { + if (criteria.validField(entry.getValue())) addedFields.add(entry.getKey()); } @@ -429,90 +402,87 @@ public class JarDiff removedFields.removeAll(changedFields); removedFields.removeAll(extNewFields.keySet()); addedFields.removeAll(changedFields); - j = changedMethods.iterator(); + + Iterator<String> j = changedMethods.iterator(); while (j.hasNext()) { - String desc = (String) j.next(); - MethodInfo oldInfo = (MethodInfo) oldMethods.get(desc); - MethodInfo newInfo = (MethodInfo) newMethods.get(desc); + String desc = j.next(); + MethodInfo oldInfo = oldMethods.get(desc); + MethodInfo newInfo = newMethods.get(desc); if (!criteria.differs(oldInfo, newInfo)) j.remove(); } j = changedFields.iterator(); while (j.hasNext()) { - String desc = (String) j.next(); - FieldInfo oldInfo = (FieldInfo) oldFields.get(desc); - FieldInfo newInfo = (FieldInfo) newFields.get(desc); + String desc = j.next(); + FieldInfo oldInfo = oldFields.get(desc); + FieldInfo newInfo = newFields.get(desc); if (!criteria.differs(oldInfo, newInfo)) j.remove(); } + boolean classchanged = criteria.differs(oci, nci); if (classchanged || !removedMethods.isEmpty() || !removedFields.isEmpty() || !addedMethods.isEmpty() || !addedFields.isEmpty() || !changedMethods.isEmpty() || !changedFields.isEmpty()) { handler.startClassChanged(s); + handler.startRemoved(); - j = removedFields.iterator(); - while (j.hasNext()) - handler - .fieldRemoved((FieldInfo) oldFields.get(j.next())); - j = removedMethods.iterator(); - while (j.hasNext()) - handler.methodRemoved((MethodInfo) - oldMethods.get(j.next())); + for (String field : removedFields) { + handler.fieldRemoved(oldFields.get(field)); + } + for (String method : removedMethods) { + handler.methodRemoved(oldMethods.get(method)); + } handler.endRemoved(); + handler.startAdded(); - j = addedFields.iterator(); - while (j.hasNext()) - handler - .fieldAdded((FieldInfo) newFields.get(j.next())); - j = addedMethods.iterator(); - while (j.hasNext()) - handler.methodAdded((MethodInfo) - newMethods.get(j.next())); + for (String field : addedFields) { + handler.fieldAdded(newFields.get(field)); + } + for (String method : addedMethods) { + handler.methodAdded(newMethods.get(method)); + } handler.endAdded(); + handler.startChanged(); if (classchanged) { - // Was only deprecated? - if (wasDeprecated(oci, nci) - && !criteria.differs(cloneDeprecated(oci), nci)) - handler.classDeprecated(oci, nci); - else - handler.classChanged(oci, nci); + // Was only deprecated? + if (wasDeprecated(oci, nci) + && !criteria.differs(cloneDeprecated(oci), nci)) + handler.classDeprecated(oci, nci); + else + handler.classChanged(oci, nci); } - j = changedFields.iterator(); - while (j.hasNext()) { - Object tmp = j.next(); - FieldInfo oldFieldInfo = (FieldInfo) oldFields.get(tmp); - FieldInfo newFieldInfo = (FieldInfo) newFields.get(tmp); - // Was only deprecated? - if (wasDeprecated(oldFieldInfo, newFieldInfo) - && !criteria.differs( - cloneDeprecated(oldFieldInfo), - newFieldInfo)) - handler.fieldDeprecated(oldFieldInfo, newFieldInfo); - else - handler.fieldChanged(oldFieldInfo, newFieldInfo); - } - j = changedMethods.iterator(); - while (j.hasNext()) { - Object tmp = j.next(); - MethodInfo oldMethodInfo = (MethodInfo) oldMethods - .get(tmp); - MethodInfo newMethodInfo = (MethodInfo) newMethods - .get(tmp); - // Was only deprecated? - if (wasDeprecated(oldMethodInfo, newMethodInfo) - && !criteria.differs( - cloneDeprecated(oldMethodInfo), - newMethodInfo)) - handler.methodDeprecated(oldMethodInfo, - newMethodInfo); - else - handler.methodChanged(oldMethodInfo, newMethodInfo); + + for (String field : changedFields) { + FieldInfo oldFieldInfo = oldFields.get(field); + FieldInfo newFieldInfo = newFields.get(field); + // Was only deprecated? + if (wasDeprecated(oldFieldInfo, newFieldInfo) + && !criteria.differs( + cloneDeprecated(oldFieldInfo), + newFieldInfo)) + handler.fieldDeprecated(oldFieldInfo, newFieldInfo); + else + handler.fieldChanged(oldFieldInfo, newFieldInfo); + } + for (String method : changedMethods) { + MethodInfo oldMethodInfo = oldMethods.get(method); + MethodInfo newMethodInfo = newMethods.get(method); + // Was only deprecated? + if (wasDeprecated(oldMethodInfo, newMethodInfo) + && !criteria.differs( + cloneDeprecated(oldMethodInfo), + newMethodInfo)) + handler.methodDeprecated(oldMethodInfo, + newMethodInfo); + else + handler.methodChanged(oldMethodInfo, newMethodInfo); } handler.endChanged(); handler.endClassChanged(); + removedMethods.clear(); removedFields.clear(); addedMethods.clear(); @@ -523,6 +493,7 @@ public class JarDiff } } handler.endChanged(); + handler.endDiff(); } diff --git a/api/src/main/java/org/osjava/jardiff/SimpleDiffCriteria.java b/api/src/main/java/org/osjava/jardiff/SimpleDiffCriteria.java index 94b1812..3d9c7ca 100644 --- a/api/src/main/java/org/osjava/jardiff/SimpleDiffCriteria.java +++ b/api/src/main/java/org/osjava/jardiff/SimpleDiffCriteria.java @@ -15,8 +15,10 @@ * limitations under the License. */ package org.osjava.jardiff; + import java.util.Arrays; import java.util.HashSet; +import java.util.Set; /** * A specific type of DiffCriteria which is only true for classes, methods @@ -79,9 +81,9 @@ public class SimpleDiffCriteria implements DiffCriteria } else if (!oldInfo.getSupername().equals(newInfo.getSupername())) { return true; } - java.util.Set oldInterfaces + Set<String> oldInterfaces = new HashSet(Arrays.asList(oldInfo.getInterfaces())); - java.util.Set newInterfaces + Set<String> newInterfaces = new HashSet(Arrays.asList(newInfo.getInterfaces())); if (!oldInterfaces.equals(newInterfaces)) return true; @@ -105,9 +107,9 @@ public class SimpleDiffCriteria implements DiffCriteria if (oldInfo.getExceptions() != newInfo.getExceptions()) return true; } else { - java.util.Set oldExceptions + Set<String> oldExceptions = new HashSet(Arrays.asList(oldInfo.getExceptions())); - java.util.Set newExceptions + Set<String> newExceptions = new HashSet(Arrays.asList(newInfo.getExceptions())); if (!oldExceptions.equals(newExceptions)) return true; diff --git a/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java b/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java index 24a3d4c..aea74fa 100644 --- a/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java +++ b/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java @@ -15,19 +15,13 @@ * limitations under the License. */ package org.semver.jardiff; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import junit.framework.Assert; - import org.junit.Test; import org.objectweb.asm.ClassReader; import org.osjava.jardiff.ClassInfo; -import org.osjava.jardiff.DiffCriteria; -import org.osjava.jardiff.DiffHandler; import org.osjava.jardiff.JarDiff; import org.osjava.jardiff.SimpleDiffCriteria; import org.semver.Delta; @@ -53,7 +47,7 @@ public class ClassInheritanceTest { } @Test - public void shouldInheritedMethodMatchImplementedMethod() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException { + public void shouldInheritedMethodMatchImplementedMethod() throws Exception { /** * The situation we are testing is as follows: * Abstract class InheritanceRoot is initially implemented directly by ClassA. @@ -67,18 +61,12 @@ public class ClassInheritanceTest { Map<String, ClassInfo> oldClassInfoMap = new HashMap<String, ClassInfo>(); Map<String, ClassInfo> newClassInfoMap = new HashMap<String, ClassInfo>(); JarDiff jd = new JarDiff(); - Method loadInfoMethod = JarDiff.class.getDeclaredMethod("loadClassInfo", ClassReader.class); - Method diffMethod = JarDiff.class.getDeclaredMethod("diff", DiffHandler.class, DiffCriteria.class, - String.class, String.class, - Map.class, Map.class); - diffMethod.setAccessible(true); - loadInfoMethod.setAccessible(true); - addClassInfo(oldClassInfoMap, ClassA.class, jd, loadInfoMethod); - addClassInfo(oldClassInfoMap, DirectDescendant.class, jd, loadInfoMethod); - addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, ClassB.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, DirectDescendant.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod); + addClassInfo(oldClassInfoMap, ClassA.class, jd); + addClassInfo(oldClassInfoMap, DirectDescendant.class, jd); + addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd); + addClassInfo(newClassInfoMap, ClassB.class, jd); + addClassInfo(newClassInfoMap, DirectDescendant.class, jd); + addClassInfo(newClassInfoMap, InheritanceRoot.class, jd); // Make B look like A ClassInfo a = oldClassInfoMap.get("org/semver/jardiff/ClassInheritanceTest$ClassA"); @@ -88,7 +76,7 @@ public class ClassInheritanceTest { b.getMethodMap(), b.getFieldMap())); newClassInfoMap.remove(b.getName()); DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler(); - diffMethod.invoke(jd, handler, new SimpleDiffCriteria(), + jd.diff(handler, new SimpleDiffCriteria(), "0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap); for (Delta.Difference d: handler.getDelta().getDifferences()) { @@ -101,9 +89,8 @@ public class ClassInheritanceTest { Assert.assertEquals("differences found", 1, handler.getDelta().getDifferences().size()); } - private void addClassInfo(Map<String, ClassInfo> classMap, Class klass, JarDiff jd, - Method loadInfoMethod) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException { - ClassInfo classInfo = (ClassInfo) loadInfoMethod.invoke(jd, new ClassReader(klass.getName())); + private void addClassInfo(Map<String, ClassInfo> classMap, Class klass, JarDiff jd) throws Exception { + ClassInfo classInfo = jd.loadClassInfo(new ClassReader(klass.getName())); classMap.put(classInfo.getName(), classInfo); } diff --git a/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java b/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java index 26558cb..a85a52e 100644 --- a/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java +++ b/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java @@ -15,20 +15,14 @@ * limitations under the License. */ package org.semver.jardiff; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Set; import junit.framework.Assert; - import org.junit.Test; import org.objectweb.asm.ClassReader; import org.osjava.jardiff.ClassInfo; -import org.osjava.jardiff.DiffCriteria; -import org.osjava.jardiff.DiffHandler; import org.osjava.jardiff.JarDiff; import org.osjava.jardiff.SimpleDiffCriteria; import org.semver.Delta.Deprecate; @@ -63,7 +57,7 @@ public class DeprecateDetectionTest { } @Test - public void shouldInheritedMethodMatchImplementedMethod() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException { + public void shouldInheritedMethodMatchImplementedMethod() throws Exception { /** * The situation we are testing is as follows: * Abstract class InheritanceRoot is initially implemented directly by ClassA. @@ -77,25 +71,19 @@ public class DeprecateDetectionTest { Map<String, ClassInfo> oldClassInfoMap = new HashMap<String, ClassInfo>(); Map<String, ClassInfo> newClassInfoMap = new HashMap<String, ClassInfo>(); JarDiff jd = new JarDiff(); - Method loadInfoMethod = JarDiff.class.getDeclaredMethod("loadClassInfo", ClassReader.class); - Method diffMethod = JarDiff.class.getDeclaredMethod("diff", DiffHandler.class, DiffCriteria.class, - String.class, String.class, - Map.class, Map.class); - diffMethod.setAccessible(true); - loadInfoMethod.setAccessible(true); - addClassInfo(oldClassInfoMap, ClassA.class, jd, loadInfoMethod); - addClassInfo(oldClassInfoMap, DirectDescendant.class, jd, loadInfoMethod); - addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, ClassB.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, DirectDescendant.class, jd, loadInfoMethod); - addClassInfo(newClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod); + addClassInfo(oldClassInfoMap, ClassA.class, jd); + addClassInfo(oldClassInfoMap, DirectDescendant.class, jd); + addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd); + addClassInfo(newClassInfoMap, ClassB.class, jd); + addClassInfo(newClassInfoMap, DirectDescendant.class, jd); + addClassInfo(newClassInfoMap, InheritanceRoot.class, jd); // Make B look like A newClassInfoMap.put("org/semver/jardiff/DeprecateDetectionTest$ClassA", newClassInfoMap.get("org/semver/jardiff/DeprecateDetectionTest$ClassB")); newClassInfoMap.remove("org/semver/jardiff/DeprecateDetectionTest$ClassB"); DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler(); - diffMethod.invoke(jd, handler, new SimpleDiffCriteria(), + jd.diff(handler, new SimpleDiffCriteria(), "0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap); Dumper.dump(handler.getDelta()); @@ -111,9 +99,8 @@ public class DeprecateDetectionTest { Assert.assertTrue("No Delta.Deprecate found", hasDeprecate); } - private void addClassInfo(Map<String, ClassInfo> classMap, Class klass, JarDiff jd, - Method loadInfoMethod) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException { - ClassInfo classInfo = (ClassInfo) loadInfoMethod.invoke(jd, new ClassReader(klass.getName())); + private void addClassInfo(Map<String, ClassInfo> classMap, Class klass, JarDiff jd) throws Exception { + ClassInfo classInfo = jd.loadClassInfo(new ClassReader(klass.getName())); classMap.put(classInfo.getName(), classInfo); } } |