Skip to content

Commit

Permalink
stop stripping annotations like a casual
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolij committed Jun 15, 2024
1 parent ea34410 commit e1cf1db
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,39 @@ private fun processClassFile(bytes: ByteArray, mappings: MemoryMappingTree): Byt
}
}

val strippableAnnotations = setOf(
"Lorg/spongepowered/asm/mixin/Dynamic;",
"Ljava/lang/SafeVarargs;",
)
val canStripAnnotation = { annotationNode: AnnotationNode ->
annotationNode.desc.startsWith("Ldev/nolij/zumegradle/proguard/") ||
annotationNode.desc.startsWith("Lorg/jetbrains/annotations/") ||
annotationNode.desc == "Lorg/spongepowered/asm/mixin/Dynamic;"
strippableAnnotations.contains(annotationNode.desc)
}

classNode.invisibleAnnotations?.removeIf(canStripAnnotation)
classNode.visibleAnnotations?.removeIf(canStripAnnotation)
classNode.invisibleTypeAnnotations?.removeIf(canStripAnnotation)
classNode.visibleTypeAnnotations?.removeIf(canStripAnnotation)
classNode.fields.forEach { fieldNode ->
fieldNode.invisibleAnnotations?.removeIf(canStripAnnotation)
fieldNode.visibleAnnotations?.removeIf(canStripAnnotation)
fieldNode.invisibleTypeAnnotations?.removeIf(canStripAnnotation)
fieldNode.visibleTypeAnnotations?.removeIf(canStripAnnotation)
}
classNode.methods.forEach { methodNode ->
methodNode.invisibleAnnotations?.removeIf(canStripAnnotation)
methodNode.visibleAnnotations?.removeIf(canStripAnnotation)
methodNode.invisibleTypeAnnotations?.removeIf(canStripAnnotation)
methodNode.visibleTypeAnnotations?.removeIf(canStripAnnotation)
methodNode.invisibleLocalVariableAnnotations?.removeIf(canStripAnnotation)
methodNode.visibleLocalVariableAnnotations?.removeIf(canStripAnnotation)
methodNode.invisibleParameterAnnotations?.forEach { parameterAnnotations ->
parameterAnnotations?.removeIf(canStripAnnotation)
}
methodNode.visibleParameterAnnotations?.forEach { parameterAnnotations ->
parameterAnnotations?.removeIf(canStripAnnotation)
}
}

if (classNode.invisibleAnnotations?.any { it.desc == "Lorg/spongepowered/asm/mixin/Mixin;" } == true) {
Expand Down

0 comments on commit e1cf1db

Please sign in to comment.