From 0d3d96028ede6e8c5b3d642914a907cdd58a9c41 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:48:34 +1000 Subject: [PATCH] Work --- .../paperweight/core/PaperweightCore.kt | 12 +- .../core/taskcontainers/AllTasks.kt | 5 + paperweight-lib/build.gradle.kts | 6 + .../extension/PaperweightServerExtension.kt | 31 ++++ .../taskcontainers/BundlerJarTasks.kt | 5 +- .../taskcontainers/DevBundleTasks.kt | 3 +- .../paperweight/tasks/GenerateDevBundle.kt | 2 - .../tasks/GenerateReobfMappings.kt | 6 +- .../io/papermc/paperweight/tasks/RemapJar.kt | 11 ++ .../paperweight/util/constants/constants.kt | 3 +- .../papermc/paperweight/util/project-util.kt | 48 ++++-- .../relocation.kt} | 24 +-- .../tasks/GenerateRelocatedReobfMappings.kt | 156 ++++++++++++++++++ .../paperweight/patcher/PaperweightPatcher.kt | 17 +- .../paperweight/userdev/PaperweightUser.kt | 40 +++++ .../setup/step/FilterPaperShadowJar.kt | 7 +- .../userdev/internal/setup/v2/DevBundleV2.kt | 1 - 17 files changed, 316 insertions(+), 61 deletions(-) create mode 100644 paperweight-lib/src/main/kotlin/extension/PaperweightServerExtension.kt rename paperweight-lib/src/main/kotlin/io/papermc/paperweight/{extension/RelocationExtension.kt => util/relocation.kt} (65%) create mode 100644 paperweight-lib/src/main/kotlin/tasks/GenerateRelocatedReobfMappings.kt diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt index 2e4d6cc1..33035031 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt @@ -143,15 +143,19 @@ class PaperweightCore : Plugin { tasks.generateReobfMappings { inputJar.set(shadowJar.flatMap { it.archiveFile }) } + tasks.generateRelocatedReobfMappings { + inputJar.set(shadowJar.flatMap { it.archiveFile }) + } - val (_, reobfJar) = serverProj.setupServerProject( + val (includeMappings, reobfJar) = serverProj.setupServerProject( target, tasks.lineMapJar.flatMap { it.outputJar }, tasks.decompileJar.flatMap { it.outputJar }, ext.mcDevSourceDir.path, cache.resolve(SERVER_LIBRARIES_TXT), ext.paper.reobfPackagesToFix, - tasks.patchReobfMappings.flatMap { it.outputMappings } + tasks.patchReobfMappings.flatMap { it.outputMappings }, + tasks.generateRelocatedReobfMappings ) ?: return@afterEvaluate devBundleTasks.configure( @@ -167,7 +171,7 @@ class PaperweightCore : Plugin { tasks.extractFromBundler.map { it.versionJson.path }.convertToFileProvider(layout, providers) ) { vanillaJarIncludes.set(ext.vanillaJarIncludes) - reobfMappingsFile.set(tasks.patchReobfMappings.flatMap { it.outputMappings }) + reobfMappingsFile.set(tasks.generateRelocatedReobfMappings.flatMap { it.outputMappings }) paramMappingsCoordinates.set( target.provider { @@ -182,7 +186,7 @@ class PaperweightCore : Plugin { tasks.extractFromBundler.flatMap { it.versionJson }, tasks.extractFromBundler.flatMap { it.serverLibrariesList }, tasks.downloadServerJar.flatMap { it.outputJar }, - shadowJar, + includeMappings.flatMap { it.outputJar }, reobfJar, ext.minecraftVersion ) diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt index 0b7b31e8..38cd5f21 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt @@ -176,4 +176,9 @@ open class AllTasks( outputMappings.set(cache.resolve(PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS)) } + + val generateRelocatedReobfMappings by tasks.registering { + inputMappings.set(patchReobfMappings.flatMap { it.outputMappings }) + outputMappings.set(cache.resolve(RELOCATED_PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS)) + } } diff --git a/paperweight-lib/build.gradle.kts b/paperweight-lib/build.gradle.kts index 3fd63f91..b4b691aa 100644 --- a/paperweight-lib/build.gradle.kts +++ b/paperweight-lib/build.gradle.kts @@ -2,6 +2,10 @@ plugins { `config-kotlin` } +repositories { + gradlePluginPortal() +} + dependencies { implementation(libs.httpclient) implementation(libs.kotson) @@ -20,4 +24,6 @@ dependencies { implementation("net.minecraftforge:DiffPatch:2.0.7:all") { isTransitive = false } + + compileOnly(libs.gradle.shadow) } diff --git a/paperweight-lib/src/main/kotlin/extension/PaperweightServerExtension.kt b/paperweight-lib/src/main/kotlin/extension/PaperweightServerExtension.kt new file mode 100644 index 00000000..e97b9131 --- /dev/null +++ b/paperweight-lib/src/main/kotlin/extension/PaperweightServerExtension.kt @@ -0,0 +1,31 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.extension + +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.kotlin.dsl.property + +abstract class PaperweightServerExtension(objects: ObjectFactory) { + val craftBukkitPackageVersion: Property = objects.property() +} diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/BundlerJarTasks.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/BundlerJarTasks.kt index cd088e00..659c605f 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/BundlerJarTasks.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/BundlerJarTasks.kt @@ -31,7 +31,6 @@ import org.gradle.api.Project import org.gradle.api.file.RegularFile import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.bundling.AbstractArchiveTask import org.gradle.kotlin.dsl.* @Suppress("MemberVisibilityCanBePrivate") @@ -60,7 +59,7 @@ class BundlerJarTasks( bundlerVersionJson: Provider, serverLibrariesList: Provider, vanillaJar: Provider, - shadowJar: TaskProvider, + mojangJar: Provider, reobfJar: TaskProvider, mcVersion: Provider ) { @@ -68,7 +67,7 @@ class BundlerJarTasks( bundlerVersionJson, serverLibrariesList, vanillaJar, - shadowJar.flatMap { it.archiveFile }, + mojangJar, ) createReobfBundlerJar.configureWith( bundlerVersionJson, diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/DevBundleTasks.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/DevBundleTasks.kt index 3a29a8d7..cf863d0e 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/DevBundleTasks.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/DevBundleTasks.kt @@ -22,7 +22,6 @@ package io.papermc.paperweight.taskcontainers -import io.papermc.paperweight.extension.RelocationExtension import io.papermc.paperweight.taskcontainers.BundlerJarTasks.Companion.registerVersionArtifact import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.* @@ -106,7 +105,7 @@ class DevBundleTasks( serverProject.set(serverProj) runtimeConfiguration.set(project.configurations.named(SERVER_RUNTIME_CLASSPATH)) - relocations.set(serverProj.the().relocations.map { gson.toJson(it) }) + relocations.set(gson.toJson(listOf())) decompiledJar.pathProvider(decompileJar) atFile.pathProvider(accessTransformFile) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateDevBundle.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateDevBundle.kt index 831cbb63..96e381e3 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateDevBundle.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateDevBundle.kt @@ -22,8 +22,6 @@ package io.papermc.paperweight.tasks -import io.papermc.paperweight.extension.Relocation -import io.papermc.paperweight.extension.RelocationWrapper import io.papermc.paperweight.util.* import io.papermc.paperweight.util.constants.* import io.papermc.paperweight.util.data.* diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateReobfMappings.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateReobfMappings.kt index af18a8e8..916a4930 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateReobfMappings.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/GenerateReobfMappings.kt @@ -74,7 +74,7 @@ abstract class GenerateReobfMappings : JavaLauncherTask() { abstract val reobfMappings: RegularFileProperty @get:Internal - abstract val jvmargs: ListProperty + abstract val jvmArgs: ListProperty @get:Inject abstract val workerExecutor: WorkerExecutor @@ -86,13 +86,13 @@ abstract class GenerateReobfMappings : JavaLauncherTask() { override fun init() { super.init() - jvmargs.convention(listOf("-Xmx2G")) + jvmArgs.convention(listOf("-Xmx2G")) } @TaskAction fun run() { val queue = workerExecutor.processIsolation { - forkOptions.jvmArgs(jvmargs.get()) + forkOptions.jvmArgs(jvmArgs.get()) forkOptions.executable(launcher.get().executablePath.path.absolutePathString()) } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RemapJar.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RemapJar.kt index f732a1b7..0d93bc9e 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RemapJar.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RemapJar.kt @@ -66,11 +66,15 @@ abstract class RemapJar : JavaLauncherTask() { @get:Internal abstract val jvmArgs: ListProperty + @get:Input + abstract val markReobf: Property + override fun init() { super.init() outputJar.convention(defaultOutput()) jvmArgs.convention(listOf("-Xmx1G")) + markReobf.convention(false) remapperArgs.convention(TinyRemapper.createArgsList()) } @@ -91,6 +95,13 @@ abstract class RemapJar : JavaLauncherTask() { workingDir = layout.cache, jvmArgs = jvmArgs.get() ) + outputJar.path.openZip().use { fs -> + val reobf = fs.getPath("META-INF/.reobf") + val moj = fs.getPath("META-INF/.mojang-mapped") + moj.deleteIfExists() + reobf.parent.createDirectories() + reobf.createFile() + } } } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt index 70ab174f..4c2a1033 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt @@ -87,6 +87,7 @@ const val PATCHED_SPIGOT_MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yar const val PATCHED_SPIGOT_MOJANG_YARN_SOURCE_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yarn-patched-source.tiny" const val REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf.tiny" const val PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf-patched.tiny" +const val RELOCATED_PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf-patched-relocated.tiny" const val OBF_NAMESPACE = "official" const val SPIGOT_NAMESPACE = "spigot" @@ -113,8 +114,6 @@ const val MC_DEV_SOURCES_DIR = "$PAPER_PATH/mc-dev-sources" const val IVY_REPOSITORY = "$PAPER_PATH/ivyRepository" -const val RELOCATION_EXTENSION = "relocation" - fun paperSetupOutput(name: String, ext: String) = "$SETUP_CACHE/$name.$ext" fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext) fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext" diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt index e1a09d9a..18ad3994 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt @@ -22,7 +22,8 @@ package io.papermc.paperweight.util -import io.papermc.paperweight.extension.RelocationExtension +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import io.papermc.paperweight.extension.PaperweightServerExtension import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.constants.* import java.nio.file.Path @@ -37,7 +38,6 @@ import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskProvider -import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.* import org.gradle.plugins.ide.idea.model.IdeaModel @@ -49,6 +49,7 @@ fun Project.setupServerProject( libsFile: Any, packagesToFix: Provider?>, reobfMappings: Provider, + relocatedReobfMappings: TaskProvider, ): ServerTasks? { if (!projectDir.exists()) { return null @@ -56,7 +57,10 @@ fun Project.setupServerProject( plugins.apply("java") - extensions.create(RELOCATION_EXTENSION, objects) + val serverExt = extensions.create(PAPERWEIGHT_EXTENSION, objects) + relocatedReobfMappings { + craftBukkitPackageVersion.set(serverExt.craftBukkitPackageVersion) + } exportRuntimeClasspathTo(parent) @@ -101,7 +105,7 @@ fun Project.setupServerProject( addMcDevSourcesRoot(mcDevSourceDir) plugins.apply("com.github.johnrengelman.shadow") - return createBuildTasks(parent, packagesToFix, reobfMappings) + return createBuildTasks(parent, serverExt, vanillaServer, packagesToFix, reobfMappings, relocatedReobfMappings) } private fun Project.exportRuntimeClasspathTo(parent: Project) { @@ -134,23 +138,45 @@ private fun Project.exportRuntimeClasspathTo(parent: Project) { private fun Project.createBuildTasks( parent: Project, + serverExt: PaperweightServerExtension, + vanillaServer: Configuration, packagesToFix: Provider?>, - reobfMappings: Provider + reobfMappings: Provider, + relocatedReobfMappings: TaskProvider ): ServerTasks { - val shadowJar: TaskProvider = tasks.named("shadowJar", Jar::class) + val shadowJar: TaskProvider = tasks.named("shadowJar", ShadowJar::class) { + archiveClassifier.set("mojang-mapped") + configurations = listOf(vanillaServer) + } val fixJarForReobf by tasks.registering { - dependsOn(shadowJar) - inputJar.set(shadowJar.flatMap { it.archiveFile }) packagesToProcess.set(packagesToFix) } + val includeMappings by tasks.registering { + inputJar.set(fixJarForReobf.flatMap { it.outputJar }) + mappings.set(relocatedReobfMappings.flatMap { it.outputMappings }) + mappingsDest.set("META-INF/mappings/reobf.tiny") + } + + val relocatedShadowJar by tasks.registering { + archiveClassifier.set("mojang-mapped-relocated") + from(zipTree(includeMappings.flatMap { it.outputJar })) + } + afterEvaluate { + relocatedShadowJar { + relocate("org.bukkit.craftbukkit", "org.bukkit.craftbukkit.${serverExt.craftBukkitPackageVersion.get()}") { + exclude("org.bukkit.craftbukkit.Main*") + } + } + } + val reobfJar by tasks.registering { group = "paperweight" description = "Re-obfuscate the built jar to obf mappings" - inputJar.set(fixJarForReobf.flatMap { it.outputJar }) + inputJar.set(relocatedShadowJar.flatMap { it.archiveFile }) mappingsFile.set(reobfMappings) @@ -163,11 +189,11 @@ private fun Project.createBuildTasks( outputJar.set(buildDir.resolve("libs/${project.name}-${project.version}-reobf.jar")) } - return ServerTasks(fixJarForReobf, reobfJar) + return ServerTasks(includeMappings, reobfJar) } data class ServerTasks( - val fixJarForReobf: TaskProvider, + val includeMappings: TaskProvider, val reobfJar: TaskProvider, ) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/RelocationExtension.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/relocation.kt similarity index 65% rename from paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/RelocationExtension.kt rename to paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/relocation.kt index 60bb38ee..86a46b13 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/RelocationExtension.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/relocation.kt @@ -20,29 +20,7 @@ * USA */ -package io.papermc.paperweight.extension - -import org.gradle.api.model.ObjectFactory -import org.gradle.kotlin.dsl.* - -abstract class RelocationExtension(objects: ObjectFactory) { - val relocations = objects.listProperty() - - fun relocate( - owningLibraryCoordinates: String, - relocation: Pair, - config: Relocation.() -> Unit = {} - ) { - relocations.add(Relocation(owningLibraryCoordinates, relocation.first, relocation.second, arrayListOf()).apply(config)) - } - - fun relocate( - relocation: Pair, - config: Relocation.() -> Unit = {} - ) { - relocations.add(Relocation(null, relocation.first, relocation.second, arrayListOf()).apply(config)) - } -} +package io.papermc.paperweight.util data class Relocation( val owningLibraryCoordinates: String?, diff --git a/paperweight-lib/src/main/kotlin/tasks/GenerateRelocatedReobfMappings.kt b/paperweight-lib/src/main/kotlin/tasks/GenerateRelocatedReobfMappings.kt new file mode 100644 index 00000000..87c0d4fd --- /dev/null +++ b/paperweight-lib/src/main/kotlin/tasks/GenerateRelocatedReobfMappings.kt @@ -0,0 +1,156 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.tasks + +import dev.denwav.hypo.asm.AsmClassDataProvider +import dev.denwav.hypo.core.HypoConfig +import dev.denwav.hypo.core.HypoContext +import dev.denwav.hypo.hydrate.HydrationManager +import dev.denwav.hypo.mappings.ChangeChain +import dev.denwav.hypo.mappings.ChangeRegistry +import dev.denwav.hypo.mappings.MappingsCompletionManager +import dev.denwav.hypo.mappings.contributors.ChangeContributor +import dev.denwav.hypo.model.ClassProviderRoot +import dev.denwav.hypo.model.data.ClassData +import io.papermc.paperweight.util.* +import io.papermc.paperweight.util.constants.* +import javax.inject.Inject +import kotlin.io.path.* +import org.cadixdev.lorenz.model.ClassMapping +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.* +import org.gradle.workers.WorkAction +import org.gradle.workers.WorkParameters +import org.gradle.workers.WorkerExecutor + +@CacheableTask +abstract class GenerateRelocatedReobfMappings : JavaLauncherTask() { + + @get:InputFile + @get:PathSensitive(PathSensitivity.NONE) + abstract val inputMappings: RegularFileProperty + + @get:Classpath + abstract val inputJar: RegularFileProperty + + @get:OutputFile + abstract val outputMappings: RegularFileProperty + + @get:Internal + abstract val jvmArgs: ListProperty + + @get:Inject + abstract val workerExecutor: WorkerExecutor + + @get:Input + abstract val craftBukkitPackageVersion: Property + + override fun init() { + super.init() + + jvmArgs.convention(listOf("-Xmx2G")) + } + + @TaskAction + fun run() { + val queue = workerExecutor.processIsolation { + forkOptions.jvmArgs(jvmArgs.get()) + forkOptions.executable(launcher.get().executablePath.path.absolutePathString()) + } + + queue.submit(Action::class) { + inputMappings.set(this@GenerateRelocatedReobfMappings.inputMappings) + inputJar.set(this@GenerateRelocatedReobfMappings.inputJar) + craftBukkitPackageVersion.set(this@GenerateRelocatedReobfMappings.craftBukkitPackageVersion) + + outputMappings.set(this@GenerateRelocatedReobfMappings.outputMappings) + } + } + + abstract class Action : WorkAction { + interface Parameters : WorkParameters { + val inputMappings: RegularFileProperty + val inputJar: RegularFileProperty + val craftBukkitPackageVersion: Property + + val outputMappings: RegularFileProperty + } + + override fun execute() { + val mappingsIn = MappingFormats.TINY.read( + parameters.inputMappings.path, + DEOBF_NAMESPACE, + SPIGOT_NAMESPACE + ) + val mappingsOut = HypoContext.builder() + .withConfig(HypoConfig.builder().setRequireFullClasspath(false).withParallelism(1).build()) + .withProvider(AsmClassDataProvider.of(ClassProviderRoot.fromJar(parameters.inputJar.path))) + .withContextProvider(AsmClassDataProvider.of(ClassProviderRoot.ofJdk())) + .build().use { hypoContext -> + HydrationManager.createDefault().hydrate(hypoContext) + ChangeChain.create() + .addLink(CraftBukkitRelocation(parameters.craftBukkitPackageVersion.get())) + .applyChain(mappingsIn, MappingsCompletionManager.create(hypoContext)) + } + MappingFormats.TINY.write( + mappingsOut, + parameters.outputMappings.path, + DEOBF_NAMESPACE, + SPIGOT_NAMESPACE + ) + } + } + + class CraftBukkitRelocation(packageVersion: String) : ChangeContributor { + companion object { + const val PREFIX = "org/bukkit/craftbukkit/" + const val MAIN = "${PREFIX}Main" + } + + private val relocateTo: String = "$PREFIX$packageVersion" + + override fun name(): String = "CraftBukkitRelocation" + + override fun contribute( + currentClass: ClassData?, + classMapping: ClassMapping<*, *>?, + context: HypoContext, + registry: ChangeRegistry + ) { + if (currentClass == null || classMapping != null) { + return + } + if (currentClass.name().startsWith(PREFIX) && !currentClass.name().startsWith(MAIN)) { + registry.submitChange( + GenerateReobfMappings.AddClassMappingChange( + currentClass.name(), + "$relocateTo/${currentClass.name().substring(PREFIX.length)}" + ) + ) + } + } + } +} diff --git a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt index e37b5699..570d43db 100644 --- a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt +++ b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt @@ -89,6 +89,11 @@ class PaperweightPatcher : Plugin { toNamespace.set(SPIGOT_NAMESPACE) } + val generateRelocatedReobfMappings by target.tasks.registering { + inputMappings.set(patchReobfMappings.flatMap { it.outputMappings }) + outputMappings.set(target.layout.cache.resolve(RELOCATED_PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS)) + } + val prepareForDownstream = target.tasks.register(PAPERWEIGHT_PREPARE_DOWNSTREAM) { dataFile.fileProvider(dataFileProp.map { File(it) }) reobfMappingsPatch.set(mergeReobfMappingsPatches.flatMap { it.outputMappings }) @@ -166,15 +171,19 @@ class PaperweightPatcher : Plugin { reobfMappings.set(target.layout.cache.resolve(REOBF_MOJANG_SPIGOT_MAPPINGS)) } + generateRelocatedReobfMappings { + inputJar.set(shadowJar.flatMap { it.archiveFile }) + } - val (_, reobfJar) = serverProj.setupServerProject( + val (includeMappings, reobfJar) = serverProj.setupServerProject( target, upstreamData.map { it.remappedJar }.convertToFileProvider(target.layout, target.providers), upstreamData.map { it.decompiledJar }, patcher.mcDevSourceDir.path, upstreamData.map { it.libFile }, mergedReobfPackagesToFix, - patchReobfMappings.flatMap { it.outputMappings } + patchReobfMappings.flatMap { it.outputMappings }, + generateRelocatedReobfMappings ) ?: return@afterEvaluate devBundleTasks.configure( @@ -190,7 +199,7 @@ class PaperweightPatcher : Plugin { upstreamData.map { it.bundlerVersionJson }.convertToFileProvider(layout, providers) ) { vanillaJarIncludes.set(upstreamData.map { it.vanillaIncludes }) - reobfMappingsFile.set(patchReobfMappings.flatMap { it.outputMappings }) + reobfMappingsFile.set(generateRelocatedReobfMappings.flatMap { it.outputMappings }) paramMappingsCoordinates.set(upstreamData.map { it.paramMappings.coordinates.single() }) paramMappingsUrl.set(upstreamData.map { it.paramMappings.url }) @@ -201,7 +210,7 @@ class PaperweightPatcher : Plugin { upstreamData.map { it.bundlerVersionJson }.convertToFileProvider(target.layout, target.providers), upstreamData.map { it.serverLibrariesList }.convertToFileProvider(target.layout, target.providers), upstreamData.map { it.vanillaJar }.convertToFileProvider(target.layout, target.providers), - shadowJar, + includeMappings.flatMap { it.outputJar }, reobfJar, upstreamData.map { it.mcVersion } ) diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUser.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUser.kt index ff14cbc0..e62f5b05 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUser.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUser.kt @@ -33,6 +33,7 @@ import io.papermc.paperweight.util.* import io.papermc.paperweight.util.constants.* import java.nio.file.Path import javax.inject.Inject +import kotlin.io.path.* import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.ModuleDependency @@ -43,11 +44,18 @@ import org.gradle.api.attributes.Bundling import org.gradle.api.attributes.Category import org.gradle.api.attributes.LibraryElements import org.gradle.api.attributes.Usage +import org.gradle.api.file.DirectoryProperty import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.TaskAction import org.gradle.jvm.toolchain.JavaToolchainService import org.gradle.kotlin.dsl.* import org.gradle.util.internal.NameMatcher @@ -124,6 +132,8 @@ abstract class PaperweightUser : Plugin { remapper.from(project.configurations.named(REMAPPER_CONFIG)) remapperArgs.set(target.provider { userdevSetup.pluginRemapArgs }) + + markReobf.set(true) } target.configurations.register(REOBF_CONFIG) { @@ -156,6 +166,15 @@ abstract class PaperweightUser : Plugin { userdev.reobfArtifactConfiguration.get() .configure(this, reobfJar) + val generateMarker by tasks.registering { + markerName.set("META-INF/.mojang-mapped") + } + target.configure { + named(SourceSet.MAIN_SOURCE_SET_NAME) { + resources.srcDir(generateMarker) + } + } + if (userdev.injectPaperRepository.get()) { repositories.maven(PAPER_MAVEN_REPO_URL) { content { onlyForConfigurations(DEV_BUNDLE_CONFIG) } @@ -305,4 +324,25 @@ abstract class PaperweightUser : Plugin { } .get() } + + abstract class GenerateMarker : BaseTask() { + @get:OutputDirectory + abstract val workDir: DirectoryProperty + + @get:Input + abstract val markerName: Property + + override fun init() { + doNotTrackState("Not worth caching") + workDir.convention(project, layout.cache.resolve(paperTaskOutput("dir"))) + } + + @TaskAction + fun run() { + workDir.path.deleteRecursively() + workDir.path.resolve(markerName.get()) + .also { it.parent.createDirectories() } + .createFile() + } + } } diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/FilterPaperShadowJar.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/FilterPaperShadowJar.kt index fc0083c9..217f2992 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/FilterPaperShadowJar.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/FilterPaperShadowJar.kt @@ -22,15 +22,10 @@ package io.papermc.paperweight.userdev.internal.setup.step -import io.papermc.paperweight.extension.Relocation -import io.papermc.paperweight.extension.RelocationWrapper import io.papermc.paperweight.userdev.internal.setup.SetupHandler import io.papermc.paperweight.userdev.internal.setup.util.HashFunctionBuilder import io.papermc.paperweight.userdev.internal.setup.util.siblingHashesFile -import io.papermc.paperweight.util.filterJar -import io.papermc.paperweight.util.gson -import io.papermc.paperweight.util.openZip -import io.papermc.paperweight.util.walk +import io.papermc.paperweight.util.* import java.nio.file.Path import kotlin.io.path.isRegularFile import kotlin.io.path.name diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/v2/DevBundleV2.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/v2/DevBundleV2.kt index a940aa53..af71e5fb 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/v2/DevBundleV2.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/v2/DevBundleV2.kt @@ -22,7 +22,6 @@ package io.papermc.paperweight.userdev.internal.setup.v2 -import io.papermc.paperweight.extension.Relocation import io.papermc.paperweight.util.* object DevBundleV2 {