Switch from SRG/MCP base to Mojmap with Yarn param names
This commit is contained in:
parent
54c2bef2cc
commit
0e34cf4a62
40 changed files with 252 additions and 1687 deletions
|
@ -39,7 +39,7 @@ dependencies {
|
|||
implementation("org.cadixdev:lorenz-io-proguard:$lorenzVersion")
|
||||
implementation("org.cadixdev:atlas:0.2.0")
|
||||
implementation("org.cadixdev:at:0.1.0-rc1")
|
||||
implementation("org.cadixdev:mercury:0.1.0-PW0-SNAPSHOT")
|
||||
implementation("org.cadixdev:mercury:0.1.0-rc2-PW-SNAPSHOT")
|
||||
|
||||
implementation("net.fabricmc:lorenz-tiny:3.0.0")
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ Install this plugin to Maven Local:
|
|||
./gradlew install
|
||||
```
|
||||
|
||||
Clone a new Paper repo and checkout the `feature/mcp` branch.
|
||||
Clone a new Paper repo and checkout the `feature/mojmap` branch.
|
||||
|
||||
Run the task (on the Paper repo) to set up the development environment:
|
||||
|
||||
|
|
|
@ -34,30 +34,25 @@ import io.papermc.paperweight.tasks.AddAdditionalSpigotMappings
|
|||
import io.papermc.paperweight.tasks.ApplyDiffPatches
|
||||
import io.papermc.paperweight.tasks.ApplyGitPatches
|
||||
import io.papermc.paperweight.tasks.ApplyPaperPatches
|
||||
import io.papermc.paperweight.tasks.DecompileVanillaJar
|
||||
import io.papermc.paperweight.tasks.DownloadMcLibraries
|
||||
import io.papermc.paperweight.tasks.DownloadMcpFiles
|
||||
import io.papermc.paperweight.tasks.DownloadMcpTools
|
||||
import io.papermc.paperweight.tasks.DownloadServerJar
|
||||
import io.papermc.paperweight.tasks.DownloadSpigotDependencies
|
||||
import io.papermc.paperweight.tasks.DownloadTask
|
||||
import io.papermc.paperweight.tasks.ExtractMappings
|
||||
import io.papermc.paperweight.tasks.ExtractMcp
|
||||
import io.papermc.paperweight.tasks.Filter
|
||||
import io.papermc.paperweight.tasks.FilterExcludes
|
||||
import io.papermc.paperweight.tasks.FilterJar
|
||||
import io.papermc.paperweight.tasks.FilterSpigotExcludes
|
||||
import io.papermc.paperweight.tasks.FixJar
|
||||
import io.papermc.paperweight.tasks.GenerateSpigotMappings
|
||||
import io.papermc.paperweight.tasks.GenerateMappings
|
||||
import io.papermc.paperweight.tasks.GenerateSpigotMappings
|
||||
import io.papermc.paperweight.tasks.InspectVanillaJar
|
||||
import io.papermc.paperweight.tasks.MergeAccessTransforms
|
||||
import io.papermc.paperweight.tasks.PatchMappings
|
||||
import io.papermc.paperweight.tasks.RemapAccessTransform
|
||||
import io.papermc.paperweight.tasks.RemapJar
|
||||
import io.papermc.paperweight.tasks.RemapSpigotAt
|
||||
import io.papermc.paperweight.tasks.RemapVanillaJarSpigot
|
||||
import io.papermc.paperweight.tasks.RunForgeFlower
|
||||
import io.papermc.paperweight.tasks.SetupMcLibraries
|
||||
import io.papermc.paperweight.tasks.WriteLibrariesFile
|
||||
import io.papermc.paperweight.tasks.SpigotDecompileJar
|
||||
import io.papermc.paperweight.tasks.SpigotRemapJar
|
||||
import io.papermc.paperweight.tasks.patchremap.ApplyAccessTransform
|
||||
import io.papermc.paperweight.tasks.patchremap.RemapPatches
|
||||
import io.papermc.paperweight.tasks.sourceremap.RemapSources
|
||||
|
@ -86,7 +81,7 @@ class Paperweight : Plugin<Project> {
|
|||
override fun apply(target: Project) {
|
||||
target.extensions.create(Constants.EXTENSION, PaperweightExtension::class.java, target.objects, target.layout)
|
||||
|
||||
val downloadService = target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {}
|
||||
target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {}
|
||||
|
||||
target.tasks.register<Delete>("cleanCache") {
|
||||
group = "Paper"
|
||||
|
@ -97,57 +92,81 @@ class Paperweight : Plugin<Project> {
|
|||
// Make sure the submodules are initialized
|
||||
Git(target.projectDir)("submodule", "update", "--init").execute()
|
||||
|
||||
target.configurations.create(Constants.YARN_CONFIG)
|
||||
target.configurations.create(Constants.PARAM_MAPPINGS_CONFIG)
|
||||
target.configurations.create(Constants.REMAPPER_CONFIG)
|
||||
target.configurations.create(Constants.DECOMPILER_CONFIG)
|
||||
|
||||
target.repositories.apply {
|
||||
mavenCentral()
|
||||
// Both of these are needed for Spigot
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
|
||||
maven("https://maven.fabricmc.net/") {
|
||||
maven(Constants.FABRIC_MAVEN_URL) {
|
||||
content {
|
||||
onlyForConfigurations(Constants.YARN_CONFIG, Constants.REMAPPER_CONFIG)
|
||||
onlyForConfigurations(Constants.PARAM_MAPPINGS_CONFIG, Constants.REMAPPER_CONFIG)
|
||||
}
|
||||
}
|
||||
maven(Constants.FORGE_MAVEN_URL) {
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
content {
|
||||
onlyForConfigurations(Constants.DECOMPILER_CONFIG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
target.createTasks(downloadService)
|
||||
target.createTasks()
|
||||
|
||||
// Setup the server jar
|
||||
target.afterEvaluate {
|
||||
val serverProj = target.ext.serverProject.orNull ?: return@afterEvaluate
|
||||
if (!serverProj.projectDir.exists()) {
|
||||
return@afterEvaluate
|
||||
}
|
||||
|
||||
val cache = target.layout.cache
|
||||
|
||||
serverProj.plugins.apply("java")
|
||||
serverProj.dependencies.apply {
|
||||
val remappedJar = cache.resolve(Constants.FINAL_REMAPPED_JAR)
|
||||
if (remappedJar.exists()) {
|
||||
add("implementation", target.files(remappedJar))
|
||||
}
|
||||
|
||||
val libsFile = cache.resolve(Constants.MC_LIBRARIES)
|
||||
if (libsFile.exists()) {
|
||||
libsFile.forEachLine { line ->
|
||||
if (!line.startsWith("org.lwjgl")) { // lwjgl is definitely client only
|
||||
add("implementation", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.createTasks(downloadService: Provider<DownloadService>) {
|
||||
private fun Project.createTasks() {
|
||||
val extension = ext
|
||||
val cache: File = layout.cache
|
||||
|
||||
val initialTasks = createInitialTasks(downloadService)
|
||||
val generalTasks = createGeneralTasks(downloadService)
|
||||
val mcpTasks = createMcpTasks(downloadService, initialTasks, generalTasks)
|
||||
val spigotTasks = createSpigotTasks(downloadService, initialTasks, generalTasks, mcpTasks)
|
||||
val initialTasks = createInitialTasks()
|
||||
val generalTasks = createGeneralTasks()
|
||||
val vanillaTasks = createVanillaTasks(initialTasks, generalTasks)
|
||||
val spigotTasks = createSpigotTasks(generalTasks, vanillaTasks)
|
||||
|
||||
createPatchRemapTasks(initialTasks, generalTasks, mcpTasks, spigotTasks)
|
||||
createPatchRemapTasks(generalTasks, vanillaTasks, spigotTasks)
|
||||
|
||||
val applyMergedAt by tasks.registering<ApplyAccessTransform> {
|
||||
inputJar.set(mcpTasks.fixJar.flatMap { it.outputJar })
|
||||
inputJar.set(vanillaTasks.fixJar.flatMap { it.outputJar })
|
||||
atFile.set(spigotTasks.mergeGeneratedAts.flatMap { it.outputFile })
|
||||
|
||||
outputJar.set(cache.resolve(Constants.FINAL_REMAPPED_JAR))
|
||||
}
|
||||
|
||||
val writeLibrariesFile by tasks.registering<WriteLibrariesFile> {
|
||||
libraries.set(mcpTasks.downloadMcLibraries.flatMap { it.outputDir })
|
||||
}
|
||||
|
||||
val decompileVanillaJarYarn by tasks.registering<RunForgeFlower> {
|
||||
executable.set(initialTasks.downloadMcpTools.flatMap { it.forgeFlowerFile })
|
||||
configFile.set(initialTasks.extractMcp.flatMap { it.configFile })
|
||||
val decompileJar by tasks.registering<RunForgeFlower> {
|
||||
executable.fileProvider(configurations.named(Constants.DECOMPILER_CONFIG).map { it.singleFile })
|
||||
|
||||
inputJar.set(applyMergedAt.flatMap { it.outputJar })
|
||||
libraries.set(writeLibrariesFile.flatMap { it.outputFile })
|
||||
libraries.set(vanillaTasks.downloadMcLibraries.flatMap { it.outputDir })
|
||||
}
|
||||
|
||||
// val mergeRemappedSources by tasks.registering<Merge> {
|
||||
// inputJars.add(spigotTasks.remapSpigotSources.flatMap { it.outputZip })
|
||||
// inputJars.add(applySourceAt.flatMap { it.outputZip })
|
||||
// }
|
||||
|
||||
val patchPaperApi by tasks.registering<ApplyGitPatches> {
|
||||
branch.set("HEAD")
|
||||
upstreamBranch.set("upstream")
|
||||
|
@ -161,9 +180,8 @@ class Paperweight : Plugin<Project> {
|
|||
val patchPaperServer by tasks.registering<ApplyPaperPatches> {
|
||||
patchDir.set(extension.paper.spigotServerPatchDir)
|
||||
remappedSource.set(spigotTasks.remapSpigotSources.flatMap { it.outputZip })
|
||||
templateGitIgnore.set(layout.projectDirectory.file(".gitignore"))
|
||||
sourceMcDevJar.set(decompileVanillaJarYarn.flatMap { it.outputJar })
|
||||
mcLibrariesDir.set(mcpTasks.downloadMcLibraries.flatMap { it.outputDir }.get())
|
||||
sourceMcDevJar.set(decompileJar.flatMap { it.outputJar })
|
||||
mcLibrariesDir.set(vanillaTasks.downloadMcLibraries.flatMap { it.outputDir }.get())
|
||||
libraryImports.set(extension.paper.libraryClassImports)
|
||||
|
||||
outputDir.set(extension.paper.paperServerDir)
|
||||
|
@ -174,35 +192,21 @@ class Paperweight : Plugin<Project> {
|
|||
description = "Set up the Paper development environment"
|
||||
dependsOn(patchPaperApi, patchPaperServer)
|
||||
}
|
||||
|
||||
/*
|
||||
* Not bothering mapping away from SRG until everything is stable under SRG
|
||||
* Moving off of SRG will make things a lot more fragile
|
||||
val remapSrgSourcesSpigotVanilla by tasks.registering<RemapSrgSources> {
|
||||
inputZips.add(ZipTarget.base(applyMcpPatches.flatMap { outputZip }))
|
||||
methodsCsv.set(mcpRewrites.flatMap { methodsCsv })
|
||||
fieldsCsv.set(mcpRewrites.flatMap { fieldsCsv })
|
||||
paramsCsv.set(mcpRewrites.flatMap { paramsCsv })
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Shared task containers
|
||||
data class InitialTasks(
|
||||
val setupMcLibraries: TaskProvider<SetupMcLibraries>,
|
||||
val downloadMappings: TaskProvider<DownloadTask>,
|
||||
val extractMcp: Provider<ExtractMcp>,
|
||||
val mcpMappings: Provider<ExtractMappings>,
|
||||
val downloadMcpTools: TaskProvider<DownloadMcpTools>
|
||||
val downloadMappings: TaskProvider<DownloadTask>
|
||||
)
|
||||
|
||||
data class GeneralTasks(
|
||||
val buildDataInfo: Provider<BuildDataInfo>,
|
||||
val downloadServerJar: TaskProvider<DownloadServerJar>,
|
||||
val filterVanillaJar: TaskProvider<Filter>
|
||||
val filterVanillaJar: TaskProvider<FilterJar>
|
||||
)
|
||||
|
||||
data class McpTasks(
|
||||
data class VanillaTasks(
|
||||
val generateMappings: TaskProvider<GenerateMappings>,
|
||||
val fixJar: TaskProvider<FixJar>,
|
||||
val downloadMcLibraries: TaskProvider<DownloadMcLibraries>
|
||||
|
@ -210,16 +214,17 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
data class SpigotTasks(
|
||||
val patchMappings: TaskProvider<PatchMappings>,
|
||||
val decompileVanillaJarSpigot: TaskProvider<DecompileVanillaJar>,
|
||||
val spigotDecompileJar: TaskProvider<SpigotDecompileJar>,
|
||||
val patchSpigotApi: TaskProvider<ApplyGitPatches>,
|
||||
val patchSpigotServer: TaskProvider<ApplyGitPatches>,
|
||||
val remapSpigotSources: TaskProvider<RemapSources>,
|
||||
val mergeGeneratedAts: TaskProvider<MergeAccessTransforms>
|
||||
)
|
||||
|
||||
private fun Project.createInitialTasks(downloadService: Provider<DownloadService>): InitialTasks {
|
||||
private fun Project.createInitialTasks(): InitialTasks {
|
||||
val cache: File = layout.cache
|
||||
val extension: PaperweightExtension = ext
|
||||
val downloadService = download
|
||||
|
||||
val downloadMcManifest by tasks.registering<DownloadTask> {
|
||||
url.set(Constants.MC_MANIFEST_URL)
|
||||
|
@ -227,7 +232,6 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
val mcManifest = downloadMcManifest.flatMap { it.outputFile }.map { gson.fromJson<MinecraftManifest>(it) }
|
||||
|
||||
val downloadMcVersionManifest by tasks.registering<DownloadTask> {
|
||||
|
@ -238,7 +242,6 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
val versionManifest = downloadMcVersionManifest.flatMap { it.outputFile }.map { gson.fromJson<JsonObject>(it) }
|
||||
|
||||
val setupMcLibraries by tasks.registering<SetupMcLibraries> {
|
||||
|
@ -259,48 +262,12 @@ class Paperweight : Plugin<Project> {
|
|||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
val downloadMcpFiles by tasks.registering<DownloadMcpFiles> {
|
||||
mcpMinecraftVersion.set(extension.mcpMinecraftVersion)
|
||||
mcpConfigVersion.set(extension.mcpConfigVersion)
|
||||
mcpMappingsChannel.set(extension.mcpMappingsChannel)
|
||||
mcpMappingsVersion.set(extension.mcpMappingsVersion)
|
||||
|
||||
configZip.set(cache.resolve(Constants.MCP_ZIPS_PATH).resolve("McpConfig.zip"))
|
||||
mappingsZip.set(cache.resolve(Constants.MCP_ZIPS_PATH).resolve("McpMappings.zip"))
|
||||
|
||||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
val extractMcpConfig by tasks.registering<ExtractMcp> {
|
||||
inputFile.set(downloadMcpFiles.flatMap { it.configZip })
|
||||
outputDir.set(cache.resolve(Constants.MCP_DATA_DIR))
|
||||
}
|
||||
val extractMcpMappings by tasks.registering<ExtractMappings> {
|
||||
inputFile.set(downloadMcpFiles.flatMap { it.mappingsZip })
|
||||
outputDir.set(cache.resolve(Constants.MCP_MAPPINGS_DIR))
|
||||
}
|
||||
|
||||
val downloadMcpTools by tasks.registering<DownloadMcpTools> {
|
||||
configFile.set(extractMcpConfig.flatMap { it.configFile })
|
||||
|
||||
val toolsPath = cache.resolve(Constants.MCP_TOOLS_PATH)
|
||||
forgeFlowerFile.set(toolsPath.resolve("ForgeFlower.jar"))
|
||||
mcInjectorFile.set(toolsPath.resolve("McInjector.jar"))
|
||||
specialSourceFile.set(toolsPath.resolve("SpecialSource.jar"))
|
||||
|
||||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
return InitialTasks(
|
||||
setupMcLibraries,
|
||||
downloadMappings,
|
||||
extractMcpConfig,
|
||||
extractMcpMappings,
|
||||
downloadMcpTools
|
||||
)
|
||||
return InitialTasks(setupMcLibraries, downloadMappings)
|
||||
}
|
||||
|
||||
private fun Project.createGeneralTasks(downloadService: Provider<DownloadService>): GeneralTasks {
|
||||
private fun Project.createGeneralTasks(): GeneralTasks {
|
||||
val downloadService = download
|
||||
|
||||
val buildDataInfo: Provider<BuildDataInfo> = contents(ext.craftBukkit.buildDataInfo) {
|
||||
gson.fromJson(it)
|
||||
}
|
||||
|
@ -312,7 +279,7 @@ class Paperweight : Plugin<Project> {
|
|||
downloader.set(downloadService)
|
||||
}
|
||||
|
||||
val filterVanillaJar by tasks.registering<Filter> {
|
||||
val filterVanillaJar by tasks.registering<FilterJar> {
|
||||
inputJar.set(downloadServerJar.flatMap { it.outputJar })
|
||||
includes.set(listOf("/*.class", "/net/minecraft/**"))
|
||||
}
|
||||
|
@ -320,64 +287,30 @@ class Paperweight : Plugin<Project> {
|
|||
return GeneralTasks(buildDataInfo, downloadServerJar, filterVanillaJar)
|
||||
}
|
||||
|
||||
private fun Project.createMcpTasks(
|
||||
downloadService: Provider<DownloadService>,
|
||||
initialTasks: InitialTasks,
|
||||
generalTasks: GeneralTasks
|
||||
): McpTasks {
|
||||
val filterVanillaJar: TaskProvider<Filter> = generalTasks.filterVanillaJar
|
||||
private fun Project.createVanillaTasks(initialTasks: InitialTasks, generalTasks: GeneralTasks): VanillaTasks {
|
||||
val filterJar: TaskProvider<FilterJar> = generalTasks.filterVanillaJar
|
||||
val cache: File = layout.cache
|
||||
|
||||
// val mcpRewrites by tasks.registering<PatchMcpCsv> {
|
||||
// fieldsCsv.set(initialTasks.mcpMappings.flatMap { it.fieldsCsv })
|
||||
// methodsCsv.set(initialTasks.mcpMappings.flatMap { it.methodsCsv })
|
||||
// paramsCsv.set(initialTasks.mcpMappings.flatMap { it.paramsCsv })
|
||||
// changesFile.set(extension.paper.mcpRewritesFile)
|
||||
//
|
||||
// paperFieldCsv.set(cache.resolve(Constants.PAPER_FIELDS_CSV))
|
||||
// paperMethodCsv.set(cache.resolve(Constants.PAPER_METHODS_CSV))
|
||||
// paperParamCsv.set(cache.resolve(Constants.PAPER_PARAMS_CSV))
|
||||
// }
|
||||
val downloadService = download
|
||||
|
||||
val generateMappings by tasks.registering<GenerateMappings> {
|
||||
vanillaJar.set(generalTasks.filterVanillaJar.flatMap { it.outputJar })
|
||||
|
||||
vanillaMappings.set(initialTasks.downloadMappings.flatMap { it.outputFile })
|
||||
yarnMappings.fileProvider(configurations.named(Constants.YARN_CONFIG).map { it.singleFile })
|
||||
paramMappings.fileProvider(configurations.named(Constants.PARAM_MAPPINGS_CONFIG).map { it.singleFile })
|
||||
|
||||
outputMappings.set(cache.resolve(Constants.SRG_DIR).resolve("merged.tiny"))
|
||||
outputMappings.set(cache.resolve(Constants.MOJANG_YARN_MAPPINGS))
|
||||
}
|
||||
|
||||
val remapJar by tasks.registering<RemapJar> {
|
||||
inputJar.set(filterVanillaJar.flatMap { it.outputJar })
|
||||
inputJar.set(filterJar.flatMap { it.outputJar })
|
||||
mappingsFile.set(generateMappings.flatMap { it.outputMappings })
|
||||
remapper.fileProvider(configurations.named(Constants.REMAPPER_CONFIG).map { it.singleFile })
|
||||
}
|
||||
|
||||
val fixJar by tasks.registering<FixJar> {
|
||||
// executable.set(initialTasks.downloadMcpTools.flatMap { it.mcInjectorFile })
|
||||
inputJar.set(remapJar.flatMap { it.outputJar })
|
||||
}
|
||||
|
||||
// val remapVanillaJarSrg by tasks.registering<RunSpecialSource> {
|
||||
// inputJar.set(filterVanillaJar.flatMap { it.outputJar })
|
||||
// mappings.set(generateSrgs.flatMap { it.notchToSrg })
|
||||
//
|
||||
// executable.set(initialTasks.downloadMcpTools.flatMap { it.specialSourceFile })
|
||||
// configFile.set(initialTasks.extractMcp.flatMap { it.configFile })
|
||||
// }
|
||||
//
|
||||
// val injectVanillaJarSrg by tasks.registering<RunMcInjector> {
|
||||
// executable.set(initialTasks.downloadMcpTools.flatMap { it.mcInjectorFile })
|
||||
// configFile.set(initialTasks.extractMcp.flatMap { it.configFile })
|
||||
//
|
||||
// exceptions.set(initialTasks.extractMcp.flatMap { it.exceptions })
|
||||
// access.set(initialTasks.extractMcp.flatMap { it.access })
|
||||
// constructors.set(initialTasks.extractMcp.flatMap { it.constructors })
|
||||
//
|
||||
// inputJar.set(remapVanillaJarSrg.flatMap { it.outputJar })
|
||||
// }
|
||||
|
||||
val downloadMcLibraries by tasks.registering<DownloadMcLibraries> {
|
||||
mcLibrariesFile.set(initialTasks.setupMcLibraries.flatMap { it.outputFile })
|
||||
mcRepo.set(Constants.MC_LIBRARY_URL)
|
||||
|
@ -385,27 +318,17 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
downloader.set(downloadService)
|
||||
}
|
||||
//
|
||||
// val applyMcpPatches by tasks.registering<ApplyMcpPatches> {
|
||||
// inputZip.set(decompileVanillaJarSrg.flatMap { it.outputJar })
|
||||
// serverPatchDir.set(initialTasks.extractMcp.flatMap { it.patchDir })
|
||||
// configFile.set(cache.resolve(Constants.MCP_CONFIG_JSON))
|
||||
// }
|
||||
|
||||
return McpTasks(generateMappings, fixJar, downloadMcLibraries)
|
||||
return VanillaTasks(generateMappings, fixJar, downloadMcLibraries)
|
||||
}
|
||||
|
||||
private fun Project.createSpigotTasks(
|
||||
downloadService: Provider<DownloadService>,
|
||||
initialTasks: InitialTasks,
|
||||
generalTasks: GeneralTasks,
|
||||
mcpTasks: McpTasks
|
||||
): SpigotTasks {
|
||||
private fun Project.createSpigotTasks(generalTasks: GeneralTasks, vanillaTasks: VanillaTasks): SpigotTasks {
|
||||
val cache: File = layout.cache
|
||||
val extension: PaperweightExtension = ext
|
||||
val downloadService = download
|
||||
|
||||
val (buildDataInfo, downloadServerJar, filterVanillaJar) = generalTasks
|
||||
val (generateMappings, _, _) = mcpTasks
|
||||
val (generateMappings, _, _) = vanillaTasks
|
||||
|
||||
val addAdditionalSpigotMappings by tasks.registering<AddAdditionalSpigotMappings> {
|
||||
classSrg.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.classMappings }))
|
||||
|
@ -429,17 +352,17 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
sourceMappings.set(generateMappings.flatMap { it.outputMappings })
|
||||
|
||||
outputMappings.set(cache.resolve(Constants.SRG_DIR).resolve("spigot-named.tiny"))
|
||||
outputMappings.set(cache.resolve(Constants.SPIGOT_MOJANG_YARN_MAPPINGS))
|
||||
}
|
||||
|
||||
val patchMappings by tasks.registering<PatchMappings> {
|
||||
inputMappings.set(generateSpigotMappings.flatMap { it.outputMappings })
|
||||
patchMappings.set(extension.paper.mappingsPatch)
|
||||
|
||||
outputMappings.set(cache.resolve(Constants.SRG_DIR).resolve("spigot-named-patched.tiny"))
|
||||
outputMappings.set(cache.resolve(Constants.PATCHED_SPIGOT_MOJANG_YARN_MAPPINGS))
|
||||
}
|
||||
|
||||
val remapVanillaJarSpigot by tasks.registering<RemapVanillaJarSpigot> {
|
||||
val spigotRemapJar by tasks.registering<SpigotRemapJar> {
|
||||
inputJar.set(filterVanillaJar.flatMap { it.outputJar })
|
||||
classMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.classMappings }))
|
||||
memberMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.memberMappings }))
|
||||
|
@ -456,19 +379,19 @@ class Paperweight : Plugin<Project> {
|
|||
finalMapCommand.set(buildDataInfo.map { it.finalMapCommand })
|
||||
}
|
||||
|
||||
val removeSpigotExcludes by tasks.registering<FilterExcludes> {
|
||||
inputZip.set(remapVanillaJarSpigot.flatMap { it.outputJar })
|
||||
val filterSpigotExcludes by tasks.registering<FilterSpigotExcludes> {
|
||||
inputZip.set(spigotRemapJar.flatMap { it.outputJar })
|
||||
excludesFile.set(extension.craftBukkit.excludesFile)
|
||||
}
|
||||
|
||||
val decompileVanillaJarSpigot by tasks.registering<DecompileVanillaJar> {
|
||||
inputJar.set(removeSpigotExcludes.flatMap { it.outputZip })
|
||||
val spigotDecompileJar by tasks.registering<SpigotDecompileJar> {
|
||||
inputJar.set(filterSpigotExcludes.flatMap { it.outputZip })
|
||||
fernFlowerJar.set(extension.craftBukkit.fernFlowerJar)
|
||||
decompileCommand.set(buildDataInfo.map { it.decompileCommand })
|
||||
}
|
||||
|
||||
val patchCraftBukkit by tasks.registering<ApplyDiffPatches> {
|
||||
sourceJar.set(decompileVanillaJarSpigot.flatMap { it.outputJar })
|
||||
sourceJar.set(spigotDecompileJar.flatMap { it.outputJar })
|
||||
sourceBasePath.set("net/minecraft/server")
|
||||
branch.set("patched")
|
||||
patchDir.set(extension.craftBukkit.patchDir)
|
||||
|
@ -508,7 +431,7 @@ class Paperweight : Plugin<Project> {
|
|||
}
|
||||
|
||||
val remapSpigotAt by tasks.registering<RemapSpigotAt> {
|
||||
inputJar.set(remapVanillaJarSpigot.flatMap { it.outputJar })
|
||||
inputJar.set(spigotRemapJar.flatMap { it.outputJar })
|
||||
mapping.set(patchMappings.flatMap { it.outputMappings })
|
||||
spigotAt.set(extension.craftBukkit.atFile)
|
||||
}
|
||||
|
@ -518,9 +441,8 @@ class Paperweight : Plugin<Project> {
|
|||
spigotApiDir.set(patchSpigotApi.flatMap { it.outputDir })
|
||||
mappings.set(patchMappings.flatMap { it.outputMappings })
|
||||
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
|
||||
vanillaRemappedSpigotJar.set(removeSpigotExcludes.flatMap { it.outputZip })
|
||||
vanillaRemappedSpigotJar.set(filterSpigotExcludes.flatMap { it.outputZip })
|
||||
spigotDeps.set(downloadSpigotDependencies.flatMap { it.outputDir })
|
||||
constructors.set(initialTasks.extractMcp.flatMap { it.constructors })
|
||||
}
|
||||
|
||||
val remapGeneratedAt by tasks.registering<RemapAccessTransform> {
|
||||
|
@ -535,7 +457,7 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
return SpigotTasks(
|
||||
patchMappings,
|
||||
decompileVanillaJarSpigot,
|
||||
spigotDecompileJar,
|
||||
patchSpigotApi,
|
||||
patchSpigotServer,
|
||||
remapSpigotSources,
|
||||
|
@ -543,12 +465,7 @@ class Paperweight : Plugin<Project> {
|
|||
)
|
||||
}
|
||||
|
||||
private fun Project.createPatchRemapTasks(
|
||||
initialTasks: InitialTasks,
|
||||
generalTasks: GeneralTasks,
|
||||
mcpTasks: McpTasks,
|
||||
spigotTasks: SpigotTasks
|
||||
) {
|
||||
private fun Project.createPatchRemapTasks(generalTasks: GeneralTasks, vanillaTasks: VanillaTasks, spigotTasks: SpigotTasks) {
|
||||
val extension: PaperweightExtension = ext
|
||||
|
||||
/*
|
||||
|
@ -562,7 +479,7 @@ class Paperweight : Plugin<Project> {
|
|||
*/
|
||||
|
||||
val applyVanillaSrgAt by tasks.registering<ApplyAccessTransform> {
|
||||
inputJar.set(mcpTasks.fixJar.flatMap { it.outputJar })
|
||||
inputJar.set(vanillaTasks.fixJar.flatMap { it.outputJar })
|
||||
atFile.set(spigotTasks.mergeGeneratedAts.flatMap { it.outputFile })
|
||||
}
|
||||
|
||||
|
@ -583,7 +500,6 @@ class Paperweight : Plugin<Project> {
|
|||
description = "EXPERIMENTAL & BROKEN: Attempt to remap Paper's patches from Spigot mappings to SRG."
|
||||
|
||||
inputPatchDir.set(extension.paper.unmappedSpigotServerPatchDir)
|
||||
// sourceJar.set(spigotTasks.remapSpigotSources.flatMap { it.outputZip }.get())
|
||||
apiPatchDir.set(extension.paper.spigotApiPatchDir)
|
||||
|
||||
mappingsFile.set(spigotTasks.patchMappings.flatMap { it.outputMappings }.get())
|
||||
|
@ -595,16 +511,17 @@ class Paperweight : Plugin<Project> {
|
|||
|
||||
spigotApiDir.set(spigotTasks.patchSpigotApi.flatMap { it.outputDir }.get())
|
||||
spigotServerDir.set(spigotTasks.patchSpigotServer.flatMap { it.outputDir }.get())
|
||||
spigotDecompJar.set(spigotTasks.decompileVanillaJarSpigot.flatMap { it.outputJar }.get())
|
||||
constructors.set(initialTasks.extractMcp.flatMap { it.constructors }.get())
|
||||
spigotDecompJar.set(spigotTasks.spigotDecompileJar.flatMap { it.outputJar }.get())
|
||||
|
||||
// library class imports
|
||||
mcLibrariesDir.set(mcpTasks.downloadMcLibraries.flatMap { it.outputDir }.get())
|
||||
mcLibrariesDir.set(vanillaTasks.downloadMcLibraries.flatMap { it.outputDir }.get())
|
||||
libraryImports.set(extension.paper.libraryClassImports)
|
||||
|
||||
parameterNames.set(spigotTasks.remapSpigotSources.flatMap { it.parameterNames }.get())
|
||||
|
||||
outputPatchDir.set(extension.paper.remappedSpigotServerPatchDir)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val Project.download: Provider<DownloadService>
|
||||
get() = gradle.sharedServices.registrations.getByName("download").service as Provider<DownloadService>
|
||||
}
|
||||
|
|
|
@ -31,12 +31,14 @@ open class CraftBukkitExtension(objects: ObjectFactory, workDir: DirectoryProper
|
|||
val bukkitDir: DirectoryProperty = objects.dirFrom(workDir, "Bukkit")
|
||||
val craftBukkitDir: DirectoryProperty = objects.dirFrom(workDir, "CraftBukkit")
|
||||
val patchDir: DirectoryProperty = objects.dirFrom(craftBukkitDir, "nms-patches")
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val buildDataDir: DirectoryProperty = objects.dirFrom(workDir, "BuildData")
|
||||
val buildDataInfo: RegularFileProperty = objects.fileFrom(buildDataDir, "info.json")
|
||||
val mappingsDir: DirectoryProperty = objects.dirFrom(buildDataDir, "mappings")
|
||||
val excludesFile: RegularFileProperty = objects.bukkitFileFrom(mappingsDir, "exclude")
|
||||
val atFile: RegularFileProperty = objects.bukkitFileFrom(mappingsDir, "at")
|
||||
val buildDataInfo: RegularFileProperty = objects.fileFrom(buildDataDir, "info.json")
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val buildDataBinDir: DirectoryProperty = objects.dirFrom(buildDataDir, "bin")
|
||||
val fernFlowerJar: RegularFileProperty = objects.fileFrom(buildDataBinDir, "fernflower.jar")
|
||||
|
|
|
@ -38,16 +38,9 @@ open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) {
|
|||
val paperServerDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "Paper-Server")
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val mcpDir: DirectoryProperty = objects.dirWithDefault(layout, "mcp")
|
||||
val buildDataDir: DirectoryProperty = objects.dirWithDefault(layout, "build-data")
|
||||
val additionalSpigotClassMappings: RegularFileProperty = objects.fileProperty()
|
||||
val additionalSpigotMemberMappings: RegularFileProperty = objects.fileProperty()
|
||||
val libraryClassImports: RegularFileProperty = objects.fileFrom(mcpDir, "library-imports.txt")
|
||||
val libraryClassImports: RegularFileProperty = objects.fileFrom(buildDataDir, "library-imports.txt")
|
||||
val mappingsPatch: RegularFileProperty = objects.fileProperty()
|
||||
|
||||
init {
|
||||
spigotApiPatchDir.disallowUnsafeRead()
|
||||
spigotServerPatchDir.disallowUnsafeRead()
|
||||
paperApiDir.disallowUnsafeRead()
|
||||
paperServerDir.disallowUnsafeRead()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
@ -36,24 +36,12 @@ open class PaperweightExtension(objects: ObjectFactory, layout: ProjectLayout) {
|
|||
val workDir: DirectoryProperty = objects.dirWithDefault(layout, "work")
|
||||
|
||||
val minecraftVersion: Property<String> = objects.property()
|
||||
val mcpMinecraftVersion: Property<String> = objects.property<String>().convention(minecraftVersion)
|
||||
val mcpConfigVersion: Property<String> = objects.property()
|
||||
val mcpMappingsChannel: Property<String> = objects.property()
|
||||
val mcpMappingsVersion: Property<String> = objects.property()
|
||||
|
||||
val mcpConfigFile: RegularFileProperty = objects.fileProperty().convention(null)
|
||||
val serverProject: Property<Project> = objects.property()
|
||||
|
||||
val craftBukkit = CraftBukkitExtension(objects, workDir)
|
||||
val spigot = SpigotExtension(objects, workDir)
|
||||
val paper = PaperExtension(objects, layout)
|
||||
|
||||
init {
|
||||
minecraftVersion.disallowUnsafeRead()
|
||||
mcpMinecraftVersion.disallowUnsafeRead()
|
||||
mcpMappingsChannel.disallowUnsafeRead()
|
||||
mcpMappingsVersion.disallowUnsafeRead()
|
||||
}
|
||||
|
||||
fun craftBukkit(action: Action<in CraftBukkitExtension>) {
|
||||
action.execute(craftBukkit)
|
||||
}
|
||||
|
|
|
@ -26,17 +26,10 @@ import org.gradle.api.file.DirectoryProperty
|
|||
import org.gradle.api.model.ObjectFactory
|
||||
|
||||
open class SpigotExtension(objects: ObjectFactory, workDir: DirectoryProperty) {
|
||||
var spigotDir: DirectoryProperty = objects.dirFrom(workDir, "Spigot")
|
||||
var spigotApiDir: DirectoryProperty = objects.dirFrom(spigotDir, "Spigot-API")
|
||||
var spigotServerDir: DirectoryProperty = objects.dirFrom(spigotDir, "Spigot-Server")
|
||||
var bukkitPatchDir: DirectoryProperty = objects.dirFrom(spigotDir, "Bukkit-Patches")
|
||||
var craftBukkitPatchDir: DirectoryProperty = objects.dirFrom(spigotDir, "CraftBukkit-Patches")
|
||||
|
||||
init {
|
||||
spigotDir.disallowUnsafeRead()
|
||||
spigotApiDir.disallowUnsafeRead()
|
||||
spigotServerDir.disallowUnsafeRead()
|
||||
bukkitPatchDir.disallowUnsafeRead()
|
||||
craftBukkitPatchDir.disallowUnsafeRead()
|
||||
}
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val spigotDir: DirectoryProperty = objects.dirFrom(workDir, "Spigot")
|
||||
val spigotApiDir: DirectoryProperty = objects.dirFrom(spigotDir, "Spigot-API")
|
||||
val spigotServerDir: DirectoryProperty = objects.dirFrom(spigotDir, "Spigot-Server")
|
||||
val bukkitPatchDir: DirectoryProperty = objects.dirFrom(spigotDir, "Bukkit-Patches")
|
||||
val craftBukkitPatchDir: DirectoryProperty = objects.dirFrom(spigotDir, "CraftBukkit-Patches")
|
||||
}
|
||||
|
|
|
@ -63,7 +63,10 @@ abstract class AddAdditionalSpigotMappings : BaseTask() {
|
|||
|
||||
private fun addLines(inFile: File, appendFile: File?, outputFile: File) {
|
||||
val lines = mutableListOf<String>()
|
||||
inFile.useLines { seq -> seq.forEach { lines.add(it) } }
|
||||
inFile.useLines { seq ->
|
||||
seq.filter { it.startsWith("") }
|
||||
}
|
||||
inFile.forEachLine { line -> lines += line }
|
||||
appendFile?.useLines { seq -> seq.forEach { lines.add(it) } }
|
||||
lines.sort()
|
||||
outputFile.bufferedWriter().use { writer ->
|
||||
|
|
|
@ -39,8 +39,6 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
@get:InputFile
|
||||
abstract val remappedSource: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val templateGitIgnore: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val sourceMcDevJar: RegularFileProperty
|
||||
@get:InputDirectory
|
||||
abstract val mcLibrariesDir: DirectoryProperty
|
||||
|
@ -88,10 +86,9 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
val patches = patchDir.file.listFiles { _, name -> name.endsWith(".patch") } ?: emptyArray()
|
||||
McDev.importMcDev(patches, sourceMcDevJar.file, libraryImports.file, mcLibrariesDir.file, sourceDir)
|
||||
|
||||
templateGitIgnore.file.copyTo(outputFile.resolve(".gitignore"))
|
||||
|
||||
git("add", ".gitignore", ".").executeSilently()
|
||||
git("add", ".").executeSilently()
|
||||
git("commit", "-m", "Initial", "--author=Initial <auto@mated.null>").executeSilently()
|
||||
git("tag", "base").executeSilently()
|
||||
|
||||
applyGitPatches(git, target, outputFile, patchDir.file, printOutput.get())
|
||||
}
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
import org.cadixdev.mercury.Mercury
|
||||
import org.cadixdev.mercury.at.AccessTransformerRewriter
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.kotlin.dsl.submit
|
||||
import org.gradle.workers.WorkAction
|
||||
import org.gradle.workers.WorkParameters
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
|
||||
abstract class ApplySourceAt : ZippedTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val vanillaJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val vanillaRemappedSrgJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val atFile: RegularFileProperty
|
||||
|
||||
@get:Inject
|
||||
abstract val workerExecutor: WorkerExecutor
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
val input = rootDir.resolve("input")
|
||||
val output = rootDir.resolve("output")
|
||||
|
||||
// Move everything into `input/` so we can put output into `output/`
|
||||
input.mkdirs()
|
||||
rootDir.listFiles()?.forEach { file ->
|
||||
if (file != input) {
|
||||
file.renameTo(input.resolve(file.name))
|
||||
}
|
||||
}
|
||||
output.mkdirs()
|
||||
|
||||
val queue = workerExecutor.processIsolation {
|
||||
forkOptions.jvmArgs("-Xmx2G")
|
||||
}
|
||||
|
||||
queue.submit(AtAction::class) {
|
||||
classpath.add(vanillaJar.file)
|
||||
classpath.add(vanillaRemappedSrgJar.file)
|
||||
|
||||
at.set(atFile.file)
|
||||
|
||||
inputDir.set(input)
|
||||
outputDir.set(output)
|
||||
}
|
||||
|
||||
queue.await()
|
||||
|
||||
// Remove input files
|
||||
rootDir.listFiles()?.forEach { file ->
|
||||
if (file != output) {
|
||||
file.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
// Move output into root
|
||||
output.listFiles()?.forEach { file ->
|
||||
file.renameTo(rootDir.resolve(file.name))
|
||||
}
|
||||
output.delete()
|
||||
}
|
||||
|
||||
abstract class AtAction : WorkAction<AtParams> {
|
||||
override fun execute() {
|
||||
val at = AccessTransformFormats.FML.read(parameters.at.path)
|
||||
|
||||
Mercury().let { merc ->
|
||||
merc.classPath.addAll(parameters.classpath.get().map { it.toPath() })
|
||||
|
||||
merc.processors.add(AccessTransformerRewriter.create(at))
|
||||
|
||||
merc.rewrite(parameters.inputDir.path, parameters.outputDir.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface AtParams : WorkParameters {
|
||||
val classpath: ListProperty<File>
|
||||
val at: RegularFileProperty
|
||||
val inputDir: RegularFileProperty
|
||||
val outputDir: RegularFileProperty
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ import org.gradle.api.tasks.InputFile
|
|||
* Because Spigot doesn't remap all classes, there are class and package name clashes if we don't do this in the source
|
||||
* remap step. Other than that, we don't need this jar
|
||||
*/
|
||||
abstract class FilterExcludes : ZippedTask() {
|
||||
abstract class FilterSpigotExcludes : ZippedTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val excludesFile: RegularFileProperty
|
|
@ -3,7 +3,6 @@ package io.papermc.paperweight.tasks
|
|||
import io.papermc.paperweight.util.AsmUtil
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.util.jar.JarFile
|
||||
import java.util.jar.JarOutputStream
|
||||
import java.util.zip.ZipEntry
|
||||
|
@ -76,8 +75,12 @@ abstract class FixJar : BaseTask(), AsmUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This was adapted from code originally written by Pokechu22 in MCInjector
|
||||
* Link: https://github.com/ModCoderPack/MCInjector/pull/3
|
||||
*/
|
||||
class ParameterAnnotationFixer(
|
||||
private val node: ClassNode,
|
||||
classVisitor: ClassVisitor?
|
||||
|
|
|
@ -59,7 +59,7 @@ abstract class GenerateMappings : DefaultTask() {
|
|||
@get:InputFile
|
||||
abstract val vanillaMappings: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val yarnMappings: RegularFileProperty
|
||||
abstract val paramMappings: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputMappings: RegularFileProperty
|
||||
|
@ -68,14 +68,14 @@ abstract class GenerateMappings : DefaultTask() {
|
|||
fun run() {
|
||||
val vanillaMappings = MappingFormats.byId("proguard").createReader(vanillaMappings.path).use { it.read() }.reverse()
|
||||
|
||||
val yarnMappings = FileSystems.newFileSystem(yarnMappings.path, null).use { fs ->
|
||||
val paramMappings = FileSystems.newFileSystem(paramMappings.path, null).use { fs ->
|
||||
val path = fs.getPath("mappings", "mappings.tiny")
|
||||
TinyMappingFormat.STANDARD.read(path, "official", "named")
|
||||
}
|
||||
|
||||
val merged = MappingSetMerger.create(
|
||||
vanillaMappings,
|
||||
yarnMappings,
|
||||
paramMappings,
|
||||
MergeConfig.builder()
|
||||
.withFieldMergeStrategy(FieldMergeStrategy.STRICT)
|
||||
.withMergeHandler(ParamsMergeHandler())
|
||||
|
@ -96,41 +96,6 @@ abstract class GenerateMappings : DefaultTask() {
|
|||
ensureParentExists(outputMappings)
|
||||
TinyMappingFormat.STANDARD.write(merged, outputMappings.path, Constants.OBF_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
}
|
||||
|
||||
/*
|
||||
private fun remapAnonymousClasses(mapping: InnerClassMapping, target: ClassMapping<*, *>) {
|
||||
val newMapping = target.createInnerClassMapping(mapping.obfuscatedName, mapping.deobfuscatedName)
|
||||
remapMembers(mapping, newMapping)
|
||||
}
|
||||
|
||||
private fun <T : ClassMapping<*, *>> remapMembers(mapping: T, newMapping: T) {
|
||||
for (fieldMapping in mapping.fieldMappings) {
|
||||
newMapping.createFieldMapping(fieldMapping.obfuscatedName, fieldMapping.deobfuscatedName)
|
||||
}
|
||||
for (methodMapping in mapping.methodMappings) {
|
||||
newMapping.createMethodMapping(methodMapping.signature, methodMapping.deobfuscatedName)
|
||||
}
|
||||
for (innerClassMapping in mapping.innerClassMappings) {
|
||||
remapAnonymousClasses(innerClassMapping, newMapping)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
private fun mergeClass(vanillaMapping: ClassMapping<*, *>, yarnMapping: ClassMapping<*, *>) {
|
||||
for (vanillaMethod in vanillaMapping.methodMappings) {
|
||||
val yarnMethod = yarnMapping.getMethodMapping(vanillaMethod.signature).orNull ?: continue
|
||||
for (yarnParam in yarnMethod.parameterMappings) {
|
||||
vanillaMethod.getOrCreateParameterMapping(yarnParam.index).deobfuscatedName = yarnParam.deobfuscatedName
|
||||
}
|
||||
}
|
||||
|
||||
for (vanillaClass in vanillaMapping.innerClassMappings) {
|
||||
val yarnClass = yarnMapping.getInnerClassMapping(vanillaClass.obfuscatedName).orNull ?: continue
|
||||
mergeClass(vanillaClass, yarnClass)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
class ParamsMergeHandler : MappingSetMergerHandler {
|
||||
|
|
|
@ -272,54 +272,76 @@ class SyntheticMethods {
|
|||
private val methods: MutableList<Data>
|
||||
) : MethodNode(Opcodes.ASM9, access, name, descriptor, signature, exceptions) {
|
||||
|
||||
private enum class State {
|
||||
IN_PARAMS,
|
||||
INVOKE,
|
||||
RETURN,
|
||||
OTHER_INSN
|
||||
}
|
||||
|
||||
// This tries to match the behavior of SpecialSource2's SyntheticFinder.addSynthetics() method
|
||||
override fun visitEnd() {
|
||||
var state = State.IN_PARAMS
|
||||
var nextLvt = 0
|
||||
|
||||
val insns = instructions.iterator().asSequence()
|
||||
.filter { it !is LabelNode && it !is LineNumberNode && it !is TypeInsnNode }
|
||||
.dropWhile {
|
||||
if (it !is VarInsnNode || it.`var` != nextLvt) {
|
||||
return@dropWhile false
|
||||
}
|
||||
var invokeInsn: MethodInsnNode? = null
|
||||
|
||||
nextLvt++
|
||||
if (it.opcode == Opcodes.LLOAD || it.opcode == Opcodes.DLOAD) {
|
||||
nextLvt++
|
||||
}
|
||||
return@dropWhile true
|
||||
loop@for (insn in instructions) {
|
||||
if (insn is LabelNode || insn is LineNumberNode || insn is TypeInsnNode) {
|
||||
continue
|
||||
}
|
||||
.take(3)
|
||||
.toList()
|
||||
|
||||
// Must only have 2 instructions left
|
||||
if (insns.size != 2) {
|
||||
return
|
||||
if (state == State.IN_PARAMS) {
|
||||
if (insn !is VarInsnNode || insn.`var` != nextLvt) {
|
||||
state = State.INVOKE
|
||||
}
|
||||
}
|
||||
|
||||
when (state) {
|
||||
State.IN_PARAMS -> {
|
||||
nextLvt++
|
||||
if (insn.opcode == Opcodes.LLOAD || insn.opcode == Opcodes.DLOAD) {
|
||||
nextLvt++
|
||||
}
|
||||
}
|
||||
State.INVOKE -> {
|
||||
// Must be a virtual or interface invoke instruction
|
||||
if ((insn.opcode != Opcodes.INVOKEVIRTUAL && insn.opcode != Opcodes.INVOKEINTERFACE) || insn !is MethodInsnNode) {
|
||||
return
|
||||
}
|
||||
|
||||
invokeInsn = insn
|
||||
state = State.RETURN
|
||||
}
|
||||
State.RETURN -> {
|
||||
// The next instruction must be a return
|
||||
if (insn.opcode !in Opcodes.IRETURN..Opcodes.RETURN) {
|
||||
return
|
||||
}
|
||||
|
||||
state = State.OTHER_INSN
|
||||
}
|
||||
State.OTHER_INSN -> {
|
||||
// We shouldn't see any other instructions
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val insn = insns.first()
|
||||
// Must be a virtual or interface invoke instruction
|
||||
if ((insn.opcode != Opcodes.INVOKEVIRTUAL && insn.opcode != Opcodes.INVOKEINTERFACE) || insn !is MethodInsnNode) {
|
||||
return
|
||||
}
|
||||
|
||||
// The next instruction must be a return
|
||||
val next = insns[1]
|
||||
if (next.opcode !in Opcodes.IRETURN..Opcodes.RETURN) {
|
||||
return
|
||||
}
|
||||
val invoke = invokeInsn ?: return
|
||||
|
||||
// Must be a method in the same class with a different signature
|
||||
if (className != insn.owner || name == insn.name || desc == insn.desc) {
|
||||
if (className != invoke.owner || name == invoke.name || desc == invoke.desc) {
|
||||
return
|
||||
}
|
||||
|
||||
// The descriptors need to be the same size
|
||||
if (Type.getArgumentTypes(desc).size != Type.getArgumentTypes(insn.desc).size) {
|
||||
if (Type.getArgumentTypes(desc).size != Type.getArgumentTypes(invoke.desc).size) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add this method as a synthetic accessor for insn.name
|
||||
methods += Data(className, insn.desc, name, insn.name)
|
||||
methods += Data(className, invoke.desc, name, invoke.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import org.cadixdev.at.AccessTransformSet
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.commentRegex
|
||||
import io.papermc.paperweight.util.path
|
||||
import io.papermc.paperweight.util.pathOrNull
|
||||
import java.nio.file.Files
|
||||
|
@ -29,7 +30,7 @@ abstract class PatchMappings : DefaultTask() {
|
|||
patchMappings.pathOrNull?.let { patchFile ->
|
||||
val temp = Files.createTempFile("patch", "tiny")
|
||||
try {
|
||||
val comment = Regex("\\s*#.*")
|
||||
val comment = commentRegex()
|
||||
// tiny format doesn't allow comments, so we manually remove them
|
||||
// The tiny mappings reader also doesn't have a InputStream or Reader input...
|
||||
Files.newBufferedReader(patchFile).useLines { lines ->
|
||||
|
|
|
@ -24,11 +24,9 @@ package io.papermc.paperweight.tasks
|
|||
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import net.fabricmc.lorenztiny.TinyMappingFormat
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
|
|
|
@ -27,23 +27,12 @@ import io.papermc.paperweight.util.Constants.paperTaskOutput
|
|||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import javax.inject.Inject
|
||||
import net.fabricmc.lorenztiny.TinyMappingFormat
|
||||
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.tasks.Classpath
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.Internal
|
||||
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 RemapJar : BaseTask() {
|
||||
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.getCsvReader
|
||||
import java.io.BufferedReader
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
|
||||
abstract class RemapSrgSources : ZippedTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val methodsCsv: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val fieldsCsv: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val paramsCsv: RegularFileProperty
|
||||
|
||||
private val methods = hashMapOf<String, String>()
|
||||
private val methodDocs = hashMapOf<String, String>()
|
||||
private val fields = hashMapOf<String, String>()
|
||||
private val fieldDocs = hashMapOf<String, String>()
|
||||
private val params = hashMapOf<String, String>()
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
readCsv()
|
||||
|
||||
rootDir.walkBottomUp()
|
||||
.filter { it.isFile && it.name.endsWith(".java") }
|
||||
.forEach(::processFile)
|
||||
}
|
||||
|
||||
private fun processFile(file: File) {
|
||||
val newFile = file.resolveSibling(file.name + ".bak")
|
||||
file.bufferedReader().use { reader ->
|
||||
newFile.bufferedWriter().use { writer ->
|
||||
writeFile(reader, writer)
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.delete()) {
|
||||
throw PaperweightException("Failed to delete file: $file")
|
||||
}
|
||||
|
||||
newFile.renameTo(file)
|
||||
}
|
||||
|
||||
private fun writeFile(reader: BufferedReader, writer: BufferedWriter) {
|
||||
for (line in reader.lineSequence()) {
|
||||
replaceInLine(line, writer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun replaceInLine(line: String, writer: BufferedWriter) {
|
||||
val buffer = StringBuffer()
|
||||
val matcher = SRG_FINDER.matcher(line)
|
||||
|
||||
while (matcher.find()) {
|
||||
val find = matcher.group()
|
||||
|
||||
val result = when {
|
||||
find.startsWith("p_") -> params[find]
|
||||
find.startsWith("func_") -> methods[find]
|
||||
find.startsWith("field_") -> fields[find]
|
||||
else -> null
|
||||
} ?: matcher.group()
|
||||
|
||||
matcher.appendReplacement(buffer, result)
|
||||
}
|
||||
|
||||
matcher.appendTail(buffer)
|
||||
|
||||
writer.appendln(buffer.toString())
|
||||
}
|
||||
|
||||
private fun readCsv() {
|
||||
readCsvFile(methodsCsv.asFile.get(), methods, methodDocs)
|
||||
readCsvFile(fieldsCsv.asFile.get(), fields, fieldDocs)
|
||||
|
||||
getCsvReader(paramsCsv.asFile.get()).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
params[line[0]] = line[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readCsvFile(file: File, names: MutableMap<String, String>, docs: MutableMap<String, String>) {
|
||||
getCsvReader(file).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
names[line[0]] = line[1]
|
||||
if (line[3].isNotEmpty()) {
|
||||
docs[line[0]] = line[3]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SRG_FINDER = Pattern.compile("func_[0-9]+_[a-zA-Z_]+|field_[0-9]+_[a-zA-Z_]+|p_[\\w]+_\\d+_\\b")
|
||||
}
|
||||
}
|
|
@ -23,30 +23,27 @@
|
|||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.McpConfig
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.decompile
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.fromJson
|
||||
import io.papermc.paperweight.util.gson
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.Classpath
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class RunForgeFlower : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val configFile: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val executable: RegularFileProperty
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val libraries: RegularFileProperty
|
||||
|
||||
@get:Classpath
|
||||
abstract val libraries: DirectoryProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputJar: RegularFileProperty
|
||||
|
@ -64,35 +61,48 @@ abstract class RunForgeFlower : BaseTask() {
|
|||
}
|
||||
target.mkdirs()
|
||||
|
||||
val config = gson.fromJson<McpConfig>(configFile)
|
||||
val libs = libraries.file.listFiles()?.sorted() ?: emptyList()
|
||||
val tempFile = createTempFile("paperweight", "txt")
|
||||
|
||||
val argList = listOf(
|
||||
"-ind= ",
|
||||
"-din=1",
|
||||
"-rbr=1",
|
||||
"-dgs=1",
|
||||
"-asc=1",
|
||||
"-rsy=1",
|
||||
"-iec=1",
|
||||
"-jvn=0",
|
||||
"-isl=0",
|
||||
"-iib=1",
|
||||
"-log=TRACE",
|
||||
"-cfg",
|
||||
libraries.file.absolutePath,
|
||||
inputJar.file.absolutePath,
|
||||
target.absolutePath
|
||||
)
|
||||
try {
|
||||
tempFile.bufferedWriter().use { writer ->
|
||||
for (lib in libs) {
|
||||
if (lib.name.endsWith(".jar") && !lib.name.endsWith("-sources.jar")) {
|
||||
writer.appendln("-e=${lib.absolutePath}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val logFile = layout.cache.resolve(paperTaskOutput("log"))
|
||||
logFile.delete()
|
||||
val argList = listOf(
|
||||
"-ind= ",
|
||||
"-din=1",
|
||||
"-rbr=1",
|
||||
"-dgs=1",
|
||||
"-asc=1",
|
||||
"-rsy=1",
|
||||
"-iec=1",
|
||||
"-jvn=0",
|
||||
"-isl=0",
|
||||
"-iib=1",
|
||||
"-log=TRACE",
|
||||
"-cfg",
|
||||
tempFile.absolutePath,
|
||||
inputJar.file.absolutePath,
|
||||
target.absolutePath
|
||||
)
|
||||
|
||||
val jvmArgs = config.functions.decompile.jvmargs ?: listOf()
|
||||
val logFile = layout.cache.resolve(paperTaskOutput("log"))
|
||||
logFile.delete()
|
||||
|
||||
runJar(executable.file, layout.cache, logFile, jvmArgs = jvmArgs, args = *argList.toTypedArray())
|
||||
val jvmArgs = listOf("-Xmx4G")
|
||||
|
||||
// FernFlower is weird with how it does directory output
|
||||
target.resolve(inputJar.file.name).renameTo(out)
|
||||
target.deleteRecursively()
|
||||
runJar(executable.file, layout.cache, logFile, jvmArgs = jvmArgs, args = *argList.toTypedArray())
|
||||
|
||||
// FernFlower is weird with how it does directory output
|
||||
target.resolve(inputJar.file.name).renameTo(out)
|
||||
target.deleteRecursively()
|
||||
} finally {
|
||||
tempFile.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.util.jar.JarOutputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import javax.inject.Inject
|
||||
import org.gradle.api.file.FileVisitDetails
|
||||
import org.gradle.api.file.FileVisitor
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.LoggingManager
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.objectweb.asm.ClassReader
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
import org.objectweb.asm.ClassWriter
|
||||
import org.objectweb.asm.Opcodes
|
||||
import org.objectweb.asm.tree.ClassNode
|
||||
|
||||
abstract class RunMcInjector : BaseTask() {
|
||||
|
||||
// @get:InputFile
|
||||
// abstract val configFile: RegularFileProperty
|
||||
// @get:InputFile
|
||||
// abstract val executable: RegularFileProperty
|
||||
|
||||
// @get:InputFile
|
||||
// abstract val exceptions: RegularFileProperty
|
||||
// @get:InputFile
|
||||
// abstract val access: RegularFileProperty
|
||||
// @get:InputFile
|
||||
// abstract val constructors: RegularFileProperty
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputJar: RegularFileProperty
|
||||
// @get:Internal
|
||||
// abstract val logFile: RegularFileProperty
|
||||
|
||||
@get:Inject
|
||||
abstract val loggingManger: LoggingManager
|
||||
|
||||
override fun init() {
|
||||
outputJar.convention(defaultOutput())
|
||||
// logFile.convention(defaultOutput("log"))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
loggingManger.captureStandardOutput(LogLevel.QUIET)
|
||||
loggingManger.captureStandardError(LogLevel.QUIET)
|
||||
|
||||
val classNode = ClassNode(Opcodes.ASM6)
|
||||
var visitor: ClassVisitor
|
||||
visitor = ParameterAnnotationFixer(classNode, null)
|
||||
// visitor = InnerClassInitAdder(visitor)
|
||||
// visitor = ClassInitAdder(visitor)
|
||||
|
||||
JarOutputStream(outputJar.file.outputStream()).use { out ->
|
||||
archives.zipTree(inputJar.file).matching {
|
||||
include("/*.class")
|
||||
include("/net/minecraft/**/*.class")
|
||||
}.visit(object : FileVisitor {
|
||||
override fun visitDir(dirDetails: FileVisitDetails) {}
|
||||
override fun visitFile(fileDetails: FileVisitDetails) {
|
||||
val classData = fileDetails.file.readBytes()
|
||||
|
||||
out.putNextEntry(ZipEntry(fileDetails.path))
|
||||
try {
|
||||
val reader = ClassReader(classData)
|
||||
reader.accept(visitor, 0)
|
||||
|
||||
val writer = ClassWriter(ClassWriter.COMPUTE_MAXS)
|
||||
classNode.accept(writer)
|
||||
|
||||
ByteArrayInputStream(writer.toByteArray()).copyTo(out)
|
||||
} finally {
|
||||
out.closeEntry()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// val config = gson.fromJson<McpConfig>(configFile)
|
||||
//
|
||||
// val argList = config.functions.mcinject.args.map {
|
||||
// when (it) {
|
||||
// "{input}" -> inputJar.file.absolutePath
|
||||
// "{output}" -> outputJar.file.absolutePath
|
||||
// "{log}" -> logFile.file.absolutePath
|
||||
// "{exceptions}" -> exceptions.file.absolutePath
|
||||
// "{access}" -> access.file.absolutePath
|
||||
// "{constructors}" -> constructors.file.absolutePath
|
||||
// else -> it
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val jvmArgs = config.functions.mcinject.jvmargs ?: listOf()
|
||||
|
||||
// runJar(
|
||||
// executable,
|
||||
// layout.cache,
|
||||
// logFile = null,
|
||||
// args = *arrayOf(
|
||||
// "--in", inputJar.file.absolutePath,
|
||||
// "--out", outputJar.file.absolutePath,
|
||||
// "--log", logFile.file.absolutePath,
|
||||
// "--level=INFO",
|
||||
// "--lvt=STRIP"
|
||||
// )
|
||||
// )
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.McpConfig
|
||||
import io.papermc.paperweight.util.cache
|
||||
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.fromJson
|
||||
import io.papermc.paperweight.util.gson
|
||||
import io.papermc.paperweight.util.rename
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class RunSpecialSource : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val mappings: RegularFileProperty
|
||||
|
||||
@get:InputFile
|
||||
abstract val configFile: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val executable: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputJar: RegularFileProperty
|
||||
|
||||
override fun init() {
|
||||
outputJar.convention(defaultOutput())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val out = outputJar.file
|
||||
ensureParentExists(out)
|
||||
ensureDeleted(out)
|
||||
|
||||
val config = gson.fromJson<McpConfig>(configFile)
|
||||
|
||||
val argList = config.functions.rename.args.map {
|
||||
when (it) {
|
||||
"{input}" -> inputJar.file.absolutePath
|
||||
"{output}" -> outputJar.file.absolutePath
|
||||
"{mappings}" -> mappings.file.absolutePath
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
|
||||
val jvmArgs = config.functions.rename.jvmargs ?: listOf()
|
||||
|
||||
val logFile = layout.cache.resolve(paperTaskOutput("log"))
|
||||
logFile.delete()
|
||||
|
||||
runJar(executable.file, layout.cache, logFile, jvmArgs = jvmArgs, args = *argList.toTypedArray())
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ import org.gradle.api.tasks.InputFile
|
|||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class DecompileVanillaJar : BaseTask() {
|
||||
abstract class SpigotDecompileJar : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
|
@ -27,7 +27,6 @@ import io.papermc.paperweight.util.Constants.paperTaskOutput
|
|||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import java.nio.file.Paths
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
|
@ -35,7 +34,7 @@ import org.gradle.api.tasks.InputFile
|
|||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class RemapVanillaJarSpigot : BaseTask() {
|
||||
abstract class SpigotRemapJar : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
||||
|
@ -92,10 +91,8 @@ abstract class RemapVanillaJarSpigot : BaseTask() {
|
|||
logFile.delete()
|
||||
runJar(
|
||||
specialSource2Jar,
|
||||
// Paths.get("/home/demonwav/IdeaProjects/SpecialSource2/build/libs/SpecialSource2-2.0.0-PW-SNAPSHOT-all.jar"),
|
||||
workingDir = work,
|
||||
logFile = logFile,
|
||||
// jvmArgs = listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"),
|
||||
args = *doReplacements(classMapCommand.get(), inputJarPath, classMappingPath, classJarPath) {
|
||||
// ignore excludes, we actually want to map every class
|
||||
it != "-e"
|
||||
|
@ -109,11 +106,9 @@ abstract class RemapVanillaJarSpigot : BaseTask() {
|
|||
val logFile = layout.cache.resolve(paperTaskOutput("member.log"))
|
||||
logFile.delete()
|
||||
runJar(
|
||||
// Paths.get("/home/demonwav/IdeaProjects/SpecialSource2/build/libs/SpecialSource2-2.0.0-PW-SNAPSHOT-all.jar"),
|
||||
specialSource2Jar,
|
||||
workingDir = work,
|
||||
logFile = logFile,
|
||||
// jvmArgs = listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"),
|
||||
args = *doReplacements(memberMapCommand.get(), classJarPath, memberMappingsPath, membersJarPath)
|
||||
)
|
||||
} catch (e: Exception) {
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.Classpath
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class WriteLibrariesFile : BaseTask() {
|
||||
|
||||
@get:Classpath
|
||||
abstract val libraries: DirectoryProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
override fun init() {
|
||||
outputFile.convention(defaultOutput("txt"))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val files = libraries.file.listFiles()?.sorted()
|
||||
?: throw PaperweightException("Libraries directory does not exist")
|
||||
|
||||
outputFile.file.delete()
|
||||
outputFile.file.bufferedWriter().use { writer ->
|
||||
for (file in files) {
|
||||
if (file.name.endsWith(".jar") && !file.name.endsWith("-sources.jar")) {
|
||||
writer.appendln("-e=${file.absolutePath}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,16 +23,8 @@
|
|||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.DownloadService
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.MavenArtifact
|
||||
import io.papermc.paperweight.util.McpConfig
|
||||
import io.papermc.paperweight.util.McpJvmCommand
|
||||
import io.papermc.paperweight.util.decompile
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.fromJson
|
||||
import io.papermc.paperweight.util.gson
|
||||
import io.papermc.paperweight.util.mcinject
|
||||
import io.papermc.paperweight.util.rename
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
@ -51,7 +43,6 @@ 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.WorkQueue
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
import org.w3c.dom.Element
|
||||
|
||||
|
@ -70,85 +61,6 @@ abstract class DownloadTask : DefaultTask() {
|
|||
fun run() = downloader.get().download(url, outputFile)
|
||||
}
|
||||
|
||||
abstract class DownloadMcpFiles : DefaultTask() {
|
||||
|
||||
@get:Input
|
||||
abstract val mcpMinecraftVersion: Property<String>
|
||||
@get:Input
|
||||
abstract val mcpConfigVersion: Property<String>
|
||||
@get:Input
|
||||
abstract val mcpMappingsChannel: Property<String>
|
||||
@get:Input
|
||||
abstract val mcpMappingsVersion: Property<String>
|
||||
|
||||
@get:OutputFile
|
||||
abstract val configZip: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val mappingsZip: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
abstract val downloader: Property<DownloadService>
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val repo = listOf(Constants.FORGE_MAVEN_URL)
|
||||
|
||||
MavenArtifact(
|
||||
group = "de.oceanlabs.mcp",
|
||||
artifact = "mcp_config",
|
||||
version = mcpMinecraftVersion.get() + "-" + mcpConfigVersion.get(),
|
||||
extension = "zip"
|
||||
).downloadToFile(downloader.get(), configZip.file, repo)
|
||||
|
||||
MavenArtifact(
|
||||
group = "de.oceanlabs.mcp",
|
||||
artifact = "mcp_${mcpMappingsChannel.get()}",
|
||||
version = mcpMappingsVersion.get(),
|
||||
extension = "zip"
|
||||
).downloadToFile(downloader.get(), mappingsZip.file, repo)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DownloadMcpTools : DefaultTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val configFile: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val forgeFlowerFile: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val mcInjectorFile: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val specialSourceFile: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
abstract val downloader: Property<DownloadService>
|
||||
|
||||
@get:Inject
|
||||
abstract val workerExecutor: WorkerExecutor
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val config = gson.fromJson<McpConfig>(configFile)
|
||||
|
||||
val queue = workerExecutor.noIsolation()
|
||||
|
||||
submitDownload(queue, config.functions.decompile, forgeFlowerFile)
|
||||
submitDownload(queue, config.functions.mcinject, mcInjectorFile)
|
||||
submitDownload(queue, config.functions.rename, specialSourceFile)
|
||||
}
|
||||
|
||||
private fun submitDownload(queue: WorkQueue, cmd: McpJvmCommand, file: RegularFileProperty) {
|
||||
queue.submit(DownloadWorker::class) {
|
||||
repos.add(cmd.repo)
|
||||
artifact.set(cmd.version)
|
||||
target.set(file.file)
|
||||
downloadToDir.set(false)
|
||||
downloader.set(this@DownloadMcpTools.downloader)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DownloadMcLibraries : DefaultTask() {
|
||||
|
||||
@get:InputFile
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 io.papermc.paperweight.util.McpConfig
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.fromJson
|
||||
import io.papermc.paperweight.util.gson
|
||||
import java.io.File
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class Extract : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputFile: RegularFileProperty
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val outputDir: DirectoryProperty
|
||||
|
||||
@TaskAction
|
||||
open fun run() {
|
||||
val input = inputFile.file
|
||||
val output = outputDir.file
|
||||
if (output.exists()) {
|
||||
output.deleteRecursively()
|
||||
}
|
||||
output.mkdirs()
|
||||
fs.copy {
|
||||
from(archives.zipTree(input))
|
||||
into(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ExtractMcp : Extract() {
|
||||
|
||||
@get:OutputFile
|
||||
abstract val configFile: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val access: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val constructors: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val exceptions: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val mappings: RegularFileProperty
|
||||
@get:OutputDirectory
|
||||
abstract val patchDir: DirectoryProperty
|
||||
|
||||
override fun init() {
|
||||
configFile.convention(outputDir.file("config.json"))
|
||||
access.convention(outputDir.file("config/access.txt"))
|
||||
constructors.convention(outputDir.file("config/constructors.txt"))
|
||||
exceptions.convention(outputDir.file("config/exceptions.txt"))
|
||||
mappings.convention(outputDir.file("config/joined.tsrg"))
|
||||
patchDir.convention(outputDir.dir("config/patches/server"))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
override fun run() {
|
||||
super.run()
|
||||
|
||||
val output = outputDir.file
|
||||
val config = gson.fromJson<McpConfig>(output.resolve("config.json"))
|
||||
|
||||
// We have to know what our output file paths are at configuration time, but these could change based on the
|
||||
// config.json file.
|
||||
// So as a workaround we just rename the files the config.json file points to to our expected paths. Likely
|
||||
// is a no-op.
|
||||
|
||||
output.resolve(config.data.access).renameTo(access.file.createParent())
|
||||
output.resolve(config.data.constructors).renameTo(constructors.file.createParent())
|
||||
output.resolve(config.data.exceptions).renameTo(exceptions.file.createParent())
|
||||
output.resolve(config.data.mappings).renameTo(mappings.file.createParent())
|
||||
output.resolve(config.data.patches.server).renameTo(patchDir.file.createParent())
|
||||
}
|
||||
|
||||
private fun File.createParent(): File {
|
||||
val par = this.parentFile
|
||||
if (!par.exists()) {
|
||||
par.mkdirs()
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ExtractMappings : Extract() {
|
||||
|
||||
@get:OutputFile
|
||||
abstract val fieldsCsv: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val methodsCsv: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val paramsCsv: RegularFileProperty
|
||||
|
||||
override fun init() {
|
||||
fieldsCsv.convention(outputDir.file("fields.csv"))
|
||||
methodsCsv.convention(outputDir.file("methods.csv"))
|
||||
paramsCsv.convention(outputDir.file("params.csv"))
|
||||
}
|
||||
}
|
|
@ -25,17 +25,14 @@ package io.papermc.paperweight.tasks
|
|||
import io.papermc.paperweight.util.defaultOutput
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.zip
|
||||
import org.gradle.api.file.DuplicatesStrategy
|
||||
import org.gradle.api.file.RegularFile
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class Filter : BaseTask() {
|
||||
abstract class FilterJar : BaseTask() {
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputJar: RegularFileProperty
|
||||
|
@ -57,7 +54,7 @@ abstract class Filter : BaseTask() {
|
|||
|
||||
fs.copy {
|
||||
from(archives.zipTree(inputJar)) {
|
||||
for (inc in this@Filter.includes.get()) {
|
||||
for (inc in this@FilterJar.includes.get()) {
|
||||
include(inc)
|
||||
}
|
||||
}
|
||||
|
@ -68,35 +65,3 @@ abstract class Filter : BaseTask() {
|
|||
target.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
abstract class Merge : BaseTask() {
|
||||
@get:InputFiles
|
||||
abstract val inputJars: ListProperty<RegularFile>
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputJar: RegularFileProperty
|
||||
|
||||
override fun init() {
|
||||
outputJar.convention(defaultOutput())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val out = outputJar.file
|
||||
val target = out.resolveSibling("${out.name}.dir")
|
||||
target.mkdirs()
|
||||
|
||||
fs.copy {
|
||||
for (file in inputJars.get()) {
|
||||
from(archives.zipTree(file))
|
||||
}
|
||||
into(target)
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
zip(target, outputJar)
|
||||
target.deleteRecursively()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -40,14 +40,6 @@ class PatchApplier(
|
|||
|
||||
private val remappedBaseTag: String = "remapped-base"
|
||||
|
||||
// fun initRepo() {
|
||||
// println("Initializing patch remap repo")
|
||||
// git("branch", unmappedBranch).executeSilently()
|
||||
// git("checkout", "--orphan", remappedBranch).executeSilently()
|
||||
// git("commit", "-m", "Initial", "--author=Initial <auto@mated.null>", "--allow-empty").executeSilently()
|
||||
// git("checkout", unmappedBranch).executeSilently()
|
||||
// }
|
||||
|
||||
fun checkoutRemapped() {
|
||||
println("Switching to $remappedBranch without losing changes")
|
||||
git("symbolic-ref", "HEAD", "refs/heads/$remappedBranch").executeSilently()
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
|
||||
package io.papermc.paperweight.tasks.patchremap
|
||||
|
||||
import io.papermc.paperweight.tasks.sourceremap.ConstructorsData
|
||||
import io.papermc.paperweight.tasks.sourceremap.ParamNames
|
||||
import io.papermc.paperweight.tasks.sourceremap.SrgParameterRemapper
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
|
@ -34,8 +31,6 @@ import org.cadixdev.mercury.remapper.MercuryRemapper
|
|||
class PatchSourceRemapWorker(
|
||||
mappings: MappingSet,
|
||||
classpath: Collection<Path>,
|
||||
paramNames: ParamNames,
|
||||
constructorsData: ConstructorsData,
|
||||
private val inputDir: Path,
|
||||
private val outputDir: Path
|
||||
) {
|
||||
|
@ -46,8 +41,7 @@ class PatchSourceRemapWorker(
|
|||
merc.classPath.addAll(classpath)
|
||||
|
||||
merc.processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappings),
|
||||
SrgParameterRemapper(mappings, constructorsData, paramNames)
|
||||
MercuryRemapper.create(mappings)
|
||||
))
|
||||
|
||||
merc.isGracefulClasspathChecks = true
|
||||
|
|
|
@ -22,17 +22,13 @@
|
|||
|
||||
package io.papermc.paperweight.tasks.patchremap
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.tasks.BaseTask
|
||||
import io.papermc.paperweight.tasks.sourceremap.parseConstructors
|
||||
import io.papermc.paperweight.tasks.sourceremap.parseParamNames
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.util.McDev
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.path
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFile
|
||||
|
@ -51,8 +47,6 @@ abstract class RemapPatches : BaseTask() {
|
|||
|
||||
@get:InputDirectory
|
||||
abstract val inputPatchDir: DirectoryProperty
|
||||
// @get:InputFile
|
||||
// abstract val sourceJar: RegularFileProperty
|
||||
@get:InputDirectory
|
||||
abstract val apiPatchDir: DirectoryProperty
|
||||
|
||||
|
@ -74,12 +68,6 @@ abstract class RemapPatches : BaseTask() {
|
|||
@get:InputFile
|
||||
abstract val libraryImports: RegularFileProperty
|
||||
|
||||
// For parameter name remapping
|
||||
@get:InputFile
|
||||
abstract val parameterNames: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val constructors: RegularFileProperty
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val outputPatchDir: DirectoryProperty
|
||||
|
||||
|
@ -101,10 +89,6 @@ abstract class RemapPatches : BaseTask() {
|
|||
|
||||
patches.sort()
|
||||
|
||||
// Setup param remapping
|
||||
val constructorsData = parseConstructors(constructors.file)
|
||||
val paramMap = parseParamNames(parameterNames.file)
|
||||
|
||||
val mappings = MappingFormats.TSRG.createReader(mappingsFile.path).use { it.read() }
|
||||
|
||||
// This should pull in any libraries needed for type bindings
|
||||
|
@ -130,8 +114,6 @@ abstract class RemapPatches : BaseTask() {
|
|||
PatchSourceRemapWorker(
|
||||
mappings,
|
||||
listOf(*classpathFiles.toTypedArray(), tempApiDir.resolve("src/main/java")).map { it.toPath() },
|
||||
paramMap,
|
||||
constructorsData,
|
||||
sourceInputDir.toPath(),
|
||||
tempOutputDir.toPath()
|
||||
).let { remapper ->
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.sourceremap
|
||||
|
||||
import org.cadixdev.mercury.RewriteContext
|
||||
import org.eclipse.jdt.core.dom.ASTVisitor
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding
|
||||
import org.eclipse.jdt.core.dom.IVariableBinding
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
import org.eclipse.jdt.core.dom.SimpleName
|
||||
import org.eclipse.jdt.core.dom.VariableDeclaration
|
||||
|
||||
abstract class AbstractParameterVisitor(protected val context: RewriteContext) : ASTVisitor() {
|
||||
|
||||
override fun visit(node: SimpleName): Boolean {
|
||||
val binding = node.resolveBinding() as? IVariableBinding ?: return false
|
||||
if (!binding.isParameter) {
|
||||
return false
|
||||
}
|
||||
|
||||
val variableDecl = context.compilationUnit.findDeclaringNode(binding.variableDeclaration) as VariableDeclaration
|
||||
|
||||
val method = binding.declaringMethod
|
||||
val methodDecl = context.compilationUnit.findDeclaringNode(method) as? MethodDeclaration ?: return false
|
||||
|
||||
if (method.isConstructor) {
|
||||
handleConstructor(node, methodDecl, method, variableDecl)
|
||||
} else {
|
||||
handleMethod(node, methodDecl, method, variableDecl)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
abstract fun handleMethod(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
)
|
||||
|
||||
abstract fun handleConstructor(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
)
|
||||
|
||||
fun getParameterIndex(methodDecl: MethodDeclaration, decl: VariableDeclaration): Int {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val params = methodDecl.parameters() as List<VariableDeclaration>
|
||||
return params.indexOfFirst { it === decl }
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.sourceremap
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import org.cadixdev.mercury.RewriteContext
|
||||
import org.cadixdev.mercury.SourceProcessor
|
||||
import org.cadixdev.mercury.SourceRewriter
|
||||
import org.cadixdev.mercury.util.BombeBindings
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
import org.eclipse.jdt.core.dom.SimpleName
|
||||
import org.eclipse.jdt.core.dom.VariableDeclaration
|
||||
|
||||
class PatchParameterRemapper(
|
||||
private val paramNames: ParamNames,
|
||||
private val constructorsData: ConstructorsData
|
||||
) : SourceRewriter {
|
||||
override fun getFlags(): Int = SourceProcessor.FLAG_RESOLVE_BINDINGS
|
||||
|
||||
override fun rewrite(context: RewriteContext) {
|
||||
context.compilationUnit.accept(PatchParameterVisitor(context, paramNames, constructorsData))
|
||||
}
|
||||
}
|
||||
|
||||
class PatchParameterVisitor(
|
||||
context: RewriteContext,
|
||||
private val paramNames: ParamNames,
|
||||
private val constructorsData: ConstructorsData
|
||||
) : AbstractParameterVisitor(context) {
|
||||
|
||||
override fun handleMethod(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
) {
|
||||
val paramNames = paramNames[methodDecl.name.identifier] ?: return
|
||||
val params = methodDecl.parameters()
|
||||
|
||||
if (paramNames.size != params.size) {
|
||||
throw PaperweightException("Invalid parameter length; expected ${paramNames.size}, actual ${params.size} " +
|
||||
"for method ${methodDecl.name.identifier}")
|
||||
}
|
||||
|
||||
val index = getParameterIndex(methodDecl, variableDecl)
|
||||
val newName = paramNames[index] ?: return
|
||||
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, newName, null)
|
||||
}
|
||||
|
||||
override fun handleConstructor(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
) {
|
||||
val className = method.declaringClass.binaryName.replace('.', '/')
|
||||
val descriptor = BombeBindings.convertSignature(method).descriptor
|
||||
|
||||
val constructorNode = constructorsData.findConstructorNode(className, descriptor) ?: return
|
||||
val paramNames = paramNames["const_${constructorNode.id}"] ?: return
|
||||
val params = methodDecl.parameters()
|
||||
|
||||
if (paramNames.size != params.size) {
|
||||
throw PaperweightException("Invalid parameter length; expected ${paramNames.size}, actual ${params.size} " +
|
||||
"for constructor $className $descriptor")
|
||||
}
|
||||
|
||||
val index = getParameterIndex(methodDecl, variableDecl)
|
||||
val newName = paramNames[index]
|
||||
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, newName, null)
|
||||
}
|
||||
}
|
|
@ -32,7 +32,6 @@ import javax.inject.Inject
|
|||
import net.fabricmc.lorenztiny.TinyMappingFormat
|
||||
import org.cadixdev.at.AccessTransformSet
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.cadixdev.mercury.Mercury
|
||||
import org.cadixdev.mercury.at.AccessTransformerRewriter
|
||||
import org.cadixdev.mercury.extra.AccessAnalyzerProcessor
|
||||
|
@ -61,8 +60,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
@get:InputDirectory
|
||||
abstract val spigotDeps: DirectoryProperty
|
||||
|
||||
@get:InputFile
|
||||
abstract val constructors: RegularFileProperty
|
||||
@get:InputDirectory
|
||||
abstract val spigotServerDir: DirectoryProperty
|
||||
@get:InputDirectory
|
||||
|
@ -96,7 +93,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
classpath.addAll(spigotDeps.get().asFileTree.filter { it.name.endsWith(".jar") && !it.name.endsWith("-sources.jar") }.files)
|
||||
|
||||
mappings.set(this@RemapSources.mappings.file)
|
||||
constructors.set(this@RemapSources.constructors.file)
|
||||
inputDir.set(srcDir)
|
||||
|
||||
outputDir.set(rootDir)
|
||||
|
@ -112,10 +108,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
val mappingSet = TinyMappingFormat.STANDARD.read(parameters.mappings.path, Constants.SPIGOT_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
val processAt = AccessTransformSet.create()
|
||||
|
||||
val constructorsData = parseConstructors(parameters.constructors.file)
|
||||
|
||||
val paramNames: ParamNames = newParamNames()
|
||||
|
||||
// Remap any references Spigot maps to SRG
|
||||
Mercury().let { merc ->
|
||||
merc.classPath.addAll(parameters.classpath.get().map { it.toPath() })
|
||||
|
@ -128,22 +120,19 @@ abstract class RemapSources : ZippedTask() {
|
|||
merc.processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappingSet),
|
||||
BridgeMethodRewriter.create(),
|
||||
AccessTransformerRewriter.create(processAt),
|
||||
SrgParameterRemapper(mappingSet, constructorsData, paramNames)
|
||||
AccessTransformerRewriter.create(processAt)
|
||||
))
|
||||
|
||||
merc.rewrite(parameters.inputDir.path, parameters.outputDir.path)
|
||||
}
|
||||
|
||||
AccessTransformFormats.FML.write(parameters.generatedAtOutput.path, processAt)
|
||||
writeParamNames(paramNames, parameters.paramNamesOutput.file)
|
||||
}
|
||||
}
|
||||
|
||||
interface RemapParams : WorkParameters {
|
||||
val classpath: ListProperty<File>
|
||||
val mappings: RegularFileProperty
|
||||
val constructors: RegularFileProperty
|
||||
val inputDir: RegularFileProperty
|
||||
|
||||
val generatedAtOutput: RegularFileProperty
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.sourceremap
|
||||
|
||||
import org.cadixdev.bombe.type.MethodDescriptor
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.mercury.RewriteContext
|
||||
import org.cadixdev.mercury.SourceProcessor
|
||||
import org.cadixdev.mercury.SourceRewriter
|
||||
import org.cadixdev.mercury.util.BombeBindings
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
import org.eclipse.jdt.core.dom.Modifier
|
||||
import org.eclipse.jdt.core.dom.SimpleName
|
||||
import org.eclipse.jdt.core.dom.VariableDeclaration
|
||||
|
||||
class SrgParameterRemapper(
|
||||
private val mappings: MappingSet,
|
||||
private val constructorsData: ConstructorsData,
|
||||
private val parameterNames: ParamNames? = null
|
||||
) : SourceRewriter {
|
||||
|
||||
override fun getFlags(): Int = SourceProcessor.FLAG_RESOLVE_BINDINGS
|
||||
|
||||
override fun rewrite(context: RewriteContext) {
|
||||
context.compilationUnit.accept(SrgParameterVisitor(context, mappings, constructorsData, parameterNames))
|
||||
}
|
||||
}
|
||||
|
||||
class SrgParameterVisitor(
|
||||
context: RewriteContext,
|
||||
private val mappings: MappingSet,
|
||||
private val constructorsData: ConstructorsData,
|
||||
private val paramNames: ParamNames?
|
||||
) : AbstractParameterVisitor(context) {
|
||||
|
||||
companion object {
|
||||
private val MATCHER = Regex("func_(\\d+)_.*")
|
||||
}
|
||||
|
||||
override fun handleMethod(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
) {
|
||||
val methodName = mappings.getClassMapping(method.declaringClass.binaryName)
|
||||
.flatMap { it.getMethodMapping(BombeBindings.convertSignature(method)) }
|
||||
.map { it.deobfuscatedName }
|
||||
.orElse(null) ?: return
|
||||
|
||||
val match = MATCHER.matchEntire(methodName) ?: return
|
||||
val isStatic = method.modifiers and Modifier.STATIC != 0
|
||||
|
||||
var index = getParameterIndex(methodDecl, variableDecl)
|
||||
if (index == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
recordName(methodName, method, node, index)
|
||||
|
||||
if (!isStatic) {
|
||||
index++
|
||||
}
|
||||
|
||||
val paramName = "p_${match.groupValues[1]}_${index}_"
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, paramName, null)
|
||||
}
|
||||
|
||||
override fun handleConstructor(
|
||||
node: SimpleName,
|
||||
methodDecl: MethodDeclaration,
|
||||
method: IMethodBinding,
|
||||
variableDecl: VariableDeclaration
|
||||
) {
|
||||
val binaryName = method.declaringClass.binaryName
|
||||
val classMapping = mappings.getClassMapping(binaryName)
|
||||
val className = classMapping
|
||||
.map { it.fullDeobfuscatedName }
|
||||
.orElse(binaryName)
|
||||
|
||||
val descriptor = BombeBindings.convertSignature(method).descriptor
|
||||
val constructorNode = constructorsData.findConstructorNode(className, descriptor) ?: return
|
||||
|
||||
val id = constructorNode.id
|
||||
|
||||
var index = getParameterIndex(methodDecl, variableDecl)
|
||||
if (index == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
recordName("const_$id", method, node, index)
|
||||
|
||||
// Constructors are never static
|
||||
index++
|
||||
|
||||
val paramName = "p_i${id}_${index}_"
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, paramName, null)
|
||||
}
|
||||
|
||||
private fun recordName(
|
||||
methodName: String,
|
||||
method: IMethodBinding,
|
||||
node: SimpleName,
|
||||
index: Int
|
||||
) {
|
||||
paramNames?.let { map ->
|
||||
val paramCount = method.parameterTypes.size
|
||||
map.computeIfAbsent(methodName) { arrayOfNulls(paramCount) }[index] = node.identifier
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ConstructorsData.findConstructorNode(className: String, desc: MethodDescriptor): ConstructorNode? {
|
||||
val constructorNodes = constructors[className] ?: return null
|
||||
|
||||
val descriptorText = desc.toString()
|
||||
return constructorNodes.firstOrNull { constructorNode ->
|
||||
constructorNode.descriptor == descriptorText
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.sourceremap
|
||||
|
||||
import java.io.File
|
||||
|
||||
data class ConstructorsData(val constructors: Map<String, List<ConstructorNode>>)
|
||||
|
||||
data class ConstructorNode(
|
||||
val id: Int,
|
||||
val descriptor: String
|
||||
)
|
||||
|
||||
fun parseConstructors(constructors: File): ConstructorsData {
|
||||
val constructorMap = hashMapOf<String, MutableList<ConstructorNode>>()
|
||||
|
||||
constructors.useLines { lines ->
|
||||
lines.forEach { line ->
|
||||
val parts = line.split(' ')
|
||||
constructorMap.compute(parts[1]) { _, v ->
|
||||
val node = ConstructorNode(parts[0].toInt(), parts[2])
|
||||
if (v == null) {
|
||||
return@compute mutableListOf(node)
|
||||
} else {
|
||||
v += node
|
||||
return@compute v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (list in constructorMap.values) {
|
||||
// Put bigger numbers first
|
||||
// Old constructor entries are still present, just with smaller numbers. So we don't want to grab an older
|
||||
// entry
|
||||
list.reverse()
|
||||
}
|
||||
|
||||
return ConstructorsData(constructorMap)
|
||||
}
|
||||
|
||||
typealias ParamNames = MutableMap<String, Array<String?>>
|
||||
fun newParamNames(): ParamNames = mutableMapOf()
|
||||
|
||||
fun writeParamNames(names: ParamNames, file: File) {
|
||||
file.bufferedWriter().use { writer ->
|
||||
for ((desc, params) in names.entries) {
|
||||
writer.append(desc).append(' ')
|
||||
for (i in params.indices) {
|
||||
writer.append(i.toString()).append(' ').append(params[i])
|
||||
if (i != params.lastIndex) {
|
||||
writer.append(' ')
|
||||
}
|
||||
}
|
||||
writer.newLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun parseParamNames(file: File): ParamNames {
|
||||
val paramNames: MutableMap<String, Array<String?>> = mutableMapOf()
|
||||
file.useLines { lines ->
|
||||
for (line in lines) {
|
||||
val parts = line.split(' ')
|
||||
val params = parts.asSequence().drop(1).chunked(2).associate { it[0].toInt() to it[1] }
|
||||
paramNames[parts.first()] = Array(params.size) { params.getValue(it) }
|
||||
}
|
||||
}
|
||||
return paramNames
|
||||
}
|
|
@ -27,59 +27,42 @@ import org.gradle.api.Task
|
|||
object Constants {
|
||||
const val EXTENSION = "paperweight"
|
||||
|
||||
const val FORGE_MAVEN_URL = "https://files.minecraftforge.net/maven"
|
||||
const val FORGE_MAVEN_URL = "https://files.minecraftforge.net/maven/"
|
||||
const val FABRIC_MAVEN_URL = "https://maven.fabricmc.net/"
|
||||
const val MC_LIBRARY_URL = "https://libraries.minecraft.net/"
|
||||
|
||||
const val MC_MANIFEST_URL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"
|
||||
|
||||
const val YARN_CONFIG = "yarn"
|
||||
const val PARAM_MAPPINGS_CONFIG = "paramMappings"
|
||||
const val REMAPPER_CONFIG = "remapper"
|
||||
const val DECOMPILER_CONFIG = "decompiler"
|
||||
|
||||
const val CACHE_PATH = "caches"
|
||||
private const val PAPER_PATH = "paperweight"
|
||||
|
||||
private const val JARS_PATH = "$PAPER_PATH/jars"
|
||||
const val MINECRAFT_JARS_PATH = "$JARS_PATH/minecraft"
|
||||
const val MCP_TOOLS_PATH = "$JARS_PATH/tools"
|
||||
const val MCP_ZIPS_PATH = "$JARS_PATH/mcp"
|
||||
const val SPIGOT_JARS_PATH = "$JARS_PATH/spigot"
|
||||
|
||||
const val MCP_DATA_DIR = "mcp/data"
|
||||
const val MCP_MAPPINGS_DIR = "mcp/mappings"
|
||||
const val SERVER_MAPPINGS = "mcp/server_mappings.txt"
|
||||
const val SRG_DIR = "$MCP_MAPPINGS_DIR/srgs"
|
||||
private const val MAPPINGS_DIR = "$PAPER_PATH/mappings"
|
||||
const val SERVER_MAPPINGS = "$MAPPINGS_DIR/server_mappings.txt"
|
||||
const val MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/official-mojang+yarn.tiny"
|
||||
const val SPIGOT_MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yarn.tiny"
|
||||
const val PATCHED_SPIGOT_MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yarn-patch.tiny"
|
||||
|
||||
const val OBF_NAMESPACE = "official"
|
||||
const val SPIGOT_NAMESPACE = "spigot"
|
||||
const val DEOBF_NAMESPACE = "mojang+yarn"
|
||||
|
||||
const val MCP_CONFIG_JSON = "$MCP_DATA_DIR/config.json"
|
||||
|
||||
const val PAPER_FIELDS_CSV = "$MCP_MAPPINGS_DIR/paper_fields.csv"
|
||||
const val PAPER_METHODS_CSV = "$MCP_MAPPINGS_DIR/paper_methods.csv"
|
||||
const val PAPER_PARAMS_CSV = "$MCP_MAPPINGS_DIR/paper_params.csv"
|
||||
|
||||
const val NOTCH_TO_SRG = "$SRG_DIR/notch-srg.tsrg"
|
||||
const val NOTCH_TO_MCP = "$SRG_DIR/notch-mcp.tsrg"
|
||||
const val NOTCH_TO_SPIGOT = "$SRG_DIR/notch-spigot.tsrg"
|
||||
|
||||
const val MCP_TO_NOTCH = "$SRG_DIR/mcp-notch.tsrg"
|
||||
const val MCP_TO_SRG = "$SRG_DIR/mcp-srg.tsrg"
|
||||
const val MCP_TO_SPIGOT = "$SRG_DIR/mcp-spigot.tsrg"
|
||||
|
||||
const val SRG_TO_NOTCH = "$SRG_DIR/srg-notch.tsrg"
|
||||
const val SRG_TO_MCP = "$SRG_DIR/srg-mcp.tsrg"
|
||||
const val SRG_TO_SPIGOT = "$SRG_DIR/srg-spigot.tsrg"
|
||||
|
||||
const val SPIGOT_TO_NOTCH = "$SRG_DIR/spigot-notch.tsrg"
|
||||
const val SPIGOT_TO_SRG = "$SRG_DIR/spigot-srg.tsrg"
|
||||
const val SPIGOT_TO_MCP = "$SRG_DIR/spigot-mcp.tsrg"
|
||||
|
||||
const val MC_MANIFEST = "jsons/McManifest.json"
|
||||
const val VERSION_JSON = "jsons/McVersion.json"
|
||||
const val MC_LIBRARIES = "jsons/McLibraries.txt"
|
||||
private const val DATA_PATH = "$PAPER_PATH/data"
|
||||
const val MC_MANIFEST = "$DATA_PATH/McManifest.json"
|
||||
const val VERSION_JSON = "$DATA_PATH/McVersion.json"
|
||||
const val MC_LIBRARIES = "$DATA_PATH/McLibraries.txt"
|
||||
|
||||
private const val TASK_CACHE = "$PAPER_PATH/taskCache"
|
||||
|
||||
const val FINAL_REMAPPED_JAR = "$TASK_CACHE/minecraft.jar"
|
||||
|
||||
fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext)
|
||||
fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext"
|
||||
}
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
|
||||
typealias FunctionMap = Map<String, McpJvmCommand>
|
||||
val FunctionMap.decompile: McpJvmCommand
|
||||
get() = getValue("decompile")
|
||||
val FunctionMap.mcinject: McpJvmCommand
|
||||
get() = getValue("mcinject")
|
||||
val FunctionMap.rename: McpJvmCommand
|
||||
get() = getValue("rename")
|
||||
|
||||
data class McpConfig(
|
||||
val spec: Int,
|
||||
val version: String,
|
||||
val data: McpConfigData,
|
||||
val steps: Map<String, List<Map<String, String>>>,
|
||||
val functions: Map<String, McpJvmCommand>
|
||||
)
|
||||
|
||||
data class McpConfigData(
|
||||
val access: String,
|
||||
val constructors: String,
|
||||
val exceptions: String,
|
||||
val mappings: String,
|
||||
val inject: String,
|
||||
val statics: String,
|
||||
val patches: McpConfigDataPatches
|
||||
)
|
||||
|
||||
data class McpConfigDataPatches(
|
||||
val client: String,
|
||||
val joined: String,
|
||||
val server: String
|
||||
)
|
||||
|
||||
data class McpJvmCommand(
|
||||
val version: String,
|
||||
val args: List<String>,
|
||||
val repo: String,
|
||||
val jvmargs: List<String>?
|
||||
)
|
|
@ -25,7 +25,6 @@ package io.papermc.paperweight.util
|
|||
import io.papermc.paperweight.PaperweightException
|
||||
import java.io.OutputStream
|
||||
import org.gradle.internal.jvm.Jvm
|
||||
import org.gradle.process.ExecOperations
|
||||
|
||||
fun runJar(jar: Any, workingDir: Any, logFile: Any?, jvmArgs: List<String> = listOf(), vararg args: String) {
|
||||
val jarFile = jar.convertToFile()
|
|
@ -24,9 +24,6 @@ package io.papermc.paperweight.util
|
|||
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import com.google.gson.Gson
|
||||
import com.opencsv.CSVParserBuilder
|
||||
import com.opencsv.CSVReader
|
||||
import com.opencsv.CSVReaderBuilder
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.ext.PaperweightExtension
|
||||
import io.papermc.paperweight.tasks.BaseTask
|
||||
|
@ -40,8 +37,6 @@ import java.nio.file.Path
|
|||
import java.util.Optional
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.lorenz.io.TextMappingFormat
|
||||
import org.cadixdev.lorenz.model.ClassMapping
|
||||
import org.cadixdev.lorenz.model.MemberMapping
|
||||
import org.gradle.api.Project
|
||||
|
@ -64,10 +59,8 @@ val Project.ext: PaperweightExtension
|
|||
val ProjectLayout.cache: File
|
||||
get() = projectDirectory.file(".gradle/${Constants.CACHE_PATH}").asFile
|
||||
|
||||
fun writeMappings(format: TextMappingFormat, vararg mappings: Pair<MappingSet, File>) {
|
||||
for ((set, file) in mappings) {
|
||||
format.createWriter(file.toPath()).use { it.write(set) }
|
||||
}
|
||||
fun commentRegex(): Regex {
|
||||
return Regex("\\s*#.*")
|
||||
}
|
||||
|
||||
fun redirect(input: InputStream, out: OutputStream): Thread {
|
||||
|
@ -88,10 +81,6 @@ object UselessOutputStream : OutputStream() {
|
|||
}
|
||||
}
|
||||
|
||||
fun getCsvReader(file: File): CSVReader = CSVReaderBuilder(file.bufferedReader())
|
||||
.withCSVParser(CSVParserBuilder().withStrictQuotes(false).build())
|
||||
.build()
|
||||
|
||||
fun Any.convertToFile(): File {
|
||||
return when (this) {
|
||||
is File -> this
|
||||
|
|
Loading…
Reference in a new issue