aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/main/java/org/osjava
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main/java/org/osjava')
-rw-r--r--api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java28
-rw-r--r--api/src/main/java/org/osjava/jardiff/DiffHandler.java35
-rw-r--r--api/src/main/java/org/osjava/jardiff/JarDiff.java103
-rw-r--r--api/src/main/java/org/osjava/jardiff/StreamDiffHandler.java25
4 files changed, 176 insertions, 15 deletions
diff --git a/api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java b/api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java
index d2500a5..a05bbbf 100644
--- a/api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java
+++ b/api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java
@@ -29,8 +29,8 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.Result;
-import org.w3c.dom.*;
+import org.w3c.dom.*;
import org.objectweb.asm.Type;
/**
@@ -373,6 +373,15 @@ public class DOMDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #classChanged(ClassInfo, ClassInfo)}.
+ */
+ public void classDeprecated(ClassInfo oldInfo, ClassInfo newInfo)
+ throws DiffException
+ {
+ classChanged(oldInfo, newInfo);
+ }
+
+ /**
* Write out info aboout a changed field.
* This writes out a <fieldchange> node, followed by a
* <from> node, with the old information about the field
@@ -402,6 +411,14 @@ public class DOMDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #fieldChanged(FieldInfo, FieldInfo)}.
+ */
+ public void fieldDeprecated(FieldInfo oldInfo, FieldInfo newInfo)
+ throws DiffException {
+ fieldChanged(oldInfo, newInfo);
+ }
+
+ /**
* Write out info aboout a changed method.
* This writes out a <methodchange> node, followed by a
* <from> node, with the old information about the method
@@ -431,6 +448,15 @@ public class DOMDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #methodChanged(MethodInfo, MethodInfo)}.
+ */
+ public void methodDeprecated(MethodInfo oldInfo, MethodInfo newInfo)
+ throws DiffException
+ {
+ methodChanged(oldInfo, newInfo);
+ }
+
+ /**
* End the changed section for an individual class.
* This closes the <classchanged> node.
*
diff --git a/api/src/main/java/org/osjava/jardiff/DiffHandler.java b/api/src/main/java/org/osjava/jardiff/DiffHandler.java
index eee74b4..e10f1bf 100644
--- a/api/src/main/java/org/osjava/jardiff/DiffHandler.java
+++ b/api/src/main/java/org/osjava/jardiff/DiffHandler.java
@@ -194,6 +194,17 @@ public interface DiffHandler
throws DiffException;
/**
+ * The current class has been deprecated.
+ *
+ * @param oldClassinfo Information about the old class.
+ * @param newClassinfo Information about the new class.
+ * @throws DiffException when there is an underlying exception, e.g.
+ * writing to a file caused an IOException
+ */
+ public void classDeprecated(ClassInfo oldClassinfo, ClassInfo newClassinfo)
+ throws DiffException;
+
+ /**
* A field on the current class has changed.
*
* @param oldFieldinfo Information about the old field.
@@ -205,6 +216,17 @@ public interface DiffHandler
throws DiffException;
/**
+ * A field on the current class has been deprecated.
+ *
+ * @param oldFieldinfo Information about the old field.
+ * @param newFieldinfo Information about the new field.
+ * @throws DiffException when there is an underlying exception, e.g.
+ * writing to a file caused an IOException
+ */
+ public void fieldDeprecated(FieldInfo oldFieldinfo, FieldInfo newFieldinfo)
+ throws DiffException;
+
+ /**
* A method on the current class has changed.
*
* @param oldMethodInfo Information about the old method.
@@ -214,7 +236,18 @@ public interface DiffHandler
*/
public void methodChanged
(MethodInfo oldMethodInfo, MethodInfo newMethodInfo) throws DiffException;
-
+
+ /**
+ * The method has been deprecated.
+ *
+ * @param oldMethodInfo Information about the old method.
+ * @param newMethodInfo Information about the new method.
+ * @throws DiffException when there is an underlying exception, e.g.
+ * writing to a file caused an IOException
+ */
+ public void methodDeprecated(MethodInfo oldMethodInfo,
+ MethodInfo newMethodInfo) throws DiffException;
+
/**
* End of changes for the current class.
*
diff --git a/api/src/main/java/org/osjava/jardiff/JarDiff.java b/api/src/main/java/org/osjava/jardiff/JarDiff.java
index 77a0c93..e0f89d9 100644
--- a/api/src/main/java/org/osjava/jardiff/JarDiff.java
+++ b/api/src/main/java/org/osjava/jardiff/JarDiff.java
@@ -41,7 +41,10 @@ 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.
@@ -123,7 +126,7 @@ public class JarDiff
/**
* Set the name of the new version.
*
- * @param newVersion
+ * @param newVersion the version
*/
public void setNewVersion(String newVersion) {
this.newVersion = newVersion;
@@ -273,7 +276,7 @@ public class JarDiff
* Load new classes from the specified File.
*
* @param file The location of a jar file to load classes from.
- * @throws DiffExeption if there is an IOException
+ * @throws DiffException if there is an IOException
*/
public void loadNewClasses(File file) throws DiffException {
loadClasses(newClassInfo, file);
@@ -440,20 +443,44 @@ public class JarDiff
newMethods.get(j.next()));
handler.endAdded();
handler.startChanged();
- if (classchanged)
- handler.classChanged(oci, nci);
- j = changedFields.iterator();
- while (j.hasNext()) {
- Object tmp = j.next();
- handler.fieldChanged((FieldInfo) oldFields.get(tmp),
- (FieldInfo) newFields.get(tmp));
+ if (classchanged) {
+ // 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();
- handler.methodChanged((MethodInfo) oldMethods.get(tmp),
- ((MethodInfo)
- newMethods.get(tmp)));
+ 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);
}
handler.endChanged();
handler.endClassChanged();
@@ -469,4 +496,54 @@ public class JarDiff
handler.endChanged();
handler.endDiff();
}
+
+ /**
+ * Determines if an {@link AbstractInfo} was deprecated. (Shortcut to avoid
+ * creating cloned deprecated infos).
+ */
+ private static boolean wasDeprecated(AbstractInfo oldInfo,
+ AbstractInfo newInfo) {
+ return !oldInfo.isDeprecated() && newInfo.isDeprecated();
+ }
+
+ /**
+ * Clones the class info, but changes access, setting deprecated flag.
+ *
+ * @param classInfo
+ * the original class info
+ * @return the cloned and deprecated info.
+ */
+ private static ClassInfo cloneDeprecated(ClassInfo classInfo) {
+ return new ClassInfo(classInfo.getVersion(), classInfo.getAccess()
+ | Opcodes.ACC_DEPRECATED, classInfo.getName(),
+ classInfo.getSignature(), classInfo.getSupername(),
+ classInfo.getInterfaces(), classInfo.getMethodMap(),
+ classInfo.getFieldMap());
+ }
+
+ /**
+ * Clones the method, but changes access, setting deprecated flag.
+ *
+ * @param methodInfo
+ * the original method info
+ * @return the cloned and deprecated method info.
+ */
+ private static MethodInfo cloneDeprecated(MethodInfo methodInfo) {
+ return new MethodInfo(methodInfo.getAccess() | Opcodes.ACC_DEPRECATED,
+ methodInfo.getName(), methodInfo.getDesc(),
+ methodInfo.getSignature(), methodInfo.getExceptions());
+ }
+
+ /**
+ * Clones the field info, but changes access, setting deprecated flag.
+ *
+ * @param fieldInfo
+ * the original field info
+ * @return the cloned and deprecated field info.
+ */
+ private static FieldInfo cloneDeprecated(FieldInfo fieldInfo) {
+ return new FieldInfo(fieldInfo.getAccess() | Opcodes.ACC_DEPRECATED,
+ fieldInfo.getName(), fieldInfo.getDesc(),
+ fieldInfo.getSignature(), fieldInfo.getValue());
+ }
}
diff --git a/api/src/main/java/org/osjava/jardiff/StreamDiffHandler.java b/api/src/main/java/org/osjava/jardiff/StreamDiffHandler.java
index e0600df..f5f7176 100644
--- a/api/src/main/java/org/osjava/jardiff/StreamDiffHandler.java
+++ b/api/src/main/java/org/osjava/jardiff/StreamDiffHandler.java
@@ -21,6 +21,7 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+
import org.objectweb.asm.Type;
/**
@@ -395,6 +396,14 @@ public class StreamDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #classChanged(ClassInfo, ClassInfo)}.
+ */
+ public void classDeprecated(ClassInfo oldInfo, ClassInfo newInfo)
+ throws DiffException {
+ classChanged(oldInfo, newInfo);
+ }
+
+ /**
* Write out info aboout a changed field.
* This writes out a <fieldchange> node, followed by a
* <from> node, with the old information about the field
@@ -421,6 +430,14 @@ public class StreamDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #fieldChanged(FieldInfo, FieldInfo)}.
+ */
+ public void fieldDeprecated(FieldInfo oldInfo, FieldInfo newInfo)
+ throws DiffException {
+ fieldChanged(oldInfo, newInfo);
+ }
+
+ /**
* Write out info aboout a changed method.
* This writes out a <methodchange> node, followed by a
* <from> node, with the old information about the method
@@ -447,6 +464,14 @@ public class StreamDiffHandler implements DiffHandler
}
/**
+ * Invokes {@link #methodChanged(MethodInfo, MethodInfo)}.
+ */
+ public void methodDeprecated(MethodInfo oldInfo, MethodInfo newInfo)
+ throws DiffException {
+ methodChanged(oldInfo, newInfo);
+ }
+
+ /**
* End the changed section for an individual class.
* This closes the <classchanged> node.
*