Skip to content

Commit 101b47c

Browse files
committed
Automatically move Paper/fork rootDirectory to <upstreamsDir>/<forkName|paper> for non-active configs
1 parent 044758e commit 101b47c

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract class PaperweightCore : Plugin<Project> {
6161
Git.checkForGit(target.providers)
6262
printId<PaperweightCore>("paperweight-core", target.gradle)
6363

64-
val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class)
64+
val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class, target.upstreamsDirectory())
6565

6666
target.gradle.sharedServices.registerIfAbsent(DOWNLOAD_SERVICE_NAME, DownloadService::class) {
6767
parameters.projectPath.set(target.projectDir)

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/ForkConfig.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.papermc.paperweight.util.*
2626
import javax.inject.Inject
2727
import org.gradle.api.Action
2828
import org.gradle.api.Named
29+
import org.gradle.api.file.Directory
2930
import org.gradle.api.file.DirectoryProperty
3031
import org.gradle.api.file.ProjectLayout
3132
import org.gradle.api.file.RegularFileProperty
@@ -40,12 +41,22 @@ abstract class ForkConfig @Inject constructor(
4041
providers: ProviderFactory,
4142
objects: ObjectFactory,
4243
layout: ProjectLayout,
44+
activeFork: Property<ForkConfig>,
45+
upstreamsDir: Provider<Directory>,
4346
) : Named {
4447
override fun getName(): String {
4548
return configName
4649
}
4750

48-
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory.dir("../"))
51+
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(
52+
activeFork.map {
53+
if (it.name == name) {
54+
layout.projectDirectory.dir("../")
55+
} else {
56+
upstreamsDir.get().dir(name)
57+
}
58+
}
59+
)
4960
val serverDirectory: DirectoryProperty = objects.dirFrom(rootDirectory, providers.provider { "$name-server" })
5061
val serverPatchesDir: DirectoryProperty = objects.dirFrom(serverDirectory, "minecraft-patches")
5162
val rejectsDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "rejected")

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ import org.gradle.api.model.ObjectFactory
3030

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

33-
val paperServerDir: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory)
33+
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory.dir("../"))
34+
val paperServerDir: DirectoryProperty = objects.dirFrom(rootDirectory, "paper-server")
3435
val serverPatchesDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches")
3536
val rejectsDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "rejected")
3637
val sourcePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "sources")
3738
val resourcePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "resources")
3839
val featurePatchDir: DirectoryProperty = objects.dirFrom(serverPatchesDir, "features")
3940

4041
@Suppress("MemberVisibilityCanBePrivate")
41-
val buildDataDir: DirectoryProperty = objects.dirFrom(paperServerDir, "../build-data")
42+
val buildDataDir: DirectoryProperty = objects.dirFrom(rootDirectory, "build-data")
4243
val devImports: RegularFileProperty = objects.fileFrom(buildDataDir, "dev-imports.txt")
4344
val additionalAts: RegularFileProperty = objects.fileFrom(buildDataDir, "paper.at")
4445
val reobfMappingsPatch: RegularFileProperty = objects.fileFrom(buildDataDir, "reobf-mappings-patch.tiny")

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperweightCoreExtension.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@
2323
package io.papermc.paperweight.core.extension
2424

2525
import io.papermc.paperweight.util.constants.*
26+
import javax.inject.Inject
2627
import org.gradle.api.Action
2728
import org.gradle.api.NamedDomainObjectContainer
29+
import org.gradle.api.file.Directory
2830
import org.gradle.api.file.DirectoryProperty
2931
import org.gradle.api.file.ProjectLayout
3032
import org.gradle.api.model.ObjectFactory
3133
import org.gradle.api.provider.ListProperty
3234
import org.gradle.api.provider.Property
35+
import org.gradle.api.provider.Provider
3336
import org.gradle.kotlin.dsl.*
3437

35-
open class PaperweightCoreExtension(objects: ObjectFactory, layout: ProjectLayout) {
36-
38+
abstract class PaperweightCoreExtension @Inject constructor(
39+
objects: ObjectFactory,
40+
layout: ProjectLayout,
41+
upstreamsDir: Provider<Directory>
42+
) {
3743
val minecraftVersion: Property<String> = objects.property()
3844
val minecraftManifestUrl: Property<String> = objects.property<String>().convention(MC_MANIFEST_URL)
3945

@@ -64,7 +70,9 @@ open class PaperweightCoreExtension(objects: ObjectFactory, layout: ProjectLayou
6470
action.execute(paper)
6571
}
6672

67-
val forks: NamedDomainObjectContainer<ForkConfig> = objects.domainObjectContainer(ForkConfig::class)
73+
val forks: NamedDomainObjectContainer<ForkConfig> = objects.domainObjectContainer(ForkConfig::class) {
74+
objects.newInstance<ForkConfig>(it, activeFork, upstreamsDir)
75+
}
6876

6977
val activeFork: Property<ForkConfig> = objects.property()
7078
}

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/CoreTasks.kt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import io.papermc.paperweight.util.*
3636
import io.papermc.paperweight.util.constants.*
3737
import io.papermc.paperweight.util.data.mache.*
3838
import java.nio.file.Files
39-
import java.nio.file.Path
40-
import kotlin.io.path.*
4139
import org.gradle.api.Project
4240
import org.gradle.api.provider.Property
4341
import org.gradle.api.tasks.TaskContainer
@@ -135,7 +133,9 @@ class CoreTasks(
135133
val hasFork = project.coreExt.forks.isNotEmpty()
136134

137135
if (hasFork) {
138-
validateRootDirs()
136+
project.coreExt.paper.rootDirectory.set(
137+
project.upstreamsDirectory().map { it.dir("paper") }
138+
)
139139
}
140140

141141
if (!hasFork) {
@@ -212,7 +212,7 @@ class CoreTasks(
212212
cfg.name,
213213
cfg.upstream,
214214
if (cfg.forksPaper.get()) {
215-
project.coreExt.paper.paperServerDir.dir("../")
215+
project.coreExt.paper.rootDirectory
216216
} else {
217217
cfg.forks.get().rootDirectory
218218
},
@@ -326,19 +326,4 @@ class CoreTasks(
326326
project.logger.info("Fork order: {}", order.joinToString(" -> ") { it.name })
327327
return order
328328
}
329-
330-
private fun validateRootDirs() {
331-
val usedRoots = mutableMapOf<Path, String>()
332-
usedRoots[project.coreExt.paper.paperServerDir.dir("../").path.normalize().absolute()] = "paper"
333-
project.coreExt.forks.forEach {
334-
val root = it.rootDirectory.path.normalize().absolute()
335-
val prev = usedRoots.putIfAbsent(root, it.name)
336-
if (prev != null) {
337-
throw PaperweightException(
338-
"Multiple forks use root directory $root. Ensure all forks and Paper have their root directory/" +
339-
"Paper server directory changed, except for the current project."
340-
)
341-
}
342-
}
343-
}
344329
}

0 commit comments

Comments
 (0)