initialize tasks earlier to allow modifications
All checks were successful
Publish to snapshot maven / build (push) Successful in 25s
All checks were successful
Publish to snapshot maven / build (push) Successful in 25s
This commit is contained in:
parent
dfb3aa47c5
commit
a415bb5b81
|
@ -7,7 +7,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.frogmc"
|
group = "dev.frogmc"
|
||||||
version = "0.0.1-alpha.14"
|
version = "0.0.1-alpha.15"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
|
|
|
@ -1,14 +1,40 @@
|
||||||
package dev.frogmc.phytotelma
|
package dev.frogmc.phytotelma
|
||||||
|
|
||||||
|
import com.electronwill.nightconfig.core.file.FileNotFoundAction
|
||||||
|
import com.electronwill.nightconfig.toml.TomlParser
|
||||||
|
import dev.frogmc.phytotelma.accesswidener.AccessWidener
|
||||||
|
import dev.frogmc.phytotelma.build.PhytotelmaBuildTask
|
||||||
|
import dev.frogmc.phytotelma.common.Env
|
||||||
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtension
|
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtension
|
||||||
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtensionImpl
|
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtensionImpl
|
||||||
|
import dev.frogmc.phytotelma.mappings.renameDstNamespace
|
||||||
|
import dev.frogmc.phytotelma.run.AssetDownloader
|
||||||
|
import dev.frogmc.phytotelma.run.RunConfigGenerator
|
||||||
|
import dev.frogmc.phytotelma.run.task.RunGameTask
|
||||||
|
import dev.frogmc.phytotelma.vineflower.FrogJavadocProvider
|
||||||
|
import dev.frogmc.thyroxine.Thyroxine
|
||||||
|
import dev.frogmc.thyroxine.api.Mapper
|
||||||
|
import dev.frogmc.thyroxine.api.data.MappingBundle
|
||||||
|
import dev.frogmc.thyroxine.provider.MojmapProvider
|
||||||
|
import net.fabricmc.fernflower.api.IFabricJavadocProvider
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.plugins.JavaBasePlugin
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
import org.gradle.api.plugins.JavaPlugin
|
||||||
|
import org.gradle.api.tasks.Delete
|
||||||
import org.gradle.configurationcache.extensions.capitalized
|
import org.gradle.configurationcache.extensions.capitalized
|
||||||
|
import org.jetbrains.java.decompiler.main.Fernflower
|
||||||
|
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger
|
||||||
|
import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver
|
||||||
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.io.PrintStream
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
import java.nio.file.FileSystems
|
||||||
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.createDirectories
|
import java.nio.file.StandardCopyOption
|
||||||
|
import kotlin.io.path.*
|
||||||
|
|
||||||
|
|
||||||
class PhytotelmaPlugin : Plugin<Project> {
|
class PhytotelmaPlugin : Plugin<Project> {
|
||||||
|
@ -88,6 +114,218 @@ class PhytotelmaPlugin : Plugin<Project> {
|
||||||
it.isCanBeConsumed = false
|
it.isCanBeConsumed = false
|
||||||
it.isTransitive = false
|
it.isTransitive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupTasks(project)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupTasks(project: Project) {
|
||||||
|
project.tasks.register("genSources") { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.actions.add {
|
||||||
|
val projectData = ProjectStorage.get(it.project)
|
||||||
|
val fileName = projectData.remappedGameJarPath!!.fileName.toString()
|
||||||
|
val output =
|
||||||
|
projectData.remappedGameJarPath!!.resolveSibling(
|
||||||
|
fileName.substring(
|
||||||
|
0,
|
||||||
|
fileName.lastIndexOf("-")
|
||||||
|
) + "-sources.jar"
|
||||||
|
)
|
||||||
|
if (output.exists()) {
|
||||||
|
println("Output $output already exists, deleting!")
|
||||||
|
output.deleteExisting()
|
||||||
|
}
|
||||||
|
val options = mutableMapOf<String, Any>()
|
||||||
|
println("Preparing Parchment...")
|
||||||
|
val javadocs = ProjectStorage.get(project).mappings!!
|
||||||
|
options[IFabricJavadocProvider.PROPERTY_NAME] =
|
||||||
|
FrogJavadocProvider(javadocs.get(ProjectStorage.get(project).targetNamespace))
|
||||||
|
|
||||||
|
println("Decompiling...")
|
||||||
|
val logger = PrintStreamLogger(PrintStream(System.out))
|
||||||
|
options.putAll(
|
||||||
|
mapOf(
|
||||||
|
IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES to "1",
|
||||||
|
IFernflowerPreferences.BYTECODE_SOURCE_MAPPING to "1",
|
||||||
|
IFernflowerPreferences.REMOVE_SYNTHETIC to "1",
|
||||||
|
IFernflowerPreferences.LOG_LEVEL to "error",
|
||||||
|
IFernflowerPreferences.THREADS to Runtime.getRuntime().availableProcessors().toString(),
|
||||||
|
IFernflowerPreferences.INDENT_STRING to "\t"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val decomp = Fernflower(
|
||||||
|
SingleFileSaver(output.toFile()),
|
||||||
|
options, logger
|
||||||
|
)
|
||||||
|
decomp.addSource(projectData.remappedGameJarPath!!.toFile())
|
||||||
|
|
||||||
|
decomp.decompileContext()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register(Constants.GEN_RUN_CONFIGS_TASK) { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.doFirst {
|
||||||
|
RunConfigGenerator.generate(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register(Constants.RUN_CLIENT_TASK, RunGameTask::class.java, Env.CLIENT)
|
||||||
|
project.tasks.register(Constants.RUNT_SERVER_TASK, RunGameTask::class.java, Env.SERVER)
|
||||||
|
|
||||||
|
project.tasks.register(Constants.DOWNLOAD_ASSETS_TASK) { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.doFirst {
|
||||||
|
AssetDownloader.download(it.project, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val buildTask = project.tasks.register(Constants.BUILD_TASK, PhytotelmaBuildTask::class.java)
|
||||||
|
project.tasks.getByName(JavaBasePlugin.BUILD_TASK_NAME).dependsOn(buildTask)
|
||||||
|
|
||||||
|
project.tasks.getByName(JavaPlugin.JAR_TASK_NAME).actions.addLast { task ->
|
||||||
|
val storage = ProjectStorage.get(project)
|
||||||
|
if (storage.targetNamespace != "mojmap") {
|
||||||
|
val mappings = MappingBundle.merge(
|
||||||
|
storage.mappings!!.reverse(), MojmapProvider.get(
|
||||||
|
storage.minecraftVersion!!,
|
||||||
|
globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt")
|
||||||
|
).orElseThrow().reverse().renameDstNamespace("mojmap")
|
||||||
|
).forNamespaces(storage.targetNamespace, "mojmap")
|
||||||
|
val parser = TomlParser()
|
||||||
|
task.outputs.files.forEach { file ->
|
||||||
|
val temp = Files.createTempFile("", file.name)
|
||||||
|
Files.copy(file.toPath(), temp, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
FileSystems.newFileSystem(temp).use { fs ->
|
||||||
|
val metadata = fs.getPath(Constants.MOD_METADATA_FILE)
|
||||||
|
parser.parse(metadata, FileNotFoundAction.READ_NOTHING)
|
||||||
|
.get<String>("frog.extensions.accesswidener")?.let { name ->
|
||||||
|
val aw = metadata.resolveSibling(name)
|
||||||
|
AccessWidener.checkAW(aw, ProjectStorage.get(project).remappedGameJarPath!!)
|
||||||
|
val mapper = Mapper(mappings) { listOf() }
|
||||||
|
val buffer = buildString {
|
||||||
|
aw.forEachLine {
|
||||||
|
if (it.contains("\\t") && !it.startsWith("#")) {
|
||||||
|
val parts = it.split("[\\t #]+".toRegex()).toMutableList()
|
||||||
|
|
||||||
|
if (parts.size > 2) {
|
||||||
|
|
||||||
|
val type = parts[1]
|
||||||
|
when (type) {
|
||||||
|
"class" -> {
|
||||||
|
parts[2] = mapper.map(parts[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
"fields" -> {
|
||||||
|
parts[3] = mapper.mapFieldName(parts[2], parts[3], parts[4])
|
||||||
|
parts[4] = mapper.mapDesc(parts[4])
|
||||||
|
parts[3] = mapper.map(parts[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
"methods" -> {
|
||||||
|
parts[3] = mapper.mapMethodName(parts[2], parts[3], parts[4])
|
||||||
|
parts[4] = mapper.mapMethodDesc(parts[4])
|
||||||
|
parts[2] = mapper.map(parts[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appendLine(parts.joinToString("\\t"))
|
||||||
|
return@forEachLine
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appendLine(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aw.writeText(buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thyroxine.remap(mappings, temp, file.toPath(), false, false)
|
||||||
|
Files.deleteIfExists(temp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register(Constants.UPDATE_AW_TASK) { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.actions.addFirst {
|
||||||
|
AccessWidener.apply(project, ProjectStorage.get(it.project).remappedGameJarPath!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK, Delete::class.java) { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.delete = setOf(ProjectStorage.get(project).localCacheDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK, Delete::class.java) { task ->
|
||||||
|
task.group = Constants.TASK_GROUP
|
||||||
|
task.delete = setOf(globalCacheDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
remapModDependencies(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun remapModDependencies(project: Project) {
|
||||||
|
val out = System.out
|
||||||
|
// Mute the output from thyroxine as there may be a lot of remapping operations here
|
||||||
|
System.setOut(PrintStream(OutputStream.nullOutputStream()))
|
||||||
|
ModConfigurations.configurations.forEach { conf ->
|
||||||
|
val artifacts = project.configurations.getByName("mod" + conf.name.capitalized())
|
||||||
|
.resolvedConfiguration.resolvedArtifacts
|
||||||
|
if (artifacts.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val target = project.configurations.create("mod" + conf.name.capitalized() + "Mapped") { c ->
|
||||||
|
c.isTransitive = false
|
||||||
|
conf.classpathNames.forEach {
|
||||||
|
project.configurations.getByName(it).extendsFrom(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val storage = ProjectStorage.get(project)
|
||||||
|
val mappings = MappingBundle.merge(
|
||||||
|
storage.mappings!!.reverse(), MojmapProvider.get(
|
||||||
|
storage.minecraftVersion!!,
|
||||||
|
globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt")
|
||||||
|
).orElseThrow().reverse().renameDstNamespace("mojmap")
|
||||||
|
).forNamespaces("mojmap", storage.targetNamespace)
|
||||||
|
val targetPath = project.layout.buildDirectory.asFile.get().toPath().resolve("remappedMods")
|
||||||
|
.resolve("dev/frogmc/phytotelma/remapped_mods")
|
||||||
|
val remappedPaths = mutableListOf<Path>()
|
||||||
|
artifacts.forEach { artifact ->
|
||||||
|
val group = artifact.moduleVersion.id.group
|
||||||
|
val name = artifact.moduleVersion.id.name
|
||||||
|
val groupname = (group + "_" + name).replace(".", "_")
|
||||||
|
val version = artifact.moduleVersion.id.version
|
||||||
|
val classifier = artifact.classifier
|
||||||
|
val remappedPath = targetPath.resolve(groupname).resolve(version)
|
||||||
|
.resolve(groupname + "-" + version + (classifier?.let { "-$it" } ?: "") + ".jar")
|
||||||
|
remappedPath.createParentDirectories()
|
||||||
|
remappedPaths.add(remappedPath)
|
||||||
|
|
||||||
|
val pom = remappedPath.resolveSibling(remappedPath.fileName.toString().removeSuffix(".jar") + ".pom")
|
||||||
|
pom.writeText(
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
|
"<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
|
||||||
|
"\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
|
||||||
|
"\t<modelVersion>4.0.0</modelVersion>\n" +
|
||||||
|
"\t<groupId>dev.frogmc.phytotelma.remapped_mods</groupId>\n" +
|
||||||
|
"\t<artifactId>$groupname</artifactId>\n" +
|
||||||
|
"\t<version>$version</version>\n" +
|
||||||
|
"</project>"
|
||||||
|
)
|
||||||
|
remappedPaths.add(pom)
|
||||||
|
|
||||||
|
Thyroxine.remap(mappings, artifact.file.toPath(), remappedPath, false, false)
|
||||||
|
|
||||||
|
project.dependencies.add(
|
||||||
|
target.name,
|
||||||
|
"dev.frogmc.phytotelma.remapped_mods:$groupname:$version" + (classifier?.let { ":$it" } ?: "")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.setOut(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -1,258 +1,25 @@
|
||||||
package dev.frogmc.phytotelma.ext
|
package dev.frogmc.phytotelma.ext
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.file.FileNotFoundAction
|
import dev.frogmc.phytotelma.Constants
|
||||||
import com.electronwill.nightconfig.toml.TomlParser
|
import dev.frogmc.phytotelma.ProjectStorage
|
||||||
import dev.frogmc.phytotelma.*
|
import dev.frogmc.phytotelma.VersionChecker
|
||||||
import dev.frogmc.phytotelma.accesswidener.AccessWidener
|
import dev.frogmc.phytotelma.accesswidener.AccessWidener
|
||||||
import dev.frogmc.phytotelma.build.PhytotelmaBuildTask
|
|
||||||
import dev.frogmc.phytotelma.common.Env
|
|
||||||
import dev.frogmc.phytotelma.mappings.renameDstNamespace
|
|
||||||
import dev.frogmc.phytotelma.run.AssetDownloader
|
import dev.frogmc.phytotelma.run.AssetDownloader
|
||||||
import dev.frogmc.phytotelma.run.RunConfigGenerator
|
import dev.frogmc.phytotelma.run.RunConfigGenerator
|
||||||
import dev.frogmc.phytotelma.run.task.RunGameTask
|
|
||||||
import dev.frogmc.phytotelma.vineflower.FrogJavadocProvider
|
|
||||||
import dev.frogmc.thyroxine.Thyroxine
|
import dev.frogmc.thyroxine.Thyroxine
|
||||||
import dev.frogmc.thyroxine.api.Mapper
|
|
||||||
import dev.frogmc.thyroxine.api.data.MappingBundle
|
|
||||||
import dev.frogmc.thyroxine.provider.MojmapProvider
|
|
||||||
import net.fabricmc.fernflower.api.IFabricJavadocProvider
|
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.model.ObjectFactory
|
import org.gradle.api.model.ObjectFactory
|
||||||
import org.gradle.api.plugins.JavaBasePlugin
|
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
|
||||||
import org.gradle.api.tasks.Delete
|
|
||||||
import org.gradle.configurationcache.extensions.capitalized
|
|
||||||
import org.jetbrains.java.decompiler.main.Fernflower
|
|
||||||
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger
|
|
||||||
import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver
|
|
||||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
|
|
||||||
import java.io.OutputStream
|
|
||||||
import java.io.PrintStream
|
|
||||||
import java.nio.file.FileSystems
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.StandardCopyOption
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.createParentDirectories
|
||||||
|
import kotlin.io.path.notExists
|
||||||
|
|
||||||
abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
||||||
private val project: Project,
|
private val project: Project,
|
||||||
private val objects: ObjectFactory
|
private val objects: ObjectFactory
|
||||||
) : PhytotelmaGradleExtension {
|
) : PhytotelmaGradleExtension {
|
||||||
|
|
||||||
private fun setupTasks() {
|
|
||||||
project.tasks.register("genSources") { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.actions.add {
|
|
||||||
val projectData = ProjectStorage.get(it.project)
|
|
||||||
val fileName = projectData.remappedGameJarPath!!.fileName.toString()
|
|
||||||
val output =
|
|
||||||
projectData.remappedGameJarPath!!.resolveSibling(
|
|
||||||
fileName.substring(
|
|
||||||
0,
|
|
||||||
fileName.lastIndexOf("-")
|
|
||||||
) + "-sources.jar"
|
|
||||||
)
|
|
||||||
if (output.exists()) {
|
|
||||||
println("Output $output already exists, deleting!")
|
|
||||||
output.deleteExisting()
|
|
||||||
}
|
|
||||||
val options = mutableMapOf<String, Any>()
|
|
||||||
println("Preparing Parchment...")
|
|
||||||
val javadocs = ProjectStorage.get(project).mappings!!
|
|
||||||
options[IFabricJavadocProvider.PROPERTY_NAME] =
|
|
||||||
FrogJavadocProvider(javadocs.get(ProjectStorage.get(project).targetNamespace))
|
|
||||||
|
|
||||||
println("Decompiling...")
|
|
||||||
val logger = PrintStreamLogger(PrintStream(System.out))
|
|
||||||
options.putAll(
|
|
||||||
mapOf(
|
|
||||||
IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES to "1",
|
|
||||||
IFernflowerPreferences.BYTECODE_SOURCE_MAPPING to "1",
|
|
||||||
IFernflowerPreferences.REMOVE_SYNTHETIC to "1",
|
|
||||||
IFernflowerPreferences.LOG_LEVEL to "error",
|
|
||||||
IFernflowerPreferences.THREADS to Runtime.getRuntime().availableProcessors().toString(),
|
|
||||||
IFernflowerPreferences.INDENT_STRING to "\t"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
val decomp = Fernflower(
|
|
||||||
SingleFileSaver(output.toFile()),
|
|
||||||
options, logger
|
|
||||||
)
|
|
||||||
decomp.addSource(projectData.remappedGameJarPath!!.toFile())
|
|
||||||
|
|
||||||
decomp.decompileContext()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.register(Constants.GEN_RUN_CONFIGS_TASK) { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.doFirst {
|
|
||||||
RunConfigGenerator.generate(project)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.register(Constants.RUN_CLIENT_TASK, RunGameTask::class.java, Env.CLIENT)
|
|
||||||
project.tasks.register(Constants.RUNT_SERVER_TASK, RunGameTask::class.java, Env.SERVER)
|
|
||||||
|
|
||||||
project.tasks.register(Constants.DOWNLOAD_ASSETS_TASK) { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.doFirst {
|
|
||||||
AssetDownloader.download(it.project, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val buildTask = project.tasks.register(Constants.BUILD_TASK, PhytotelmaBuildTask::class.java)
|
|
||||||
project.tasks.getByName(JavaBasePlugin.BUILD_TASK_NAME).dependsOn(buildTask)
|
|
||||||
|
|
||||||
project.tasks.getByName(JavaPlugin.JAR_TASK_NAME).actions.addLast { task ->
|
|
||||||
val storage = ProjectStorage.get(project)
|
|
||||||
if (storage.targetNamespace != "mojmap") {
|
|
||||||
val mappings = MappingBundle.merge(
|
|
||||||
storage.mappings!!.reverse(), MojmapProvider.get(
|
|
||||||
storage.minecraftVersion!!,
|
|
||||||
PhytotelmaPlugin.globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt")
|
|
||||||
).orElseThrow().reverse().renameDstNamespace("mojmap")
|
|
||||||
).forNamespaces(storage.targetNamespace, "mojmap")
|
|
||||||
val parser = TomlParser()
|
|
||||||
task.outputs.files.forEach { file ->
|
|
||||||
val temp = Files.createTempFile("", file.name)
|
|
||||||
Files.copy(file.toPath(), temp, StandardCopyOption.REPLACE_EXISTING)
|
|
||||||
FileSystems.newFileSystem(temp).use { fs ->
|
|
||||||
val metadata = fs.getPath(Constants.MOD_METADATA_FILE)
|
|
||||||
parser.parse(metadata, FileNotFoundAction.READ_NOTHING)
|
|
||||||
.get<String>("frog.extensions.accesswidener")?.let { name ->
|
|
||||||
val aw = metadata.resolveSibling(name)
|
|
||||||
AccessWidener.checkAW(aw, ProjectStorage.get(project).remappedGameJarPath!!)
|
|
||||||
val mapper = Mapper(mappings) { listOf() }
|
|
||||||
val buffer = buildString {
|
|
||||||
aw.forEachLine {
|
|
||||||
if (it.contains("\\t") && !it.startsWith("#")) {
|
|
||||||
val parts = it.split("[\\t #]+".toRegex()).toMutableList()
|
|
||||||
|
|
||||||
if (parts.size > 2) {
|
|
||||||
|
|
||||||
val type = parts[1]
|
|
||||||
when (type) {
|
|
||||||
"class" -> {
|
|
||||||
parts[2] = mapper.map(parts[2])
|
|
||||||
}
|
|
||||||
|
|
||||||
"fields" -> {
|
|
||||||
parts[3] = mapper.mapFieldName(parts[2], parts[3], parts[4])
|
|
||||||
parts[4] = mapper.mapDesc(parts[4])
|
|
||||||
parts[3] = mapper.map(parts[2])
|
|
||||||
}
|
|
||||||
|
|
||||||
"methods" -> {
|
|
||||||
parts[3] = mapper.mapMethodName(parts[2], parts[3], parts[4])
|
|
||||||
parts[4] = mapper.mapMethodDesc(parts[4])
|
|
||||||
parts[2] = mapper.map(parts[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appendLine(parts.joinToString("\\t"))
|
|
||||||
return@forEachLine
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appendLine(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
aw.writeText(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Thyroxine.remap(mappings, temp, file.toPath(), false, false)
|
|
||||||
Files.deleteIfExists(temp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.register(Constants.UPDATE_AW_TASK) { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.actions.addFirst {
|
|
||||||
AccessWidener.apply(project, ProjectStorage.get(it.project).remappedGameJarPath!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK, Delete::class.java) { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.delete = setOf(ProjectStorage.get(project).localCacheDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK, Delete::class.java) { task ->
|
|
||||||
task.group = Constants.TASK_GROUP
|
|
||||||
task.delete = setOf(PhytotelmaPlugin.globalCacheDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
project.afterEvaluate {
|
|
||||||
remapModDependencies()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun remapModDependencies() {
|
|
||||||
val out = System.out
|
|
||||||
// Mute the output from thyroxine as there may be a lot of remapping operations here
|
|
||||||
System.setOut(PrintStream(OutputStream.nullOutputStream()))
|
|
||||||
ModConfigurations.configurations.forEach { conf ->
|
|
||||||
val artifacts = project.configurations.getByName("mod" + conf.name.capitalized())
|
|
||||||
.resolvedConfiguration.resolvedArtifacts
|
|
||||||
if (artifacts.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val target = project.configurations.create("mod" + conf.name.capitalized() + "Mapped") { c ->
|
|
||||||
c.isTransitive = false
|
|
||||||
conf.classpathNames.forEach {
|
|
||||||
project.configurations.getByName(it).extendsFrom(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val storage = ProjectStorage.get(project)
|
|
||||||
val mappings = MappingBundle.merge(
|
|
||||||
storage.mappings!!.reverse(), MojmapProvider.get(
|
|
||||||
storage.minecraftVersion!!,
|
|
||||||
PhytotelmaPlugin.globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt")
|
|
||||||
).orElseThrow().reverse().renameDstNamespace("mojmap")
|
|
||||||
).forNamespaces("mojmap", storage.targetNamespace)
|
|
||||||
val targetPath = project.layout.buildDirectory.asFile.get().toPath().resolve("remappedMods")
|
|
||||||
.resolve("dev/frogmc/phytotelma/remapped_mods")
|
|
||||||
val remappedPaths = mutableListOf<Path>()
|
|
||||||
artifacts.forEach { artifact ->
|
|
||||||
val group = artifact.moduleVersion.id.group
|
|
||||||
val name = artifact.moduleVersion.id.name
|
|
||||||
val groupname = (group + "_" + name).replace(".", "_")
|
|
||||||
val version = artifact.moduleVersion.id.version
|
|
||||||
val classifier = artifact.classifier
|
|
||||||
val remappedPath = targetPath.resolve(groupname).resolve(version)
|
|
||||||
.resolve(groupname + "-" + version + (classifier?.let { "-$it" } ?: "") + ".jar")
|
|
||||||
remappedPath.createParentDirectories()
|
|
||||||
remappedPaths.add(remappedPath)
|
|
||||||
|
|
||||||
val pom = remappedPath.resolveSibling(remappedPath.fileName.toString().removeSuffix(".jar") + ".pom")
|
|
||||||
pom.writeText(
|
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
||||||
"<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
|
|
||||||
"\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
|
|
||||||
"\t<modelVersion>4.0.0</modelVersion>\n" +
|
|
||||||
"\t<groupId>dev.frogmc.phytotelma.remapped_mods</groupId>\n" +
|
|
||||||
"\t<artifactId>$groupname</artifactId>\n" +
|
|
||||||
"\t<version>$version</version>\n" +
|
|
||||||
"</project>"
|
|
||||||
)
|
|
||||||
remappedPaths.add(pom)
|
|
||||||
|
|
||||||
Thyroxine.remap(mappings, artifact.file.toPath(), remappedPath, false, false)
|
|
||||||
|
|
||||||
project.dependencies.add(
|
|
||||||
target.name,
|
|
||||||
"dev.frogmc.phytotelma.remapped_mods:$groupname:$version" + (classifier?.let { ":$it" } ?: "")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.setOut(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun minecraft(action: Action<MinecraftConfiguration>) {
|
override fun minecraft(action: Action<MinecraftConfiguration>) {
|
||||||
setupTasks()
|
|
||||||
val mcConf = objects.newInstance(MinecraftConfiguration::class.java)
|
val mcConf = objects.newInstance(MinecraftConfiguration::class.java)
|
||||||
action.execute(mcConf)
|
action.execute(mcConf)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue