aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Eluard <[email protected]>2014-04-18 08:17:32 -0300
committerJulien Eluard <[email protected]>2014-04-18 08:17:32 -0300
commit05c5be4df87b486cbbd67e7593af4e6faaeacc64 (patch)
tree77087b4f3913479d227fa6333374aeb4add60c1f
parent0997367dfea0ae2d68854c3602c6a7641e7a3665 (diff)
parentf64dfb33396d4a5fc7f5cd93e865167d37ef1351 (diff)
Merge pull request #28 from timowest/superclasses
Add superclass handling
-rw-r--r--api/src/main/java/org/osjava/jardiff/JarDiff.java29
-rw-r--r--api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java14
-rw-r--r--api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java7
3 files changed, 42 insertions, 8 deletions
diff --git a/api/src/main/java/org/osjava/jardiff/JarDiff.java b/api/src/main/java/org/osjava/jardiff/JarDiff.java
index e0f89d9..dcf6454 100644
--- a/api/src/main/java/org/osjava/jardiff/JarDiff.java
+++ b/api/src/main/java/org/osjava/jardiff/JarDiff.java
@@ -368,6 +368,32 @@ public class JarDiff
Map oldFields = oci.getFieldMap();
Map newMethods = nci.getMethodMap();
Map newFields = nci.getFieldMap();
+
+ Map extNewMethods = new HashMap(newMethods);
+ Map extNewFields = new HashMap(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())) {
+ 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())) {
+ extNewMethods.put(entry.getKey(), entry.getValue());
+ }
+ }
+ superClass = sci.getSupername();
+ }
+
Iterator j = oldMethods.entrySet().iterator();
while (j.hasNext()) {
Map.Entry entry = (Map.Entry) j.next();
@@ -392,13 +418,16 @@ public class JarDiff
if (criteria.validField((FieldInfo) entry.getValue()))
addedFields.add(entry.getKey());
}
+
changedMethods.addAll(removedMethods);
changedMethods.retainAll(addedMethods);
removedMethods.removeAll(changedMethods);
+ removedMethods.removeAll(extNewMethods.keySet());
addedMethods.removeAll(changedMethods);
changedFields.addAll(removedFields);
changedFields.retainAll(addedFields);
removedFields.removeAll(changedFields);
+ removedFields.removeAll(extNewFields.keySet());
addedFields.removeAll(changedFields);
j = changedMethods.iterator();
while (j.hasNext()) {
diff --git a/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java b/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java
index 2624ba0..24a3d4c 100644
--- a/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java
+++ b/api/src/test/java/org/semver/jardiff/ClassInheritanceTest.java
@@ -81,8 +81,12 @@ public class ClassInheritanceTest {
addClassInfo(newClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod);
// Make B look like A
- newClassInfoMap.put(ClassA.class.getName(), newClassInfoMap.get(ClassB.class.getName()));
- newClassInfoMap.remove(ClassB.class.getName());
+ ClassInfo a = oldClassInfoMap.get("org/semver/jardiff/ClassInheritanceTest$ClassA");
+ ClassInfo b = newClassInfoMap.get("org/semver/jardiff/ClassInheritanceTest$ClassB");
+ newClassInfoMap.put(a.getName(), new ClassInfo(b.getVersion(), b.getAccess(), a.getName(),
+ b.getSignature(), b.getSupername(), b.getInterfaces(),
+ b.getMethodMap(), b.getFieldMap()));
+ newClassInfoMap.remove(b.getName());
DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler();
diffMethod.invoke(jd, handler, new SimpleDiffCriteria(),
"0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap);
@@ -94,13 +98,13 @@ public class ClassInheritanceTest {
System.err.println(" : " + ((Change) d).getModifiedInfo().getName());
}
}
- Assert.assertEquals("differences found", 0, handler.getDelta().getDifferences().size());
+ 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(ClassA.class.getName()));
- classMap.put(klass.getName(), classInfo);
+ ClassInfo classInfo = (ClassInfo) loadInfoMethod.invoke(jd, 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 6cc85d6..26558cb 100644
--- a/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java
+++ b/api/src/test/java/org/semver/jardiff/DeprecateDetectionTest.java
@@ -91,8 +91,9 @@ public class DeprecateDetectionTest {
addClassInfo(newClassInfoMap, InheritanceRoot.class, jd, loadInfoMethod);
// Make B look like A
- newClassInfoMap.put(ClassA.class.getName(), newClassInfoMap.get(ClassB.class.getName()));
- newClassInfoMap.remove(ClassB.class.getName());
+ 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(),
"0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap);
@@ -113,6 +114,6 @@ public class DeprecateDetectionTest {
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()));
- classMap.put(klass.getName(), classInfo);
+ classMap.put(classInfo.getName(), classInfo);
}
}