11package com.cleanroommc.gradle.helpers.tasks
22
33import groovy.json.JsonBuilder
4-
54import org.gradle.api.DefaultTask
65import org.gradle.api.tasks.InputFile
76import org.gradle.api.tasks.OutputFile
87import org.gradle.api.tasks.TaskAction
9-
108import org.objectweb.asm.ClassReader
119import org.objectweb.asm.Opcodes
12- import org.objectweb.asm.Type
1310import org.objectweb.asm.tree.ClassNode
1411import org.objectweb.asm.tree.FieldNode
1512import org.objectweb.asm.tree.MethodNode
@@ -18,19 +15,21 @@ import java.util.zip.ZipEntry
1815import java.util.zip.ZipInputStream
1916
2017public abstract class BytecodeFinder extends DefaultTask {
21- @InputFile File jar
22- @OutputFile output = project. file(" build/${ name} /output.json" )
23-
18+ @InputFile
19+ File jar
20+ @OutputFile
21+ output = project. file(" build/${ name} /output.json" )
22+
2423 @TaskAction
2524 protected void exec () {
2625 Util . init()
27-
26+
2827 if (output. exists())
2928 output. delete()
30-
29+
3130 pre()
32-
33- jar. withInputStream { i ->
31+
32+ jar. withInputStream { i ->
3433 new ZipInputStream (i). withCloseable { zin ->
3534 ZipEntry zein
3635 while ((zein = zin. nextEntry) != null ) {
@@ -42,20 +41,24 @@ public abstract class BytecodeFinder extends DefaultTask {
4241 }
4342 }
4443 }
45-
44+
4645 post()
4746 output. text = new JsonBuilder (getData()). toPrettyString()
4847 }
49-
50-
48+
49+
5150 protected process (ClassNode node ) {
5251 if (node. fields != null ) node. fields. each { process(node, it) }
5352 if (node. methods != null ) node. methods. each { process(node, it) }
5453 }
55-
54+
5655 protected pre () {}
56+
5757 protected process (ClassNode parent , FieldNode node ) {}
58+
5859 protected process (ClassNode parent , MethodNode node ) {}
60+
5961 protected post () {}
62+
6063 protected abstract Object getData ()
6164}
0 commit comments