Skip to content

Commit

Permalink
Adjust fork roots during configuration instead of using delicate conv…
Browse files Browse the repository at this point in the history
…ention fallbacks
  • Loading branch information
jpenilla committed Jan 15, 2025
1 parent 101b47c commit ecbdd0a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract class PaperweightCore : Plugin<Project> {
Git.checkForGit(target.providers)
printId<PaperweightCore>("paperweight-core", target.gradle)

val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class, target.upstreamsDirectory())
val ext = target.extensions.create<PaperweightCoreExtension>(PAPERWEIGHT_EXTENSION)

target.gradle.sharedServices.registerIfAbsent(DOWNLOAD_SERVICE_NAME, DownloadService::class) {
parameters.projectPath.set(target.projectDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,23 +39,13 @@ abstract class ForkConfig @Inject constructor(
private val configName: String,
providers: ProviderFactory,
objects: ObjectFactory,
layout: ProjectLayout,
activeFork: Property<ForkConfig>,
upstreamsDir: Provider<Directory>,
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Directory>
) {
abstract class PaperweightCoreExtension @Inject constructor(objects: ObjectFactory) {
val minecraftVersion: Property<String> = objects.property()
val minecraftManifestUrl: Property<String> = objects.property<String>().convention(MC_MANIFEST_URL)

Expand All @@ -57,8 +50,8 @@ abstract class PaperweightCoreExtension @Inject constructor(

val reobfPackagesToFix: ListProperty<String> = objects.listProperty()

val spigot = SpigotExtension(objects)
val paper = PaperExtension(objects, layout)
val spigot = objects.newInstance<SpigotExtension>()
val paper = objects.newInstance<PaperExtension>()

@Suppress("unused")
fun spigot(action: Action<in SpigotExtension>) {
Expand All @@ -71,7 +64,7 @@ abstract class PaperweightCoreExtension @Inject constructor(
}

val forks: NamedDomainObjectContainer<ForkConfig> = objects.domainObjectContainer(ForkConfig::class) {
objects.newInstance<ForkConfig>(it, activeFork, upstreamsDir)
objects.newInstance<ForkConfig>(it)
}

val activeFork: Property<ForkConfig> = objects.property()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = objects.property()
val packageVersion: Property<String> = objects.property()
val buildDataRef: Property<String>
val packageVersion: Property<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ fun JavaToolchainService.defaultJavaLauncher(project: Project): Provider<JavaLau
return launcherFor(ext.toolchain).orElse(fallback)
}

fun <P : Property<*>> P.withDisallowChanges(): P = apply { disallowChanges() }
fun <P : Property<*>> P.withDisallowUnsafeRead(): P = apply { disallowUnsafeRead() }
fun <P : Property<*>> P.changesDisallowed(): P = apply { disallowChanges() }
fun <P : Property<*>> P.finalizedOnRead(): P = apply { finalizeValueOnRead() }

fun FileCollection.toJarClassProviderRoots(): List<ClassProviderRoot> = files.asSequence()
.map { f -> f.toPath() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ abstract class PaperweightUserExtension(
*/
val minecraftVersion: Provider<String> = objects.property<String>().value(
setup.map { it.minecraftVersion }
).withDisallowChanges()
).changesDisallowed()

/**
* The [JavaLauncher] used for the userdev setup pipeline.
Expand Down

0 comments on commit ecbdd0a

Please sign in to comment.