Finish reobfTask
This commit is contained in:
parent
9ee9f4bb1b
commit
3d6c9413d6
7 changed files with 159 additions and 139 deletions
|
@ -34,19 +34,30 @@ gradlePlugin {
|
|||
isAutomatedPublishing = false
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://files.minecraftforge.net/maven/")
|
||||
maven("https://maven.fabricmc.net/")
|
||||
maven("https://repo.demonwav.com/snapshots/")
|
||||
}
|
||||
|
||||
val shade: Configuration by configurations.creating
|
||||
configurations.implementation {
|
||||
extendsFrom(shade)
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
|
||||
mavenContent {
|
||||
includeGroup("org.cadixdev")
|
||||
}
|
||||
}
|
||||
maven("https://repo.demonwav.com/snapshots/") {
|
||||
mavenContent {
|
||||
includeGroup("org.cadixdev")
|
||||
}
|
||||
}
|
||||
maven("https://maven.fabricmc.net/") {
|
||||
mavenContent {
|
||||
includeGroup("net.fabricmc")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
shade("org.apache.httpcomponents:httpclient:4.5.13")
|
||||
shade("com.github.salomonbrys.kotson:kotson:2.5.0")
|
||||
|
|
|
@ -117,7 +117,7 @@ class Paperweight : Plugin<Project> {
|
|||
}
|
||||
|
||||
serverProj.apply(plugin = "com.github.johnrengelman.shadow")
|
||||
serverProj.createBuildTasks(spigotTasks)
|
||||
serverProj.createBuildTasks(target.ext, spigotTasks)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ class Paperweight : Plugin<Project> {
|
|||
)
|
||||
}
|
||||
|
||||
private fun Project.createBuildTasks(spigotTasks: SpigotTasks) {
|
||||
private fun Project.createBuildTasks(ext: PaperweightExtension, spigotTasks: SpigotTasks) {
|
||||
val shadowJar: TaskProvider<Jar> = tasks.named("shadowJar", Jar::class.java)
|
||||
|
||||
val reobfJar by tasks.registering<RemapJarAtlas> {
|
||||
|
@ -490,12 +490,11 @@ class Paperweight : Plugin<Project> {
|
|||
inputJar.fileProvider(shadowJar.map { it.outputs.files.singleFile })
|
||||
|
||||
mappingsFile.set(spigotTasks.patchMappings.flatMap { it.outputMappingsReversed })
|
||||
packageVersion.set(ext.versionPackage)
|
||||
fromNamespace.set(Constants.DEOBF_NAMESPACE)
|
||||
toNamespace.set(Constants.SPIGOT_NAMESPACE)
|
||||
// singleThreaded.set(false) // not worried about param names
|
||||
// rebuildSourceFilenames.set(false)
|
||||
|
||||
// remapper.fileProvider(rootProject.configurations.named(Constants.REMAPPER_CONFIG).map { it.singleFile })
|
||||
outputJar.set(buildDir.resolve("libs/${shadowJar.get().archiveBaseName.get()}-reobf.jar"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ open class PaperweightExtension(objects: ObjectFactory, layout: ProjectLayout) {
|
|||
val workDir: DirectoryProperty = objects.dirWithDefault(layout, "work")
|
||||
|
||||
val minecraftVersion: Property<String> = objects.property()
|
||||
val versionPackage: Property<String> = objects.property()
|
||||
val serverProject: Property<Project> = objects.property()
|
||||
|
||||
val craftBukkit = CraftBukkitExtension(objects, workDir)
|
||||
|
|
|
@ -22,15 +22,19 @@
|
|||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.AtlasHelper
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.MappingFormats
|
||||
import io.papermc.paperweight.util.emptyMergeResult
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
import javax.inject.Inject
|
||||
import org.cadixdev.atlas.Atlas
|
||||
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.lorenz.asm.LorenzRemapper
|
||||
import org.cadixdev.lorenz.merge.FieldMergeStrategy
|
||||
import org.cadixdev.lorenz.merge.MappingSetMerger
|
||||
import org.cadixdev.lorenz.merge.MappingSetMergerHandler
|
||||
|
@ -48,6 +52,9 @@ import org.gradle.api.file.RegularFileProperty
|
|||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.submit
|
||||
import org.gradle.workers.WorkAction
|
||||
import org.gradle.workers.WorkParameters
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
|
||||
abstract class GenerateMappings : DefaultTask() {
|
||||
|
@ -85,11 +92,57 @@ abstract class GenerateMappings : DefaultTask() {
|
|||
).merge()
|
||||
|
||||
// Fill out any missing inheritance info in the mappings
|
||||
val filledMerged = AtlasHelper.using(workerExecutor).fillInheritance(merged, vanillaJar.path)
|
||||
val tempMappingsFile = Files.createTempFile("mappings", "tiny")
|
||||
val tempMappingsOutputFile = Files.createTempFile("mappings-out", "tiny")
|
||||
|
||||
val filledMerged = try {
|
||||
MappingFormats.TINY.write(merged, tempMappingsFile, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
|
||||
val queue = workerExecutor.processIsolation {
|
||||
forkOptions.jvmArgs("-Xmx1G")
|
||||
}
|
||||
|
||||
queue.submit(AtlasAction::class) {
|
||||
inputJar.set(vanillaJar.file)
|
||||
mappingsFile.set(tempMappingsFile.toFile())
|
||||
outputMappingsFile.set(tempMappingsOutputFile.toFile())
|
||||
}
|
||||
|
||||
queue.await()
|
||||
|
||||
MappingFormats.TINY.read(tempMappingsOutputFile, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
} finally {
|
||||
Files.deleteIfExists(tempMappingsFile)
|
||||
Files.deleteIfExists(tempMappingsOutputFile)
|
||||
}
|
||||
|
||||
ensureParentExists(outputMappings)
|
||||
MappingFormats.TINY.write(filledMerged, outputMappings.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
}
|
||||
|
||||
abstract class AtlasAction : WorkAction<AtlasParameters> {
|
||||
override fun execute() {
|
||||
val mappings = MappingFormats.TINY.read(parameters.mappingsFile.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
|
||||
val tempOut = Files.createTempFile("remapped", "jar")
|
||||
try {
|
||||
Atlas().let { atlas ->
|
||||
atlas.install { ctx -> JarEntryRemappingTransformer(LorenzRemapper(mappings, ctx.inheritanceProvider())) }
|
||||
atlas.run(parameters.inputJar.path, tempOut)
|
||||
}
|
||||
|
||||
MappingFormats.TINY.write(mappings, parameters.outputMappingsFile.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
} finally {
|
||||
Files.deleteIfExists(tempOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface AtlasParameters : WorkParameters {
|
||||
val inputJar: RegularFileProperty
|
||||
val mappingsFile: RegularFileProperty
|
||||
val outputMappingsFile: RegularFileProperty
|
||||
}
|
||||
}
|
||||
|
||||
class ParamsMergeHandler : MappingSetMergerHandler {
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.Constants.DEOBF_NAMESPACE
|
||||
import io.papermc.paperweight.util.Constants.SPIGOT_NAMESPACE
|
||||
import io.papermc.paperweight.util.MappingFormats
|
||||
import io.papermc.paperweight.util.commentRegex
|
||||
import io.papermc.paperweight.util.path
|
||||
|
@ -52,8 +53,8 @@ abstract class PatchMappings : DefaultTask() {
|
|||
fun run() {
|
||||
val mappings = MappingFormats.TINY.read(
|
||||
inputMappings.path,
|
||||
Constants.SPIGOT_NAMESPACE,
|
||||
Constants.DEOBF_NAMESPACE
|
||||
SPIGOT_NAMESPACE,
|
||||
DEOBF_NAMESPACE
|
||||
)
|
||||
patchMappings.pathOrNull?.let { patchFile ->
|
||||
val temp = Files.createTempFile("patch", "tiny")
|
||||
|
@ -71,13 +72,31 @@ abstract class PatchMappings : DefaultTask() {
|
|||
}
|
||||
}
|
||||
}
|
||||
MappingFormats.TINY.read(mappings, temp, Constants.SPIGOT_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
MappingFormats.TINY.read(mappings, temp, SPIGOT_NAMESPACE, DEOBF_NAMESPACE)
|
||||
} finally {
|
||||
Files.deleteIfExists(temp)
|
||||
}
|
||||
}
|
||||
|
||||
MappingFormats.TINY.write(mappings, outputMappings.path, Constants.SPIGOT_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
MappingFormats.TINY.write(mappings.reverse(), outputMappingsReversed.path, Constants.DEOBF_NAMESPACE, Constants.SPIGOT_NAMESPACE)
|
||||
MappingFormats.TINY.write(mappings, outputMappings.path, SPIGOT_NAMESPACE, DEOBF_NAMESPACE)
|
||||
MappingFormats.TINY.write(mappings.reverse(), outputMappingsReversed.path, DEOBF_NAMESPACE, SPIGOT_NAMESPACE)
|
||||
}
|
||||
//
|
||||
// private fun appendServerVersion(mappings: MappingSet): MappingSet {
|
||||
// val ver = versionPackage.get()
|
||||
//
|
||||
// val result = MappingSet.create()
|
||||
// for (topLevelClassMapping in mappings.topLevelClassMappings) {
|
||||
// val newMapping = if (topLevelClassMapping.deobfuscatedPackage == "net/minecraft/server") {
|
||||
// val newName = topLevelClassMapping.deobfuscatedPackage + "/v$ver/" + topLevelClassMapping.simpleDeobfuscatedName
|
||||
// result.createTopLevelClassMapping(topLevelClassMapping.obfuscatedName, newName)
|
||||
// } else {
|
||||
// result.createTopLevelClassMapping(topLevelClassMapping.obfuscatedName, topLevelClassMapping.deobfuscatedName)
|
||||
// }
|
||||
// topLevelClassMapping.fieldMappings.forEach { it.copy(newMapping) }
|
||||
// topLevelClassMapping.methodMappings.forEach { it.copy(newMapping) }
|
||||
// topLevelClassMapping.innerClassMappings.forEach { it.copy(newMapping) }
|
||||
// }
|
||||
// return result
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -22,21 +22,27 @@
|
|||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.AtlasHelper
|
||||
import io.papermc.paperweight.util.MappingFormats
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.ensureDeleted
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import java.nio.file.Files
|
||||
import javax.inject.Inject
|
||||
import org.cadixdev.atlas.Atlas
|
||||
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer
|
||||
import org.cadixdev.lorenz.asm.LorenzRemapper
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.submit
|
||||
import org.gradle.workers.WorkAction
|
||||
import org.gradle.workers.WorkParameters
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
import org.objectweb.asm.commons.Remapper
|
||||
|
||||
abstract class RemapJarAtlas : BaseTask() {
|
||||
|
||||
|
@ -45,6 +51,8 @@ abstract class RemapJarAtlas : BaseTask() {
|
|||
|
||||
@get:InputFile
|
||||
abstract val mappingsFile: RegularFileProperty
|
||||
@get:Input
|
||||
abstract val packageVersion: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val fromNamespace: Property<String>
|
||||
|
@ -66,9 +74,51 @@ abstract class RemapJarAtlas : BaseTask() {
|
|||
ensureParentExists(outputJar)
|
||||
ensureDeleted(outputJar)
|
||||
|
||||
val mappings = MappingFormats.TINY.read(mappingsFile.path, fromNamespace.get(), toNamespace.get())
|
||||
val queue = workerExecutor.processIsolation {
|
||||
forkOptions.jvmArgs("-Xmx1G")
|
||||
}
|
||||
|
||||
val result = AtlasHelper.using(workerExecutor).remap(mappings, inputJar)
|
||||
Files.move(result, outputJar.path)
|
||||
queue.submit(AtlasAction::class) {
|
||||
inputJar.set(this@RemapJarAtlas.inputJar.file)
|
||||
outputJar.set(this@RemapJarAtlas.outputJar.file)
|
||||
mappingsFile.set(this@RemapJarAtlas.mappingsFile.file)
|
||||
packageVersion.set(this@RemapJarAtlas.packageVersion.get())
|
||||
toNamespace.set(this@RemapJarAtlas.toNamespace.get())
|
||||
fromNamespace.set(this@RemapJarAtlas.fromNamespace.get())
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AtlasAction : WorkAction<AtlasParameters> {
|
||||
override fun execute() {
|
||||
val mappings = MappingFormats.TINY.read(parameters.mappingsFile.path, parameters.fromNamespace.get(), parameters.toNamespace.get())
|
||||
|
||||
val oldPack = "net/minecraft/server"
|
||||
val newPack = "$oldPack/v${parameters.packageVersion.get()}"
|
||||
Atlas().let { atlas ->
|
||||
atlas.install { ctx -> JarEntryRemappingTransformer(LorenzRemapper(mappings, ctx.inheritanceProvider())) }
|
||||
atlas.install { JarEntryRemappingTransformer(PackageRemapper(oldPack, newPack)) }
|
||||
atlas.run(parameters.inputJar.path, parameters.outputJar.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface AtlasParameters : WorkParameters {
|
||||
val inputJar: RegularFileProperty
|
||||
val outputJar: RegularFileProperty
|
||||
val mappingsFile: RegularFileProperty
|
||||
val fromNamespace: Property<String>
|
||||
val toNamespace: Property<String>
|
||||
val packageVersion: Property<String>
|
||||
}
|
||||
}
|
||||
|
||||
class PackageRemapper(private val oldPackage: String, private val newPackage: String) : Remapper() {
|
||||
|
||||
override fun map(internalName: String): String {
|
||||
return if (internalName.startsWith(oldPackage)) {
|
||||
internalName.replaceFirst(oldPackage, newPackage)
|
||||
} else {
|
||||
internalName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project.
|
||||
*
|
||||
* Copyright (c) 2020 Kyle Wood (DemonWav)
|
||||
* 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.util
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import org.cadixdev.atlas.Atlas
|
||||
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.lorenz.asm.LorenzRemapper
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.kotlin.dsl.submit
|
||||
import org.gradle.workers.WorkAction
|
||||
import org.gradle.workers.WorkParameters
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
|
||||
class AtlasHelper private constructor(private val workerExecutor: WorkerExecutor) {
|
||||
|
||||
fun remap(mappings: MappingSet, inputJar: Any): Path {
|
||||
val (outputJar, _) = runAtlas(mappings, inputJar)
|
||||
return outputJar
|
||||
}
|
||||
|
||||
fun fillInheritance(mappings: MappingSet, inputJar: Any): MappingSet {
|
||||
val (outputJar, outputMappings) = runAtlas(mappings, inputJar)
|
||||
try {
|
||||
return outputMappings
|
||||
} finally {
|
||||
Files.deleteIfExists(outputJar)
|
||||
}
|
||||
}
|
||||
|
||||
private fun runAtlas(mappings: MappingSet, input: Any): AtlasOutput {
|
||||
val inputFile = input.convertToFile()
|
||||
|
||||
val tempMappingsFile = Files.createTempFile("in-mappings", "tiny")
|
||||
val tempOutputMappingsFile = Files.createTempFile("out-mappings", "tiny")
|
||||
val outputJarFile = Files.createTempFile("output", "jar")
|
||||
|
||||
MappingFormats.TINY.write(mappings, tempMappingsFile, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
|
||||
val resultMappings: MappingSet = try {
|
||||
val queue = workerExecutor.processIsolation {
|
||||
forkOptions.jvmArgs("-Xmx1G")
|
||||
}
|
||||
|
||||
queue.submit(AtlasRunner::class) {
|
||||
inputJar.set(inputFile)
|
||||
outputJar.set(outputJarFile.toFile())
|
||||
mappingsFile.set(tempMappingsFile.toFile())
|
||||
outputMappingsFile.set(tempOutputMappingsFile.toFile())
|
||||
}
|
||||
|
||||
queue.await()
|
||||
|
||||
MappingFormats.TINY.read(tempOutputMappingsFile, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
} finally {
|
||||
Files.deleteIfExists(tempMappingsFile)
|
||||
Files.deleteIfExists(tempOutputMappingsFile)
|
||||
}
|
||||
|
||||
return AtlasOutput(outputJarFile, resultMappings)
|
||||
}
|
||||
|
||||
private data class AtlasOutput(
|
||||
val outputJar: Path,
|
||||
val outputMappings: MappingSet
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun using(workerExecutor: WorkerExecutor) = AtlasHelper(workerExecutor)
|
||||
}
|
||||
|
||||
abstract class AtlasRunner : WorkAction<AtlasParameters> {
|
||||
override fun execute() {
|
||||
val mappings = MappingFormats.TINY.read(parameters.mappingsFile.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
|
||||
Atlas().let { atlas ->
|
||||
atlas.install { ctx -> JarEntryRemappingTransformer(LorenzRemapper(mappings, ctx.inheritanceProvider())) }
|
||||
atlas.run(parameters.inputJar.path, parameters.outputJar.path)
|
||||
}
|
||||
|
||||
MappingFormats.TINY.write(mappings, parameters.outputMappingsFile.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
}
|
||||
}
|
||||
|
||||
interface AtlasParameters : WorkParameters {
|
||||
val inputJar: RegularFileProperty
|
||||
val outputJar: RegularFileProperty
|
||||
val mappingsFile: RegularFileProperty
|
||||
val outputMappingsFile: RegularFileProperty
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue