mirror of
https://github.com/fankes/unmeta-gradle-plugin.git
synced 2025-09-05 18:45:17 +08:00
Suppress error for unreadable classes
This commit is contained in:
@@ -72,20 +72,31 @@ abstract class UnmetaTask : DefaultTask() {
|
|||||||
fileLogger.appendText(message + System.lineSeparator(), Charsets.UTF_8)
|
fileLogger.appendText(message + System.lineSeparator(), Charsets.UTF_8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun logError(message: String) {
|
||||||
|
logger.error(message)
|
||||||
|
fileLogger.appendText(message + System.lineSeparator(), Charsets.UTF_8)
|
||||||
|
}
|
||||||
|
|
||||||
private fun removeAnnotation(directory: File, basePath: File) {
|
private fun removeAnnotation(directory: File, basePath: File) {
|
||||||
directory.walk()
|
directory.walk()
|
||||||
.filter { it.path.contains("classes") && it.path.endsWith(".class") && it.isFile }
|
.filter { it.path.contains("classes") && it.path.endsWith(".class") && it.isFile }
|
||||||
.forEach {
|
.forEach {
|
||||||
++scannedFiles
|
try {
|
||||||
val sourceClassBytes = it.readBytes()
|
++scannedFiles
|
||||||
val classReader = ClassReader(sourceClassBytes)
|
val sourceClassBytes = it.readBytes()
|
||||||
val classWriter = ClassWriter(classReader, ClassWriter.COMPUTE_MAXS)
|
val classReader = ClassReader(sourceClassBytes)
|
||||||
val unmetaClassVisitor = UnmetaClassVisitor(classWriter)
|
val classWriter = ClassWriter(classReader, ClassWriter.COMPUTE_MAXS)
|
||||||
classReader.accept(unmetaClassVisitor, ClassReader.SKIP_DEBUG)
|
val unmetaClassVisitor = UnmetaClassVisitor(classWriter)
|
||||||
if (unmetaClassVisitor.isModified) {
|
classReader.accept(unmetaClassVisitor, ClassReader.SKIP_DEBUG)
|
||||||
++modifiedFiles
|
if (unmetaClassVisitor.isModified) {
|
||||||
log("- Removed @DebugMetadata annotation from ${it.toRelativeString(basePath)}")
|
++modifiedFiles
|
||||||
it.writeBytes(classWriter.toByteArray())
|
log("- Removed @DebugMetadata annotation from ${it.toRelativeString(basePath)}")
|
||||||
|
it.writeBytes(classWriter.toByteArray())
|
||||||
|
}
|
||||||
|
} catch (e: UnsupportedOperationException) {
|
||||||
|
// Suppress error for unreadable classes
|
||||||
|
// PermittedSubclasses requires ASM9
|
||||||
|
logError("- Error ${it.toRelativeString(basePath)}: $e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user