src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java
Print this page
@@ -41,44 +41,50 @@
* information to determine if the entry represents a class or a
* resource, and whether two entries are identical. If the FingerPrint represents
* a class, it also contains information to (1) describe the public API;
* (2) compare the public API of this class with another class; (3) determine
* whether or not it's a nested class and, if so, the name of the associated
- * top level class; and (4) for an canonically ordered set of classes determine
+ * outer class; and (4) for an canonically ordered set of classes determine
* if the class versions are compatible. A set of classes is canonically
* ordered if the classes in the set have the same name, and the base class
* precedes the versioned classes and if each versioned class with version
* {@code n} precedes classes with versions {@code > n} for all versions
* {@code n}.
*/
final class FingerPrint {
private static final MessageDigest MD;
+ private final String basename;
+ private final String entryName;
+ private final int mrversion;
+
private final byte[] sha1;
private final ClassAttributes attrs;
private final boolean isClassEntry;
- private final String entryName;
static {
try {
MD = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException x) {
// log big problem?
throw new RuntimeException(x);
}
}
- public FingerPrint(String entryName,byte[] bytes) throws IOException {
+ public FingerPrint(String basename, String entryName, int mrversion, byte[] bytes)
+ throws IOException {
+ this.basename = basename;
this.entryName = entryName;
- if (entryName.endsWith(".class") && isCafeBabe(bytes)) {
+ this.mrversion = mrversion;
+ if (isCafeBabe(bytes)) {
isClassEntry = true;
sha1 = sha1(bytes, 8); // skip magic number and major/minor version
attrs = getClassAttributes(bytes);
} else {
isClassEntry = false;
- sha1 = sha1(bytes);
- attrs = new ClassAttributes(); // empty class
+ sha1 = null;
+ attrs = null;
}
}
public boolean isClass() {
return isClassEntry;
@@ -105,18 +111,28 @@
public boolean isSameAPI(FingerPrint that) {
if (that == null) return false;
return attrs.equals(that.attrs);
}
- public String name() {
- String name = attrs.name;
- return name == null ? entryName : name;
+ public String basename() {
+ return basename;
+ }
+
+ public String entryName() {
+ return entryName;
+ }
+
+ public String className() {
+ return attrs.name;
+ }
+
+ public int mrversion() {
+ return mrversion;
}
- public String topLevelName() {
- String name = attrs.topLevelName;
- return name == null ? name() : name;
+ public String outerClassName() {
+ return attrs.outerClassName;
}
private byte[] sha1(byte[] entry) {
MD.update(entry);
return MD.digest();
@@ -216,21 +232,21 @@
}
}
private static final class ClassAttributes extends ClassVisitor {
private String name;
- private String topLevelName;
+ private String outerClassName;
private String superName;
private int version;
private int access;
private boolean publicClass;
private boolean nestedClass;
private final Set<Field> fields = new HashSet<>();
private final Set<Method> methods = new HashSet<>();
public ClassAttributes() {
- super(Opcodes.ASM5);
+ super(Opcodes.ASM6);
}
private boolean isPublic(int access) {
return ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC)
|| ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED);
@@ -248,20 +264,20 @@
}
@Override
public void visitOuterClass(String owner, String name, String desc) {
if (!this.nestedClass) return;
- this.topLevelName = owner;
+ this.outerClassName = owner;
}
@Override
public void visitInnerClass(String name, String outerName, String innerName,
int access) {
if (!this.nestedClass) return;
if (outerName == null) return;
if (!this.name.equals(name)) return;
- if (this.topLevelName == null) this.topLevelName = outerName;
+ if (this.outerClassName == null) this.outerClassName = outerName;
}
@Override
public FieldVisitor visitField(int access, String name, String desc,
String signature, Object value) {
@@ -292,11 +308,11 @@
return null;
}
@Override
public void visitEnd() {
- this.nestedClass = this.topLevelName != null;
+ this.nestedClass = this.outerClassName != null;
}
@Override
public boolean equals(Object that) {
if (that == null) return false;