From e3648a7b1c03c2943bad378ee445ca1b86f15225 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Wed, 1 Dec 2021 20:55:13 +0800 Subject: [PATCH] Update for mc 1.18 --- build.gradle | 6 +- .../gradle/ArclightGradlePlugin.groovy | 16 ++-- .../gradle/tasks/BuildSpigotTask.groovy | 12 +++ .../gradle/tasks/ProcessMappingV2Task.groovy | 83 ++----------------- .../gradle/tasks/RemapSpigotTask.groovy | 2 - 5 files changed, 28 insertions(+), 91 deletions(-) diff --git a/build.gradle b/build.gradle index 703217e..2afd746 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.izzel.arclight' -version '1.20' +version '1.21' repositories { mavenCentral() @@ -25,8 +25,8 @@ dependencies { implementation group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true embed group: 'net.md-5', name: 'SpecialSource', version: '1.10.0' implementation "org.cadixdev:mercury:0.1.0" - embed 'org.cadixdev:lorenz-io-proguard:0.5.7' - embed 'org.cadixdev:lorenz:0.5.7' + embed 'org.cadixdev:lorenz-io-proguard:0.5.8' + embed 'org.cadixdev:lorenz:0.5.8' } java.toolchain.languageVersion = JavaLanguageVersion.of(16) diff --git a/src/main/groovy/io/izzel/arclight/gradle/ArclightGradlePlugin.groovy b/src/main/groovy/io/izzel/arclight/gradle/ArclightGradlePlugin.groovy index fa65d56..b81d978 100644 --- a/src/main/groovy/io/izzel/arclight/gradle/ArclightGradlePlugin.groovy +++ b/src/main/groovy/io/izzel/arclight/gradle/ArclightGradlePlugin.groovy @@ -69,7 +69,7 @@ class ArclightGradlePlugin implements Plugin { def processMapping = project.tasks.create('processMapping', ProcessMappingV2Task) def remapSpigot = project.tasks.create('remapSpigotJar', RemapSpigotTask) def generateMeta = project.tasks.create('generateArclightMeta', Copy) - def processAt = project.tasks.create('processAT', ProcessAccessTransformerTask) + //def processAt = project.tasks.create('processAT', ProcessAccessTransformerTask) def downloadInstaller = project.tasks.create('downloadInstaller') generateMeta.dependsOn(downloadInstaller) def metaFolder = project.file("${project.buildDir}/arclight_cache/meta") @@ -94,13 +94,13 @@ class ArclightGradlePlugin implements Plugin { task.packageName = arclightExt.packageName task.dependsOn(extractSrg, createSrgToMcp, buildSpigot) } - processAt.configure { ProcessAccessTransformerTask task -> - task.buildData = new File(buildTools, 'BuildData') - task.mcVersion = arclightExt.mcVersion - task.outDir = project.file("${project.buildDir}/arclight_cache/tmp_srg") - task.inSrg = extractSrg.output.get().asFile - task.dependsOn(extractSrg, createSrgToMcp, buildSpigot) - } + //processAt.configure { ProcessAccessTransformerTask task -> + // task.buildData = new File(buildTools, 'BuildData') + // task.mcVersion = arclightExt.mcVersion + // task.outDir = project.file("${project.buildDir}/arclight_cache/tmp_srg") + // task.inSrg = extractSrg.output.get().asFile + // task.dependsOn(extractSrg, createSrgToMcp, buildSpigot) + //} remapSpigot.configure { RemapSpigotTask task -> task.ssJar = new File(buildTools, 'BuildData/bin/SpecialSource.jar') task.inJar = new File(buildTools, "spigot-${arclightExt.mcVersion}.jar") diff --git a/src/main/groovy/io/izzel/arclight/gradle/tasks/BuildSpigotTask.groovy b/src/main/groovy/io/izzel/arclight/gradle/tasks/BuildSpigotTask.groovy index f511d39..14e71e4 100644 --- a/src/main/groovy/io/izzel/arclight/gradle/tasks/BuildSpigotTask.groovy +++ b/src/main/groovy/io/izzel/arclight/gradle/tasks/BuildSpigotTask.groovy @@ -9,6 +9,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import javax.inject.Inject +import java.util.jar.JarFile class BuildSpigotTask extends DefaultTask { @@ -73,5 +74,16 @@ class BuildSpigotTask extends DefaultTask { ] standardOutput = System.out } + def bundler = new File(outSpigot.parentFile, 'bundler-' + outSpigot.name) + outSpigot.renameTo(bundler) + new JarFile(bundler).with { + it.stream().filter(ent -> ent.name.startsWith('META-INF/versions/') && ent.name.endsWith('.jar')) + .limit(1) + .forEach { ent -> + outSpigot.withOutputStream { out -> + it.getInputStream(ent).transferTo(out) + } + } + } } } diff --git a/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingV2Task.groovy b/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingV2Task.groovy index ce5645c..cea5f86 100644 --- a/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingV2Task.groovy +++ b/src/main/groovy/io/izzel/arclight/gradle/tasks/ProcessMappingV2Task.groovy @@ -10,21 +10,14 @@ import org.cadixdev.lorenz.io.srg.csrg.CSrgReader import org.cadixdev.lorenz.io.srg.tsrg.TSrgReader import org.cadixdev.lorenz.io.srg.tsrg.TSrgWriter import org.cadixdev.lorenz.model.ClassMapping -import org.cadixdev.lorenz.model.MethodMapping import org.cadixdev.lorenz.model.TopLevelClassMapping import org.gradle.api.DefaultTask import org.gradle.api.tasks.* -import org.objectweb.asm.commons.Remapper import java.util.stream.Collectors class ProcessMappingV2Task extends DefaultTask { - private static final def PKG = [ - 'it', 'org/apache', 'jline', 'org/codehaus', 'org/eclipse' - ] - private static final Map KNOWN_WRONG_MAP = ['m_7870_': 'startDrownedConversion'] - private File buildData private File inSrg private File inMcp @@ -42,10 +35,6 @@ class ProcessMappingV2Task extends DefaultTask { clFile.withReader { new CSrgReader(it).read(csrg) } - def memberFile = new File(buildData, "mappings/bukkit-$mcVersion-members.csrg") - memberFile.withReader { - csrg = csrg.merge(new CSrgReader(it).read()) - } def srg = MappingSet.create() inSrg.withReader { def data = it.lines().filter { String s -> !(s.startsWith('\t\t') || s.startsWith('tsrg2')) }.collect(Collectors.joining('\n')) @@ -73,78 +62,14 @@ class ProcessMappingV2Task extends DefaultTask { } def srgRev = srg.reverse() def finalMap = srgRev.merge(csrg).reverse() - Map seenNames = [:] - finalMap.topLevelClassMappings.each { - if (!it.fullObfuscatedName.contains('/')) { - return - } - it.methodMappings.each { MethodMapping m -> - if (!m.hasDeobfuscatedName()) { - return - } - def s = m.deobfuscatedName - if (!s.startsWith('m_')) { - def c = srgRev.getTopLevelClassMapping(m.parent.deobfuscatedName).get() - if (c.getMethodMapping(m.deobfuscatedSignature).isEmpty()) { - if (m.obfuscatedName.length() > 4) { - def candidate = it.methodMappings.find { t -> t.obfuscatedName == m.obfuscatedName && t.deobfuscatedName != m.deobfuscatedName } - if (candidate) { - m.deobfuscatedName = candidate.deobfuscatedName - } - } - if (s == m.deobfuscatedName) { - println('No mapping found for ' + m) - } - } - } else { - def old = seenNames[m.deobfuscatedName] - if (old) { - if ((old.length() > 2 || m.obfuscatedName.length() > 2) && old != m.obfuscatedName) { - if (old.length() > 2 && m.obfuscatedName.length() > 2) { - if (KNOWN_WRONG_MAP[m.deobfuscatedName] != m.obfuscatedName) { - println("Duplicate [$old, ${m.obfuscatedName}] -> ${m.deobfuscatedName} in ${m.parent.fullDeobfuscatedName}") - } - } else { - seenNames[m.deobfuscatedName] = m.obfuscatedName.length() > old.length() ? m.obfuscatedName : old - } - } - } else { - seenNames[m.deobfuscatedName] = m.obfuscatedName - } - } - } - } new File(outDir, 'bukkit_srg.srg').withWriter { - PKG.each { pkg -> - it.writeLine("PK: org/bukkit/craftbukkit/libs/$pkg $pkg") - } new TSrgWriter(it) { - def remapper = new Remapper() { - @Override - String map(String internalName) { - for (String pkg : PKG) { - if (internalName.startsWith(pkg)) { - return 'org/bukkit/craftbukkit/libs/' + internalName - } - } - return internalName - } - } - @Override protected void writeClassMapping(ClassMapping mapping) { if (mapping.fullObfuscatedName.contains('/')) { super.writeClassMapping(mapping) } } - - @Override - protected void writeMethodMapping(MethodMapping mapping) { - this.writer.println(String.format("\t%s %s %s", - seenNames.getOrDefault(mapping.getDeobfuscatedName(), mapping.getObfuscatedName()), - remapper.mapMethodDesc(mapping.getObfuscatedDescriptor()), - mapping.getDeobfuscatedName())) - } }.write(finalMap) } new File(outDir, 'bukkit_at.at').withWriter { w -> @@ -161,8 +86,8 @@ class ProcessMappingV2Task extends DefaultTask { w.writeLine("${split[0].replace('inal', '')} ${(finalMap.deobfuscate(new ObjectType(split[1])) as ObjectType).className.replace('/', '.')}") } else { def cl = split[1].substring(0, split[1].lastIndexOf('/')) - def f = finalMap.getTopLevelClassMapping(cl) - .flatMap { mcp.getTopLevelClassMapping(it.fullDeobfuscatedName) } + def f = finalMap.getClassMapping(cl) + .flatMap { mcp.getClassMapping(it.fullDeobfuscatedName) } .flatMap { it.getFieldMapping(name) } .map { it.deobfuscatedName } if (f.isEmpty()) { @@ -176,7 +101,9 @@ class ProcessMappingV2Task extends DefaultTask { def s = split[1].substring(0, i) def cl = s.substring(0, s.lastIndexOf('/')) def name = s.substring(s.lastIndexOf('/') + 1) - def m = finalMap.getTopLevelClassMapping(cl).flatMap { it.getMethodMapping(name, desc) } + def m = finalMap.getClassMapping(cl) + .flatMap { mcp.getClassMapping(it.fullDeobfuscatedName) } + .map() { it.methodMappings.find { it.obfuscatedName == name } } if (m.isEmpty()) { w.writeLine("${name == '' ? '' : '# TODO '}${split[0].replace('inal', '')} ${(finalMap.deobfuscate(new ObjectType(cl)) as ObjectType).className.replace('/', '.')} $name${finalMap.deobfuscate(MethodDescriptor.of(desc))}") } else { diff --git a/src/main/groovy/io/izzel/arclight/gradle/tasks/RemapSpigotTask.groovy b/src/main/groovy/io/izzel/arclight/gradle/tasks/RemapSpigotTask.groovy index 7be42c6..b1fddcc 100644 --- a/src/main/groovy/io/izzel/arclight/gradle/tasks/RemapSpigotTask.groovy +++ b/src/main/groovy/io/izzel/arclight/gradle/tasks/RemapSpigotTask.groovy @@ -32,8 +32,6 @@ class RemapSpigotTask extends DefaultTask { includes = new ArrayList<>() includes.add('configurations') includes.add('META-INF/maven/org.spigotmc') - includes.add('META-INF/services') - includes.add('mojang-translations') includes.add('org/spigotmc') includes.add('org/bukkit/craftbukkit') includes.add('version.json')