Skip to content

Commit

Permalink
fix(transform-kit): debugWriteJar时忽略META-INF/目录文件
Browse files Browse the repository at this point in the history
同时采用output时相同的entryName。

fix #641
  • Loading branch information
shifujun committed Oct 14, 2021
1 parent cc8f6d0 commit 5528372
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,19 @@ abstract class AbstractTransform(
onCheckTransformedClasses(debugClassPool, inputClassNames)
}

override fun onOutputClass(className: String, outputStream: OutputStream) {
classPool[className].debugWriteJar(mDebugClassJarZOS)
super.onOutputClass(className, outputStream)
override fun onOutputClass(entryName: String?, className: String, outputStream: OutputStream) {
classPool[className].debugWriteJar(entryName, mDebugClassJarZOS)
super.onOutputClass(entryName, className, outputStream)
}

private fun CtClass.debugWriteJar(outputStream: ZipOutputStream) {
//忽略Kotlin 1.4引入的module-info
//https://kotlinlang.org/docs/reference/whatsnew14.html#module-info-descriptors-for-stdlib-artifacts
if (name == "module-info") {
private fun CtClass.debugWriteJar(outputEntryName: String?, outputStream: ZipOutputStream) {
//忽略META-INF
if (outputEntryName?.startsWith("META-INF/") == true) {
return
}

try {
val entryName = (name.replace('.', '/') + ".class")
val entryName = outputEntryName ?: (name.replace('.', '/') + ".class")
outputStream.putNextEntry(ZipEntry(entryName))
val p = stopPruning(true)
toBytecode(DataOutputStream(outputStream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class ClassTransform(val project: Project) : Transform() {
val file = it.second
Files.createParentDirs(file)
FileOutputStream(file).use {
onOutputClass(className, it)
onOutputClass(null, className, it)
}
}
}
Expand All @@ -129,7 +129,7 @@ abstract class ClassTransform(val project: Project) : Transform() {
val className = it.first
val entryName = it.second
zos.putNextEntry(ZipEntry(entryName))
onOutputClass(className, zos)
onOutputClass(entryName, className, zos)
}
}
}
Expand All @@ -138,7 +138,7 @@ abstract class ClassTransform(val project: Project) : Transform() {
}
}

abstract fun onOutputClass(className: String, outputStream: OutputStream)
abstract fun onOutputClass(entryName: String?, className: String, outputStream: OutputStream)

abstract fun DirInputClass.onInputClass(classFile: File, outputFile: File)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class JavassistTransform(project: Project, val classPoolBuilder: ClassPoolB
val mCtClassInputMap = mutableMapOf<CtClass, InputClass>()
lateinit var classPool: ClassPool

override fun onOutputClass(className: String, outputStream: OutputStream) {
override fun onOutputClass(entryName: String?, className: String, outputStream: OutputStream) {
classPool[className].writeOut(outputStream)
}

Expand Down

0 comments on commit 5528372

Please sign in to comment.