Skip to content

Commit 45bb5d0

Browse files
yanglwshifujun
authored andcommitted
fix(core.gradle-plugin): 修复在 Windows 平台连续 gradle clean 打包失败的问题
transform-temp.jar 文件被新创建的 ClassPool 持有访问且没有释放,导致在 Windows 环境下 gradle clean 无法删除 transform-temp.jar 。新的方案是基于 IO 流读取 transform-temp.jar 文件中的 class 文件,并创建 CtClass 导入 ClassPool 中,避免 ClassPool 对 transform-temp.jar 文件持有访问。
1 parent 05c213b commit 45bb5d0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • projects/sdk/core/transform-kit/src/main/kotlin/com/tencent/shadow/core/transform_kit

projects/sdk/core/transform-kit/src/main/kotlin/com/tencent/shadow/core/transform_kit/AbstractTransform.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@ abstract class AbstractTransform(
7474
//CtClass在编辑后,其对象中的各种信息,比如superClass并没有更新。
7575
//所以需要重新创建一个ClassPool,加载转换后的类,用于各种转换后的检查。
7676
val debugClassPool = classPoolBuilder.build()
77-
debugClassPool.appendClassPath(mDebugClassJar.absolutePath)
77+
java.util.jar.JarFile(mDebugClassJar).use { jarFile ->
78+
jarFile.entries().iterator().forEach { entry ->
79+
if (!entry.name.endsWith(".class")) {
80+
return@forEach
81+
}
82+
jarFile.getInputStream(entry).use {
83+
// 直接从流创建 CtClass
84+
debugClassPool.makeClass(it)
85+
}
86+
}
87+
}
7888
val inputClassNames = allInputCtClass.map { it.name }
7989
onCheckTransformedClasses(debugClassPool, inputClassNames)
8090
}

0 commit comments

Comments
 (0)