diff options
author | SizableShrimp <sizableshrimp@sizableshrimp.me> | 2023-01-09 00:28:20 -0600 |
---|---|---|
committer | SizableShrimp <sizableshrimp@sizableshrimp.me> | 2023-01-09 00:28:20 -0600 |
commit | 4cfab97beb7402b1df3fa7524c1e5af2338a749d (patch) | |
tree | bbdd1b3f580cf4a863c0e5256db819f2e8737045 /buildSrc/src/main | |
parent | 86fe50bd075b6e543d319fa9b99641812e1014fa (diff) | |
download | Artifactural-4cfab97beb7402b1df3fa7524c1e5af2338a749d.tar.gz Artifactural-4cfab97beb7402b1df3fa7524c1e5af2338a749d.tar.bz2 Artifactural-4cfab97beb7402b1df3fa7524c1e5af2338a749d.zip |
Fix the transformers and `JarTransformationTask`
The transformers for the $1$1 anonymous inner class were entirely wrong
`JarTransformationTask` had the possibility of stacking on itself with the previous implementation if run multiple times
This caused the same methods to get injected multiple times
Fixed by using a separate file for the transformed classes
Diffstat (limited to 'buildSrc/src/main')
-rw-r--r-- | buildSrc/src/main/groovy/net/minecraftforge/artifactural/buildscript/JarTransformationTask.groovy | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/buildSrc/src/main/groovy/net/minecraftforge/artifactural/buildscript/JarTransformationTask.groovy b/buildSrc/src/main/groovy/net/minecraftforge/artifactural/buildscript/JarTransformationTask.groovy index 8dce1a4..137ea71 100644 --- a/buildSrc/src/main/groovy/net/minecraftforge/artifactural/buildscript/JarTransformationTask.groovy +++ b/buildSrc/src/main/groovy/net/minecraftforge/artifactural/buildscript/JarTransformationTask.groovy @@ -25,8 +25,9 @@ import groovy.transform.stc.SimpleType import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.MapProperty -import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassWriter @@ -40,12 +41,16 @@ import java.util.zip.ZipOutputStream @CompileStatic abstract class JarTransformationTask extends DefaultTask { @InputFile - abstract RegularFileProperty getFile() - @Input + abstract RegularFileProperty getInputFile() + @OutputFile + abstract RegularFileProperty getOutputFile() + @Internal abstract MapProperty<String, ClassTransformer> getTransformers() JarTransformationTask() { transformers.convention([:]) + // Class transformers can change and are not serializable, so we always have to run this + outputs.upToDateWhen { false } } void addTransformer(String className, @ClosureParams(value = SimpleType, options = 'org.objectweb.asm.tree.ClassNode') Closure transformer) { @@ -56,7 +61,7 @@ abstract class JarTransformationTask extends DefaultTask { void run() { final bos = new ByteArrayOutputStream() final zipOut = new ZipOutputStream(bos) - try (final zipIn = new ZipInputStream(file.get().asFile.newInputStream())) { + try (final zipIn = new ZipInputStream(inputFile.get().asFile.newInputStream())) { ZipEntry entry while ((entry = zipIn.nextEntry) !== null) { if (entry.name.endsWith('.class')) { @@ -83,7 +88,7 @@ abstract class JarTransformationTask extends DefaultTask { } zipOut.close() - Files.write(file.asFile.get().toPath(), bos.toByteArray()) + Files.write(outputFile.asFile.get().toPath(), bos.toByteArray()) } private static ZipEntry copy(ZipEntry entry) { |