diff --git a/buildSrc/src/main/kotlin/ReobfTask.kt b/buildSrc/src/main/kotlin/ReobfTask.kt new file mode 100644 index 00000000..f168915f --- /dev/null +++ b/buildSrc/src/main/kotlin/ReobfTask.kt @@ -0,0 +1,60 @@ +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.bundling.Jar +import java.io.File +import java.nio.file.Path +import java.nio.file.Paths + +abstract class ReobfTask: Jar() { + + @get:Input + open val spigotVersion: Property = objectFactory.property(String::class.java) + + @get:InputFile + open val inputFile: Property = objectFactory.fileProperty() + + @get:Input + open val intermediaryClassifier: Property = objectFactory.property(String::class.java).convention("mojang-mapped") + + init { + archiveClassifier.convention("reobf") + } + + @TaskAction + override fun copy() { + val spigotVer = spigotVersion.get() + val inFile = inputFile.get().asFile + val obfPath = inFile.resolveSibling(inFile.name.replace(".jar", "-${intermediaryClassifier.get()}.jar")) + + // https://www.spigotmc.org/threads/510208/#post-4184317 + val specialsource = project.configurations.named("spigotRemap").get().incoming.artifacts.artifacts + .first { it.id.componentIdentifier.toString() == "net.md-5:SpecialSource:1.11.4" }.file.path + val repo = Paths.get(project.repositories.mavenLocal().url) + val spigotDir = repo.resolve("org/spigotmc/spigot/$spigotVer/") + val mappingDir = repo.resolve("org/spigotmc/minecraft-server/$spigotVer/") + + // Remap original Mojang-mapped jar to obfuscated intermediary + val mojangServer = spigotDir.resolve("spigot-$spigotVer-remapped-mojang.jar") + val mojangMappings = mappingDir.resolve("minecraft-server-$spigotVer-maps-mojang.txt") + remapPartial(specialsource, mojangServer, mojangMappings, inFile, obfPath, true) + + // Remap obfuscated intermediary jar to Spigot and replace original + val obfServer = spigotDir.resolve("spigot-$spigotVer-remapped-obf.jar") + val spigotMappings = mappingDir.resolve("minecraft-server-$spigotVer-maps-spigot.csrg") + remapPartial(specialsource, obfServer, spigotMappings, obfPath, archiveFile.get().asFile, false) + } + + private fun remapPartial(specialSource: String, serverJar: Path, mapping: Path, input: File, output: File, reverse: Boolean) { + project.providers.exec { + commandLine("java", "-cp", "$specialSource${File.pathSeparator}$serverJar", + "net.md_5.specialsource.SpecialSource", "--live", + "-i", input.path, "-o", output.path, + "-m", "$mapping", + if (reverse) "--reverse" else "") + }.result.get() + } + +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/remap-spigot.gradle.kts b/buildSrc/src/main/kotlin/remap-spigot.gradle.kts deleted file mode 100644 index a1a6fab9..00000000 --- a/buildSrc/src/main/kotlin/remap-spigot.gradle.kts +++ /dev/null @@ -1,55 +0,0 @@ -import java.nio.file.Path -import java.nio.file.Paths - -val spigotRemap = configurations.create("spigotRemap") - -repositories { - mavenCentral() -} - -dependencies { - spigotRemap("net.md-5:SpecialSource:1.11.4:shaded") -} - -abstract class RemapTask - @Inject constructor(private val project: Project): DefaultTask() { - - @get:Input - abstract var spigotVersion: String - - @TaskAction - fun remapInputs() { - inputs.files.forEach { - remap(spigotVersion, it.toPath(), it.toPath().resolveSibling(it.name.replace(".jar", "-obf.jar"))) - } - } - - private fun remap(spigotVersion: String, jarPath: Path, obfPath: Path) { - // https://www.spigotmc.org/threads/510208/#post-4184317 - val specialsource = project.configurations.named("spigotRemap").get().incoming.artifacts.artifacts - .first { it.id.componentIdentifier.toString() == "net.md-5:SpecialSource:1.11.4" }.file.path - val repo = Paths.get(project.repositories.mavenLocal().url) - val spigotDir = repo.resolve("org/spigotmc/spigot/$spigotVersion/") - val mappingDir = repo.resolve("org/spigotmc/minecraft-server/$spigotVersion/") - - // Remap original Mojang-mapped jar to obfuscated intermediary - val mojangServer = spigotDir.resolve("spigot-$spigotVersion-remapped-mojang.jar") - val mojangMappings = mappingDir.resolve("minecraft-server-$spigotVersion-maps-mojang.txt") - remapPartial(specialsource, mojangServer, mojangMappings, jarPath, obfPath, true) - - // Remap obfuscated intermediary jar to Spigot and replace original - val obfServer = spigotDir.resolve("spigot-$spigotVersion-remapped-obf.jar") - val spigotMappings = mappingDir.resolve("minecraft-server-$spigotVersion-maps-spigot.csrg") - remapPartial(specialsource, obfServer, spigotMappings, obfPath, jarPath, false) - } - - private fun remapPartial(specialSource: String, serverJar: Path, mapping: Path, input: Path, output: Path, reverse: Boolean) { - project.providers.exec { - commandLine("java", "-cp", "$specialSource${File.pathSeparator}$serverJar", - "net.md_5.specialsource.SpecialSource", "--live", - "-i", "$input", "-o", "$output", - "-m", "$mapping", - if (reverse) "--reverse" else "") - }.result.get() - } -} diff --git a/internal/spigot/build.gradle.kts b/internal/spigot/build.gradle.kts index 6a88b17e..1d7dc411 100644 --- a/internal/spigot/build.gradle.kts +++ b/internal/spigot/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - `remap-spigot` `openinv-base` alias(libs.plugins.shadow) } @@ -9,6 +8,7 @@ repositories { } val spigotVer = "1.21.4-R0.1-SNAPSHOT" +rootProject.extra["spigotVersion"] = spigotVer rootProject.extra["craftbukkitPackage"] = "v1_21_R3" configurations.all { @@ -25,7 +25,10 @@ configurations.all { } } +val spigotRemap = configurations.create("spigotRemap") + dependencies { + spigotRemap("net.md-5:SpecialSource:1.11.4:shaded") compileOnly(libs.spigotapi) compileOnly(create("org.spigotmc", "spigot", spigotVer, classifier = "remapped-mojang")) @@ -37,15 +40,27 @@ dependencies { } tasks.shadowJar { - notCompatibleWithConfigurationCache("reobf task replaces output artifact") // TODO use an output of reobf relocate("com.lishid.openinv.internal.common", "com.lishid.openinv.internal.reobf") } -// TODO this appears to be a deprecated way to do things -// may want to just move all helper methods here. -tasks.register("reobf") { +val reobfTask = tasks.register("reobfTask") { notCompatibleWithConfigurationCache("gradle is hard") dependsOn(tasks.shadowJar) - inputs.files(tasks.shadowJar.get().outputs.files.files) - spigotVersion = spigotVer + inputFile.value(tasks.shadowJar.get().archiveFile.get()) + spigotVersion.value(spigotVer) +} + +configurations { + consumable("reobf") { + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) + attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR)) + } + } +} + +artifacts { + add("reobf", reobfTask) } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 46a72d48..8269af66 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -13,7 +13,7 @@ dependencies { implementation(project(":openinvadaptercommon")) implementation(project(":openinvadapterpaper1_21_3")) implementation(project(":openinvadapterpaper1_21_1")) - implementation(project(":openinvadapterspigot", configuration = "shadow")) + implementation(project(":openinvadapterspigot", configuration = "reobf")) implementation(libs.planarwrappers) } @@ -26,7 +26,6 @@ tasks.jar { } tasks.shadowJar { - dependsOn(":openinvadapterspigot:reobf") minimize { exclude(":openinv**") }