-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation("io.papermc.paperweight:paperweight-userdev:1.7.3") | ||
} |
514 changes: 514 additions & 0 deletions
514
buildSrc/src/main/java/modified/mercury/RemapperVisitor.java
Large diffs are not rendered by default.
Oops, something went wrong.
496 changes: 496 additions & 0 deletions
496
buildSrc/src/main/java/modified/mercury/SimpleRemapperVisitor.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import modified.mercury.RemapperVisitor | ||
import modified.mercury.SimpleRemapperVisitor | ||
import paper.libs.org.cadixdev.lorenz.MappingSet | ||
import paper.libs.org.cadixdev.mercury.RewriteContext | ||
import paper.libs.org.cadixdev.mercury.SourceRewriter | ||
import java.util.Objects | ||
|
||
class MercuryRemapper private constructor(mappings: MappingSet, simple: Boolean, javadoc: Boolean) : SourceRewriter { | ||
private val mappings: MappingSet | ||
private val simple: Boolean | ||
private val javadoc: Boolean | ||
|
||
init { | ||
this.mappings = Objects.requireNonNull(mappings, "mappings") | ||
this.simple = simple | ||
this.javadoc = javadoc | ||
} | ||
|
||
override fun getFlags(): Int = SourceRewriter.FLAG_RESOLVE_BINDINGS | ||
|
||
override fun rewrite(context: RewriteContext) { | ||
context.compilationUnit.accept(if (simple) SimpleRemapperVisitor(context, mappings, this.javadoc) else RemapperVisitor(context, mappings, this.javadoc)) | ||
} | ||
|
||
companion object { | ||
fun create(mappings: MappingSet): SourceRewriter { | ||
return MercuryRemapper(mappings, false, true) | ||
} | ||
|
||
fun create(mappings: MappingSet, javadoc: Boolean): SourceRewriter { | ||
return MercuryRemapper(mappings, false, javadoc) | ||
} | ||
|
||
fun createSimple(mappings: MappingSet): SourceRewriter { | ||
return MercuryRemapper(mappings, true, true) | ||
} | ||
|
||
fun createSimple(mappings: MappingSet, javadoc: Boolean): SourceRewriter { | ||
return MercuryRemapper(mappings, true, javadoc) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import io.papermc.paperweight.tasks.JavaLauncherTask | ||
import io.papermc.paperweight.tasks.RemapSources | ||
import io.papermc.paperweight.util.MappingFormats | ||
import io.papermc.paperweight.util.constants.DEOBF_NAMESPACE | ||
import io.papermc.paperweight.util.constants.SPIGOT_NAMESPACE | ||
import io.papermc.paperweight.util.deleteRecursive | ||
import io.papermc.paperweight.util.path | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.CompileClasspath | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputDirectory | ||
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 paper.libs.org.cadixdev.mercury.Mercury | ||
import paper.libs.org.eclipse.jdt.core.JavaCore | ||
import java.nio.file.Files | ||
import javax.inject.Inject | ||
|
||
abstract class RemapPluginSources : JavaLauncherTask() { | ||
@get:CompileClasspath | ||
abstract val remapClasspath: ConfigurableFileCollection | ||
|
||
@get:InputDirectory | ||
abstract val inputSources: DirectoryProperty | ||
|
||
@get:OutputDirectory | ||
abstract val outputDir: DirectoryProperty | ||
|
||
@get:InputFile | ||
abstract val mappingsFile: RegularFileProperty | ||
|
||
@get:Input | ||
abstract val addExplicitThis: Property<Boolean> | ||
|
||
@get:Inject | ||
abstract val workerExecutor: WorkerExecutor | ||
|
||
override fun init() { | ||
super.init() | ||
addExplicitThis.convention(false) | ||
} | ||
|
||
@TaskAction | ||
fun run() { | ||
val queue = workerExecutor.processIsolation { | ||
forkOptions.jvmArgs("-Xmx2G") | ||
forkOptions.executable(launcher.get().executablePath.path.toAbsolutePath().toString()) | ||
} | ||
|
||
queue.submit(RemapPluginSourcesAction::class) { | ||
remapClasspath.setFrom(this@RemapPluginSources.remapClasspath) | ||
inputSources.set(this@RemapPluginSources.inputSources) | ||
outputDir.set(this@RemapPluginSources.outputDir) | ||
mappingsFile.set(this@RemapPluginSources.mappingsFile) | ||
addExplicitThis.set(this@RemapPluginSources.addExplicitThis) | ||
} | ||
} | ||
|
||
abstract class RemapPluginSourcesAction : WorkAction<RemapPluginSourcesAction.Params> { | ||
interface Params : WorkParameters { | ||
val remapClasspath: ConfigurableFileCollection | ||
val inputSources: DirectoryProperty | ||
val outputDir: DirectoryProperty | ||
val mappingsFile: RegularFileProperty | ||
val addExplicitThis: Property<Boolean> | ||
} | ||
|
||
override fun execute() { | ||
val mappingSet = MappingFormats.TINY.read( | ||
parameters.mappingsFile.path, | ||
SPIGOT_NAMESPACE, | ||
DEOBF_NAMESPACE | ||
) | ||
|
||
val merc = Mercury() | ||
merc.isGracefulClasspathChecks = true | ||
merc.sourceCompatibility = JavaCore.VERSION_17 | ||
merc.classPath.addAll(parameters.remapClasspath.map { it.toPath() }) | ||
if (parameters.addExplicitThis.get()) { | ||
merc.processors.add(RemapSources.ExplicitThisAdder) | ||
} | ||
merc.processors.add(MercuryRemapper.create(mappingSet, false)) | ||
|
||
parameters.outputDir.path.deleteRecursive() | ||
Files.createDirectories(parameters.outputDir.path) | ||
|
||
merc.rewrite(parameters.inputSources.path, parameters.outputDir.path) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import io.papermc.paperweight.util.MappingFormats | ||
import io.papermc.paperweight.util.constants.DEOBF_NAMESPACE | ||
import io.papermc.paperweight.util.constants.SPIGOT_NAMESPACE | ||
import io.papermc.paperweight.util.path | ||
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 java.nio.file.Files | ||
|
||
abstract class ReverseMappings : io.papermc.paperweight.tasks.BaseTask() { | ||
@get:InputFile | ||
abstract val inputMappings: RegularFileProperty | ||
|
||
@get:OutputFile | ||
abstract val outputMappings: RegularFileProperty | ||
|
||
@get:Input | ||
abstract val fromNs: Property<String> | ||
|
||
@get:Input | ||
abstract val toNs: Property<String> | ||
|
||
@TaskAction | ||
fun run() { | ||
val mappingSet = MappingFormats.TINY.read( | ||
inputMappings.path, | ||
fromNs.get(), | ||
toNs.get() | ||
).reverse() | ||
|
||
Files.deleteIfExists(outputMappings.path) | ||
Files.createDirectories(outputMappings.path.parent) | ||
MappingFormats.TINY.write( | ||
mappingSet, | ||
outputMappings.path, | ||
toNs.get(), | ||
fromNs.get() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import io.papermc.paperweight.tasks.RemapJar | ||
import io.papermc.paperweight.util.constants.DEOBF_NAMESPACE | ||
import io.papermc.paperweight.util.constants.SPIGOT_NAMESPACE | ||
import io.papermc.paperweight.util.registering | ||
|
||
plugins { | ||
java | ||
id("io.papermc.paperweight.userdev") | ||
} | ||
|
||
tasks { | ||
val reverseMappings by registering<ReverseMappings> { | ||
inputMappings.set(layout.projectDirectory.file(".gradle/caches/paperweight/setupCache/extractDevBundle.dir/data/mojang+yarn-spigot-reobf.tiny")) | ||
outputMappings.set(layout.buildDirectory.file("reversed-reobf-mappings.tiny")) | ||
|
||
fromNs.set(DEOBF_NAMESPACE) | ||
toNs.set(SPIGOT_NAMESPACE) | ||
} | ||
|
||
val reobfPaperJar by tasks.registering<RemapJar> { | ||
// won't be runnable as we don't fixjarforreobf | ||
// pretty hacky but should work | ||
inputJar.set(layout.file(configurations.mojangMappedServerRuntime.flatMap { | ||
it.elements.map { elements -> | ||
elements.filter { element -> | ||
val p = element.asFile.absolutePath | ||
p.contains("ivyRepository") && p.contains("paper-server-userdev") | ||
}.single().asFile | ||
} | ||
})) | ||
outputJar.set(layout.buildDirectory.file("reobfPaper.jar")) | ||
fromNamespace.set(DEOBF_NAMESPACE) | ||
toNamespace.set(SPIGOT_NAMESPACE) | ||
mappingsFile.set(reverseMappings.flatMap { it.outputMappings }) | ||
remapper.from(configurations.remapper) | ||
} | ||
|
||
@Suppress("unused_variable") | ||
val remapPluginSources by registering<RemapPluginSources> { | ||
remapClasspath.from(reobfPaperJar.flatMap { it.outputJar }) | ||
remapClasspath.from(configurations.compileClasspath) | ||
inputSources.set(layout.projectDirectory.dir("src/main/java")) | ||
outputDir.set(layout.projectDirectory.dir("src/main/mojangMappedJava")) | ||
mappingsFile.set(reverseMappings.flatMap { it.outputMappings }) | ||
} | ||
} |