From ecbdd0a19d977a8fab33c20647122a88b8803959 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:53:02 -0700 Subject: [PATCH] Adjust fork roots during configuration instead of using delicate convention fallbacks --- .../papermc/paperweight/core/PaperweightCore.kt | 2 +- .../paperweight/core/extension/ForkConfig.kt | 17 +++-------------- .../core/extension/PaperExtension.kt | 7 ++++--- .../core/extension/PaperweightCoreExtension.kt | 15 ++++----------- .../core/extension/SpigotExtension.kt | 8 +++----- .../core/taskcontainers/CoreTasks.kt | 8 ++++++++ .../kotlin/io/papermc/paperweight/util/utils.kt | 4 ++-- .../userdev/PaperweightUserExtension.kt | 2 +- 8 files changed, 26 insertions(+), 37 deletions(-) diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt index 5242c26c4..3efc45e62 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt @@ -61,7 +61,7 @@ abstract class PaperweightCore : Plugin { Git.checkForGit(target.providers) printId("paperweight-core", target.gradle) - val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class, target.upstreamsDirectory()) + val ext = target.extensions.create(PAPERWEIGHT_EXTENSION) target.gradle.sharedServices.registerIfAbsent(DOWNLOAD_SERVICE_NAME, DownloadService::class) { parameters.projectPath.set(target.projectDir) diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/ForkConfig.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/ForkConfig.kt index 891b7d8b4..cd242eba4 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/ForkConfig.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/ForkConfig.kt @@ -26,9 +26,8 @@ import io.papermc.paperweight.util.* import javax.inject.Inject import org.gradle.api.Action import org.gradle.api.Named -import org.gradle.api.file.Directory +import org.gradle.api.file.BuildLayout 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 @@ -40,23 +39,13 @@ abstract class ForkConfig @Inject constructor( private val configName: String, providers: ProviderFactory, objects: ObjectFactory, - layout: ProjectLayout, - activeFork: Property, - upstreamsDir: Provider, + buildLayout: BuildLayout, ) : Named { override fun getName(): String { return configName } - val rootDirectory: DirectoryProperty = objects.directoryProperty().convention( - activeFork.map { - if (it.name == name) { - layout.projectDirectory.dir("../") - } else { - upstreamsDir.get().dir(name) - } - } - ) + val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(buildLayout.rootDirectory).finalizedOnRead() val serverDirectory: DirectoryProperty = objects.dirFrom(rootDirectory, providers.provider { "$name-server" }) val serverPatchesDir: DirectoryProperty = objects.dirFrom(serverDirectory, "minecraft-patches") val rejectsDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "rejected") diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt index b2c715d10..2b8dbf205 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt @@ -23,14 +23,15 @@ package io.papermc.paperweight.core.extension import io.papermc.paperweight.util.* +import javax.inject.Inject +import org.gradle.api.file.BuildLayout import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.ProjectLayout import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory -open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) { +abstract class PaperExtension @Inject constructor(objects: ObjectFactory, buildLayout: BuildLayout) { - val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory.dir("../")) + val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(buildLayout.rootDirectory) val paperServerDir: DirectoryProperty = objects.dirFrom(rootDirectory, "paper-server") val serverPatchesDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches") val rejectsDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "rejected") diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperweightCoreExtension.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperweightCoreExtension.kt index 11f3ac830..4f577afae 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperweightCoreExtension.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperweightCoreExtension.kt @@ -26,20 +26,13 @@ import io.papermc.paperweight.util.constants.* import javax.inject.Inject import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.ProjectLayout import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.* -abstract class PaperweightCoreExtension @Inject constructor( - objects: ObjectFactory, - layout: ProjectLayout, - upstreamsDir: Provider -) { +abstract class PaperweightCoreExtension @Inject constructor(objects: ObjectFactory) { val minecraftVersion: Property = objects.property() val minecraftManifestUrl: Property = objects.property().convention(MC_MANIFEST_URL) @@ -57,8 +50,8 @@ abstract class PaperweightCoreExtension @Inject constructor( val reobfPackagesToFix: ListProperty = objects.listProperty() - val spigot = SpigotExtension(objects) - val paper = PaperExtension(objects, layout) + val spigot = objects.newInstance() + val paper = objects.newInstance() @Suppress("unused") fun spigot(action: Action) { @@ -71,7 +64,7 @@ abstract class PaperweightCoreExtension @Inject constructor( } val forks: NamedDomainObjectContainer = objects.domainObjectContainer(ForkConfig::class) { - objects.newInstance(it, activeFork, upstreamsDir) + objects.newInstance(it) } val activeFork: Property = objects.property() diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/SpigotExtension.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/SpigotExtension.kt index 84b9f693e..ade0fc99f 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/SpigotExtension.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/SpigotExtension.kt @@ -22,12 +22,10 @@ package io.papermc.paperweight.core.extension -import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property -import org.gradle.kotlin.dsl.* -open class SpigotExtension(objects: ObjectFactory) { +interface SpigotExtension { - val buildDataRef: Property = objects.property() - val packageVersion: Property = objects.property() + val buildDataRef: Property + val packageVersion: Property } diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/CoreTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/CoreTasks.kt index 4ecea9b29..057511ca4 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/CoreTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/CoreTasks.kt @@ -136,6 +136,14 @@ class CoreTasks( project.coreExt.paper.rootDirectory.set( project.upstreamsDirectory().map { it.dir("paper") } ) + project.coreExt.forks.forEach { fork -> + val activeFork = project.coreExt.activeFork.get().name == fork.name + if (!activeFork) { + fork.rootDirectory.set( + project.upstreamsDirectory().map { it.dir(fork.name) } + ) + } + } } if (!hasFork) { diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt index bf565d7a0..5a9e71088 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt @@ -388,8 +388,8 @@ fun JavaToolchainService.defaultJavaLauncher(project: Project): Provider> P.withDisallowChanges(): P = apply { disallowChanges() } -fun

> P.withDisallowUnsafeRead(): P = apply { disallowUnsafeRead() } +fun

> P.changesDisallowed(): P = apply { disallowChanges() } +fun

> P.finalizedOnRead(): P = apply { finalizeValueOnRead() } fun FileCollection.toJarClassProviderRoots(): List = files.asSequence() .map { f -> f.toPath() } diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUserExtension.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUserExtension.kt index ea1703688..44684cb90 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUserExtension.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/PaperweightUserExtension.kt @@ -78,7 +78,7 @@ abstract class PaperweightUserExtension( */ val minecraftVersion: Provider = objects.property().value( setup.map { it.minecraftVersion } - ).withDisallowChanges() + ).changesDisallowed() /** * The [JavaLauncher] used for the userdev setup pipeline.