From fe7e58e56c5ce7fd4088f25363c347d69effa970 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Fri, 26 Apr 2024 23:52:32 -0400 Subject: [PATCH 1/2] move MixinConfigMergingTransformer and plugin definitions to buildSrc --- build.gradle.kts | 75 ----------------- buildSrc/build.gradle.kts | 21 +++++ .../kotlin/MixinConfigMergingTransformer.kt | 84 +++++++++++++++++++ settings.gradle.kts | 23 +---- 4 files changed, 106 insertions(+), 97 deletions(-) create mode 100644 buildSrc/src/main/kotlin/MixinConfigMergingTransformer.kt diff --git a/build.gradle.kts b/build.gradle.kts index 944ebf98..87480ac1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,5 @@ @file:Suppress("UnstableApiUsage") import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer -import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext -import groovy.json.JsonOutput -import groovy.json.JsonSlurper import kotlinx.serialization.encodeToString import me.modmuss50.mpp.HttpUtils import me.modmuss50.mpp.PublishModTask @@ -15,8 +11,6 @@ import okhttp3.MultipartBody import okhttp3.Request import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.internal.immutableListOf -import org.apache.tools.zip.ZipEntry -import org.apache.tools.zip.ZipOutputStream import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassWriter import org.objectweb.asm.tree.ClassNode @@ -334,75 +328,6 @@ tasks.jar { enabled = false } -class MixinConfigMergingTransformer : Transformer { - private val JSON = JsonSlurper() - - @Input lateinit var modId: String - @Input lateinit var packageName: String - @Input lateinit var mixinPlugin: String - - override fun getName(): String { - return "MixinConfigMergingTransformer" - } - - override fun canTransformResource(element: FileTreeElement?): Boolean { - return element != null && (element.name.endsWith(".mixins.json") || element.name.endsWith("-refmap.json")) - } - - private var transformed = false - - private var mixins = ArrayList() - private var refMaps = HashMap>() - - override fun transform(context: TransformerContext?) { - if (context == null) - return - - this.transformed = true - - val parsed = JSON.parse(context.`is`) as Map<*, *> - if (parsed.contains("client")) { - @Suppress("UNCHECKED_CAST") - mixins.addAll(parsed["client"] as List) - } else { - @Suppress("UNCHECKED_CAST") - refMaps.putAll(parsed["mappings"] as Map>) - } - } - - override fun hasTransformedResource(): Boolean { - return transformed - } - - override fun modifyOutputStream(os: ZipOutputStream?, preserveFileTimestamps: Boolean) { - val mixinConfigEntry = ZipEntry("${modId}.mixins.json") - os!!.putNextEntry(mixinConfigEntry) - os.write(JsonOutput.prettyPrint(JsonOutput.toJson(mapOf( - "required" to true, - "minVersion" to "0.8", - "package" to packageName, - "plugin" to mixinPlugin, - "compatibilityLevel" to "JAVA_8", - "client" to mixins, - "injectors" to mapOf( - "defaultRequire" to 1, - ), - "refmap" to "${modId}-refmap.json", - ))).toByteArray()) - - val refMapEntry = ZipEntry("${modId}-refmap.json") - os.putNextEntry(refMapEntry) - os.write(JsonOutput.prettyPrint(JsonOutput.toJson(mapOf( - "mappings" to refMaps, - ))).toByteArray()) - - transformed = false - mixins.clear() - refMaps.clear() - } - -} - tasks.shadowJar { transform(MixinConfigMergingTransformer::class.java) { modId = "mod_id"() diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 8bae01a5..c3353a52 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,9 +4,30 @@ plugins { repositories { mavenCentral() + maven("https://maven.fabricmc.net/") + maven("https://maven.glass-launcher.net/babric") + maven("https://repo.legacyfabric.net/repository/legacyfabric/") + maven("https://maven.wagyourtail.xyz/releases") + maven("https://maven.wagyourtail.xyz/snapshots") + gradlePluginPortal { + content { + excludeGroup("org.apache.logging.log4j") + } + } +} + +fun DependencyHandler.plugin(id: String, version: String) { + this.implementation(group = id, name = "$id.gradle.plugin", version = version) } dependencies { implementation("org.ow2.asm:asm-tree:9.7") implementation("com.google.code.gson:gson:2.10.1") + + implementation("org.apache.ant:ant:1.10.13") + plugin("com.github.johnrengelman.shadow", "8.1.1") + plugin("xyz.wagyourtail.unimined", "1.2.3") + plugin("com.github.gmazzo.buildconfig", "5.2.0") + plugin("org.ajoberstar.grgit", "5.2.2") + plugin("me.modmuss50.mod-publish-plugin", "0.4.5") } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/MixinConfigMergingTransformer.kt b/buildSrc/src/main/kotlin/MixinConfigMergingTransformer.kt new file mode 100644 index 00000000..e6709d48 --- /dev/null +++ b/buildSrc/src/main/kotlin/MixinConfigMergingTransformer.kt @@ -0,0 +1,84 @@ +import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer +import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext +import groovy.json.JsonOutput +import groovy.json.JsonSlurper +import org.gradle.api.file.FileTreeElement +import org.gradle.api.tasks.Input +import org.apache.tools.zip.ZipOutputStream +import org.apache.tools.zip.ZipEntry + +class MixinConfigMergingTransformer : Transformer { + private val JSON = JsonSlurper() + + @Input + lateinit var modId: String + @Input + lateinit var packageName: String + @Input + lateinit var mixinPlugin: String + + override fun getName(): String { + return "MixinConfigMergingTransformer" + } + + override fun canTransformResource(element: FileTreeElement?): Boolean { + return element != null && (element.name.endsWith(".mixins.json") || element.name.endsWith("-refmap.json")) + } + + private var transformed = false + + private var mixins = ArrayList() + private var refMaps = HashMap>() + + override fun transform(context: TransformerContext?) { + if (context == null) + return + + this.transformed = true + + val parsed = JSON.parse(context.`is`) as Map<*, *> + if (parsed.contains("client")) { + @Suppress("UNCHECKED_CAST") + mixins.addAll(parsed["client"] as List) + } else { + @Suppress("UNCHECKED_CAST") + refMaps.putAll(parsed["mappings"] as Map>) + } + } + + override fun hasTransformedResource(): Boolean { + return transformed + } + + override fun modifyOutputStream(os: ZipOutputStream?, preserveFileTimestamps: Boolean) { + val mixinConfigEntry = ZipEntry("${modId}.mixins.json") + os!!.putNextEntry(mixinConfigEntry) + os.write( + JsonOutput.prettyPrint( + JsonOutput.toJson(mapOf( + "required" to true, + "minVersion" to "0.8", + "package" to packageName, + "plugin" to mixinPlugin, + "compatibilityLevel" to "JAVA_8", + "client" to mixins, + "injectors" to mapOf( + "defaultRequire" to 1, + ), + "refmap" to "${modId}-refmap.json", + ))).toByteArray()) + + val refMapEntry = ZipEntry("${modId}-refmap.json") + os.putNextEntry(refMapEntry) + os.write( + JsonOutput.prettyPrint( + JsonOutput.toJson(mapOf( + "mappings" to refMaps, + ))).toByteArray()) + + transformed = false + mixins.clear() + refMaps.clear() + } + +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 18c036ef..f70d74e8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,32 +1,11 @@ pluginManagement { repositories { - mavenCentral() - maven("https://maven.fabricmc.net/") - maven("https://maven.glass-launcher.net/babric") - maven("https://repo.legacyfabric.net/repository/legacyfabric/") - maven("https://maven.wagyourtail.xyz/releases") - maven("https://maven.wagyourtail.xyz/snapshots") - gradlePluginPortal { - content { - excludeGroup("org.apache.logging.log4j") - } - } + gradlePluginPortal() } } -buildscript { - dependencies { - classpath("org.ow2.asm:asm-tree:9.7") - } -} - plugins { id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0") - id("xyz.wagyourtail.unimined") version("1.2.3") apply(false) - id("com.github.gmazzo.buildconfig") version("5.2.0") apply(false) - id("com.github.johnrengelman.shadow") version("8.1.1") apply(false) - id("me.modmuss50.mod-publish-plugin") version("0.4.5") apply(false) - id("org.ajoberstar.grgit") version("5.2.2") apply(false) } rootProject.name = "zume" From d51f6ccadb58593a338f09641dd88e880f02f8b0 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Fri, 26 Apr 2024 23:54:27 -0400 Subject: [PATCH 2/2] niceify --- buildSrc/build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index c3353a52..20ef6146 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -25,9 +25,9 @@ dependencies { implementation("com.google.code.gson:gson:2.10.1") implementation("org.apache.ant:ant:1.10.13") - plugin("com.github.johnrengelman.shadow", "8.1.1") - plugin("xyz.wagyourtail.unimined", "1.2.3") - plugin("com.github.gmazzo.buildconfig", "5.2.0") - plugin("org.ajoberstar.grgit", "5.2.2") - plugin("me.modmuss50.mod-publish-plugin", "0.4.5") + plugin(id = "com.github.johnrengelman.shadow", version = "8.1.1") + plugin(id = "xyz.wagyourtail.unimined", version = "1.2.3") + plugin(id = "com.github.gmazzo.buildconfig", version = "5.2.0") + plugin(id = "org.ajoberstar.grgit", version = "5.2.2") + plugin(id = "me.modmuss50.mod-publish-plugin", version = "0.4.5") } \ No newline at end of file