Skip to content

Commit

Permalink
Automatically move Paper/fork rootDirectory to `<upstreamsDir>/<forkN…
Browse files Browse the repository at this point in the history
…ame|paper>` for non-active configs
  • Loading branch information
jpenilla committed Jan 14, 2025
1 parent 044758e commit 101b47c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 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)
val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class, target.upstreamsDirectory())

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,6 +26,7 @@ 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.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.RegularFileProperty
Expand All @@ -40,12 +41,22 @@ abstract class ForkConfig @Inject constructor(
providers: ProviderFactory,
objects: ObjectFactory,
layout: ProjectLayout,
activeFork: Property<ForkConfig>,
upstreamsDir: Provider<Directory>,
) : Named {
override fun getName(): String {
return configName
}

val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory.dir("../"))
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(
activeFork.map {
if (it.name == name) {
layout.projectDirectory.dir("../")
} else {
upstreamsDir.get().dir(name)
}
}
)
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 @@ -30,15 +30,16 @@ import org.gradle.api.model.ObjectFactory

open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) {

val paperServerDir: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory)
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory.dir("../"))
val paperServerDir: DirectoryProperty = objects.dirFrom(rootDirectory, "paper-server")
val serverPatchesDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches")
val rejectsDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "rejected")
val sourcePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "sources")
val resourcePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "resources")
val featurePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "features")

@Suppress("MemberVisibilityCanBePrivate")
val buildDataDir: DirectoryProperty = objects.dirFrom(paperServerDir, "../build-data")
val buildDataDir: DirectoryProperty = objects.dirFrom(rootDirectory, "build-data")
val devImports: RegularFileProperty = objects.fileFrom(buildDataDir, "dev-imports.txt")
val additionalAts: RegularFileProperty = objects.fileFrom(buildDataDir, "paper.at")
val reobfMappingsPatch: RegularFileProperty = objects.fileFrom(buildDataDir, "reobf-mappings-patch.tiny")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@
package io.papermc.paperweight.core.extension

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.*

open class PaperweightCoreExtension(objects: ObjectFactory, layout: ProjectLayout) {

abstract class PaperweightCoreExtension @Inject constructor(
objects: ObjectFactory,
layout: ProjectLayout,
upstreamsDir: Provider<Directory>
) {
val minecraftVersion: Property<String> = objects.property()
val minecraftManifestUrl: Property<String> = objects.property<String>().convention(MC_MANIFEST_URL)

Expand Down Expand Up @@ -64,7 +70,9 @@ open class PaperweightCoreExtension(objects: ObjectFactory, layout: ProjectLayou
action.execute(paper)
}

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

val activeFork: Property<ForkConfig> = objects.property()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.TaskContainer
Expand Down Expand Up @@ -135,7 +133,9 @@ class CoreTasks(
val hasFork = project.coreExt.forks.isNotEmpty()

if (hasFork) {
validateRootDirs()
project.coreExt.paper.rootDirectory.set(
project.upstreamsDirectory().map { it.dir("paper") }
)
}

if (!hasFork) {
Expand Down Expand Up @@ -212,7 +212,7 @@ class CoreTasks(
cfg.name,
cfg.upstream,
if (cfg.forksPaper.get()) {
project.coreExt.paper.paperServerDir.dir("../")
project.coreExt.paper.rootDirectory
} else {
cfg.forks.get().rootDirectory
},
Expand Down Expand Up @@ -326,19 +326,4 @@ class CoreTasks(
project.logger.info("Fork order: {}", order.joinToString(" -> ") { it.name })
return order
}

private fun validateRootDirs() {
val usedRoots = mutableMapOf<Path, String>()
usedRoots[project.coreExt.paper.paperServerDir.dir("../").path.normalize().absolute()] = "paper"
project.coreExt.forks.forEach {
val root = it.rootDirectory.path.normalize().absolute()
val prev = usedRoots.putIfAbsent(root, it.name)
if (prev != null) {
throw PaperweightException(
"Multiple forks use root directory $root. Ensure all forks and Paper have their root directory/" +
"Paper server directory changed, except for the current project."
)
}
}
}
}

0 comments on commit 101b47c

Please sign in to comment.