improve support for multi-module builds
All checks were successful
Publish to snapshot maven / build (push) Successful in 22s

This commit is contained in:
moehreag 2024-06-11 21:50:10 +02:00
parent 3f25831332
commit bdc9fe585c
7 changed files with 52 additions and 24 deletions

View file

@ -32,8 +32,9 @@ class PhytotelmaPlugin : Plugin<Project> {
println("> Applying FrogMC Gradle Plugin to ${project.name}") println("> Applying FrogMC Gradle Plugin to ${project.name}")
globalCacheDir = project.gradle.gradleUserHomeDir.resolve("caches/phytotelma/").toPath() globalCacheDir = project.gradle.gradleUserHomeDir.resolve("caches/phytotelma/").toPath()
globalCacheDir.createDirectories() globalCacheDir.createDirectories()
localCacheDir = project.projectDir.resolve(".gradle/phytotelma/cache/").toPath() val localCacheDir = project.projectDir.resolve(".gradle/phytotelma/cache/").toPath()
localCacheDir.createDirectories() localCacheDir.createDirectories()
ProjectStorage.get(project).localCacheDir = localCacheDir
project.plugins.let { project.plugins.let {
it.apply("java-library") it.apply("java-library")
@ -72,9 +73,10 @@ class PhytotelmaPlugin : Plugin<Project> {
project.task("genSources").apply { project.task("genSources").apply {
group = Constants.TASK_GROUP group = Constants.TASK_GROUP
doFirst { doFirst {
val fileName = remappedGameJarPath.fileName.toString() val projectData = ProjectStorage.get(it.project)
val fileName = projectData.remappedGameJarPath!!.fileName.toString()
val output = val output =
remappedGameJarPath.resolveSibling( projectData.remappedGameJarPath!!.resolveSibling(
fileName.substring( fileName.substring(
0, 0,
fileName.lastIndexOf("-") fileName.lastIndexOf("-")
@ -87,9 +89,9 @@ class PhytotelmaPlugin : Plugin<Project> {
val options = mutableMapOf<String, Any>() val options = mutableMapOf<String, Any>()
println("Preparing Parchment...") println("Preparing Parchment...")
val parchment = ParchmentProvider.getParchment( val parchment = ParchmentProvider.getParchment(
minecraftVersion, projectData.minecraftVersion!!,
parchmentVersion, projectData.parchmentVersion!!,
globalCacheDir.resolve("org/parchmentmc/parchment/$minecraftVersion/$parchmentVersion/") globalCacheDir.resolve("org/parchmentmc/parchment/${projectData.minecraftVersion}/${projectData.parchmentVersion}/")
) )
options[IFabricJavadocProvider.PROPERTY_NAME] = ParchmentJavadocProvider(parchment) options[IFabricJavadocProvider.PROPERTY_NAME] = ParchmentJavadocProvider(parchment)
@ -110,7 +112,7 @@ class PhytotelmaPlugin : Plugin<Project> {
SingleFileSaver(output.toFile()), SingleFileSaver(output.toFile()),
options, logger options, logger
) )
decomp.addSource(remappedGameJarPath.toFile()) decomp.addSource(projectData.remappedGameJarPath!!.toFile())
decomp.decompileContext() decomp.decompileContext()
} }
@ -131,7 +133,7 @@ class PhytotelmaPlugin : Plugin<Project> {
project.task(Constants.DOWNLOAD_ASSETS_TASK).apply { project.task(Constants.DOWNLOAD_ASSETS_TASK).apply {
group = Constants.TASK_GROUP group = Constants.TASK_GROUP
doFirst { doFirst {
AssetDownloader.download() AssetDownloader.download(it.project)
} }
} }
@ -154,16 +156,12 @@ class PhytotelmaPlugin : Plugin<Project> {
project.tasks.register(Constants.UPDATE_AW_TASK) { project.tasks.register(Constants.UPDATE_AW_TASK) {
it.group = Constants.TASK_GROUP it.group = Constants.TASK_GROUP
it.actions.addFirst { it.actions.addFirst {
AccessWidener.apply(project, remappedGameJarPath) AccessWidener.apply(project, ProjectStorage.get(it.project).remappedGameJarPath!!)
} }
} }
} }
companion object { companion object {
lateinit var localCacheDir: Path
lateinit var globalCacheDir: Path lateinit var globalCacheDir: Path
lateinit var minecraftVersion: String
lateinit var remappedGameJarPath: Path
lateinit var parchmentVersion: String
} }
} }

View file

@ -0,0 +1,22 @@
package dev.frogmc.phytotelma
import org.gradle.api.Project
import java.nio.file.Path
object ProjectStorage {
private val data = mutableMapOf<Project, ProjectData>()
fun get(project: Project): ProjectData {
if (!data.containsKey(project)){
data[project] = ProjectData(null, null, null, null)
}
return data[project]!!
}
}
class ProjectData(var localCacheDir: Path?,
var minecraftVersion: String?,
var remappedGameJarPath: Path?,
var parchmentVersion: String?)

View file

@ -7,6 +7,7 @@ import com.electronwill.nightconfig.toml.TomlParser
import com.electronwill.nightconfig.toml.TomlWriter import com.electronwill.nightconfig.toml.TomlWriter
import dev.frogmc.phytotelma.Constants import dev.frogmc.phytotelma.Constants
import dev.frogmc.phytotelma.PhytotelmaPlugin import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.nest.Nester import dev.frogmc.phytotelma.nest.Nester
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.OutputFile
@ -66,7 +67,7 @@ abstract class PhytotelmaBuildTask : DefaultTask() {
""" """
Built-By: Phytotelma ${this.javaClass.`package`.implementationVersion} Built-By: Phytotelma ${this.javaClass.`package`.implementationVersion}
Target-Namespace: Mojmap Target-Namespace: Mojmap
Built-For: Minecraft ${PhytotelmaPlugin.minecraftVersion} Built-For: Minecraft ${ProjectStorage.get(project).minecraftVersion}
Build-Date: ${LocalDateTime.now()} Build-Date: ${LocalDateTime.now()}
""".trimIndent() """.trimIndent()
) )

View file

@ -2,6 +2,7 @@ package dev.frogmc.phytotelma.ext
import dev.frogmc.phytotelma.Constants import dev.frogmc.phytotelma.Constants
import dev.frogmc.phytotelma.PhytotelmaPlugin import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.VersionChecker import dev.frogmc.phytotelma.VersionChecker
import dev.frogmc.phytotelma.accesswidener.AccessWidener import dev.frogmc.phytotelma.accesswidener.AccessWidener
import dev.frogmc.phytotelma.run.RunConfigGenerator import dev.frogmc.phytotelma.run.RunConfigGenerator
@ -25,14 +26,15 @@ abstract class PhytotelmaGradleExtensionImpl : PhytotelmaGradleExtension {
val parchment = val parchment =
parchmentVersion ?: kotlin.runCatching { ParchmentProvider.findForMinecraftVersion(version) } parchmentVersion ?: kotlin.runCatching { ParchmentProvider.findForMinecraftVersion(version) }
.getOrDefault("") .getOrDefault("")
PhytotelmaPlugin.minecraftVersion = version val projectData = ProjectStorage.get(getProject())
PhytotelmaPlugin.parchmentVersion = parchment projectData.minecraftVersion = version
projectData.parchmentVersion = parchment
println("Valid version! $version") println("Valid version! $version")
val clientJar = VersionChecker.downloadClient(version) val clientJar = VersionChecker.downloadClient(version)
val remappedJar = val remappedJar =
PhytotelmaPlugin.localCacheDir.resolve("net/minecraft/client/$version/client-$version-remapped.jar") projectData.localCacheDir!!.resolve("net/minecraft/client/$version/client-$version-remapped.jar")
remappedJar.createParentDirectories() remappedJar.createParentDirectories()
PhytotelmaPlugin.remappedGameJarPath = remappedJar projectData.remappedGameJarPath = remappedJar
println("Time to setup Minecraft!") println("Time to setup Minecraft!")
val applyAW = AccessWidener.needsUpdate(getProject()) val applyAW = AccessWidener.needsUpdate(getProject())
if (remappedJar.notExists() || applyAW) { if (remappedJar.notExists() || applyAW) {

View file

@ -3,8 +3,10 @@ package dev.frogmc.phytotelma.run
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonObject import com.google.gson.JsonObject
import dev.frogmc.phytotelma.PhytotelmaPlugin import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.VersionChecker import dev.frogmc.phytotelma.VersionChecker
import dev.frogmc.phytotelma.common.CachingHttpClient import dev.frogmc.phytotelma.common.CachingHttpClient
import org.gradle.api.Project
import java.net.URI import java.net.URI
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.nio.file.Path import java.nio.file.Path
@ -14,8 +16,8 @@ import kotlin.io.path.reader
object AssetDownloader { object AssetDownloader {
private const val ASSETS_URL = "https://resources.download.minecraft.net" private const val ASSETS_URL = "https://resources.download.minecraft.net"
fun download() { fun download(project: Project) {
val version = PhytotelmaPlugin.minecraftVersion val version = ProjectStorage.get(project).minecraftVersion!!
val path = PhytotelmaPlugin.globalCacheDir.resolve("assets") val path = PhytotelmaPlugin.globalCacheDir.resolve("assets")
val id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes")) val id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes"))

View file

@ -1,6 +1,7 @@
package dev.frogmc.phytotelma.run package dev.frogmc.phytotelma.run
import dev.frogmc.phytotelma.PhytotelmaPlugin import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.VersionChecker import dev.frogmc.phytotelma.VersionChecker
import dev.frogmc.phytotelma.common.Env import dev.frogmc.phytotelma.common.Env
import dev.frogmc.phytotelma.run.adapter.EclipseAdapter import dev.frogmc.phytotelma.run.adapter.EclipseAdapter
@ -32,7 +33,8 @@ object RunConfigGenerator {
if (assetIndexPath.notExists()) { if (assetIndexPath.notExists()) {
assetIndexPath.createDirectories() assetIndexPath.createDirectories()
} }
val indexId = VersionChecker.downloadAssetIndex(PhytotelmaPlugin.minecraftVersion, assetIndexPath) val projectData = ProjectStorage.get(project)
val indexId = VersionChecker.downloadAssetIndex(projectData.minecraftVersion!!, assetIndexPath)
val projectName = if (project.rootDir == project.projectDir) "" else " (${project.name})" val projectName = if (project.rootDir == project.projectDir) "" else " (${project.name})"
@ -48,7 +50,7 @@ object RunConfigGenerator {
mutableListOf( mutableListOf(
"-Xmx${project.properties.getOrDefault("frogmc.gameHeap", "2048M")}", "-Xmx${project.properties.getOrDefault("frogmc.gameHeap", "2048M")}",
"-Dfrogmc.development=true", "-Dfrogmc.development=true",
"-Dfrogmc.plugin.minecraft.gameJar=${PhytotelmaPlugin.remappedGameJarPath}", "-Dfrogmc.plugin.minecraft.gameJar=${projectData.remappedGameJarPath}",
"-Dlog4j2.configurationFile=$log4jPath", "-Dlog4j2.configurationFile=$log4jPath",
"-Dlog4j2.formatMsgLookups=true" "-Dlog4j2.formatMsgLookups=true"
).apply { ).apply {

View file

@ -2,6 +2,7 @@ package dev.frogmc.phytotelma.run.task
import dev.frogmc.phytotelma.Constants import dev.frogmc.phytotelma.Constants
import dev.frogmc.phytotelma.PhytotelmaPlugin import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.VersionChecker import dev.frogmc.phytotelma.VersionChecker
import dev.frogmc.phytotelma.common.Env import dev.frogmc.phytotelma.common.Env
import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.ConfigurableFileCollection
@ -28,7 +29,7 @@ abstract class RunGameTask @Inject constructor(env: Env) : JavaExec() {
if (assetIndexPath.notExists()) { if (assetIndexPath.notExists()) {
assetIndexPath.createDirectories() assetIndexPath.createDirectories()
} }
val indexId = VersionChecker.downloadAssetIndex(PhytotelmaPlugin.minecraftVersion, assetIndexPath) val indexId = VersionChecker.downloadAssetIndex(ProjectStorage.get(project).minecraftVersion!!, assetIndexPath)
val log4jPath = project.rootDir.resolve(".gradle/phytotelma/log4j.xml").toPath().absolute() val log4jPath = project.rootDir.resolve(".gradle/phytotelma/log4j.xml").toPath().absolute()
if (log4jPath.notExists()) { if (log4jPath.notExists()) {
log4jPath.createParentDirectories() log4jPath.createParentDirectories()
@ -56,7 +57,7 @@ abstract class RunGameTask @Inject constructor(env: Env) : JavaExec() {
jvmArguments.addAll( jvmArguments.addAll(
"-Xmx${project.properties.getOrDefault("frogmc.gameHeap", "2048M")}", "-Xmx${project.properties.getOrDefault("frogmc.gameHeap", "2048M")}",
"-Dfrogmc.development=true", "-Dfrogmc.development=true",
"-Dfrogmc.plugin.minecraft.gameJar=${PhytotelmaPlugin.remappedGameJarPath}", "-Dfrogmc.plugin.minecraft.gameJar=${ProjectStorage.get(project).remappedGameJarPath}",
"-Dlog4j2.configurationFile=$log4jPath", "-Dlog4j2.configurationFile=$log4jPath",
"-Dlog4j2.formatMsgNoLookups=true", "-Dlog4j2.formatMsgNoLookups=true",
writeArgFile() writeArgFile()