Skip to content

Commit

Permalink
Fill bytecodeVersion for Jar
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Aug 25, 2023
1 parent d029d8d commit 518b586
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

class Class private constructor(
val bytecodeVersion: Short,
val descriptor: TypeDescriptor,
val declaredMembers: List<Member>,
val referencedMembers: List<Member>,
Expand All @@ -26,13 +27,14 @@ class Class private constructor(
@JvmName("parse")
fun Input.toClass(): Class {
val reader = ClassReader(toByteArray())
val bytecodeVersion = reader.readShort(0 + 6)
val type = TypeDescriptor("L${reader.className};")

val referencedVisitor = ReferencedMembersVisitor()
val declaredVisitor = DeclaredMembersVisitor(type, referencedVisitor)
reader.accept(declaredVisitor, 0)

return Class(type, declaredVisitor.members.sorted(), referencedVisitor.members.sorted())
return Class(bytecodeVersion, type, declaredVisitor.members.sorted(), referencedVisitor.members.sorted())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.jakewharton.diffuse.io.Input

class Jar private constructor(
override val filename: String?,
val bytecodeVersion: Short,
val files: ArchiveFiles,
val classes: List<Class>,
override val declaredMembers: List<Member>,
Expand All @@ -25,12 +26,14 @@ class Jar private constructor(
.filter { it.path.endsWith(".class") }
.map { it.asInput().toClass() }

val bytecodeVersion = classes.first().bytecodeVersion

val declaredMembers = classes.flatMap { it.declaredMembers }
val referencedMembers = classes.flatMapTo(LinkedHashSet()) { it.referencedMembers }
// Declared methods are likely to reference other declared members. Ensure all are removed.
referencedMembers -= declaredMembers

return Jar(name, files, classes, declaredMembers.sorted(), referencedMembers.sorted())
return Jar(name, bytecodeVersion, files, classes, declaredMembers.sorted(), referencedMembers.sorted())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ internal class JarDiffTextReport(private val jarDiff: JarDiff) : Report {
override fun write(appendable: Appendable) {
appendable.apply {
append("OLD: ")
appendLine(jarDiff.oldJar.filename)
append(jarDiff.oldJar.filename)
append(" (bytecodeVersion: ")
append(jarDiff.oldJar.bytecodeVersion.toString())
appendLine(')')

append("NEW: ")
appendLine(jarDiff.newJar.filename)

append(jarDiff.newJar.filename)
append(" (bytecodeVersion: ")
append(jarDiff.newJar.bytecodeVersion.toString())
appendLine(')')
appendLine()
appendLine(jarDiff.archive.toSummaryTable("JAR", Type.JAR_TYPES))
appendLine()
Expand Down

0 comments on commit 518b586

Please sign in to comment.