Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class ForkConfig @Inject constructor(
return configName
}

val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(project.rootProject.layout.projectDirectory).finalizedOnRead()
val rootDirectory: DirectoryProperty = objects.directoryProperty().convention(project.rootProject.layout.projectDirectory)
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 @@ -24,12 +24,15 @@ package io.papermc.paperweight.core.taskcontainers

import io.papermc.paperweight.PaperweightException
import io.papermc.paperweight.core.extension.ForkConfig
import io.papermc.paperweight.core.tasks.CheckoutRepo
import io.papermc.paperweight.core.tasks.ExtractMinecraftSources
import io.papermc.paperweight.core.tasks.ImportLibraryFiles
import io.papermc.paperweight.core.tasks.IndexLibraryFiles
import io.papermc.paperweight.core.tasks.RunNestedBuild
import io.papermc.paperweight.core.tasks.SetupMinecraftSources
import io.papermc.paperweight.core.tasks.SetupPaperScript
import io.papermc.paperweight.core.util.coreExt
import io.papermc.paperweight.patcher.extension.PaperweightPatcherExtension
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.tasks.mache.DecompileJar
import io.papermc.paperweight.tasks.mache.RunCodebook
Expand All @@ -38,7 +41,9 @@ import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
import java.nio.file.Files
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*

Expand Down Expand Up @@ -144,18 +149,29 @@ class CoreTasks(
setupPatchingTasks()
}

private fun upstreamRootDirectory(name: String): Provider<Directory> = with(project.rootProject) {
val isNestedUpstream = extensions.findByType<PaperweightPatcherExtension>()?.upstreams?.findByName(name)?.applyUpstreamNested?.orNull == true
if (isNestedUpstream) {
val applyUpstreamTask = tasks.namedOrNull<RunNestedBuild>("applyUpstream")
if (applyUpstreamTask != null) return applyUpstreamTask.flatMap { it.outputDir }
}

return tasks.namedOrNull<CheckoutRepo>("checkout${name.capitalized()}Repo")?.flatMap { it.outputDir }
?: project.upstreamsDirectory().map { it.dir(name) }
}

private fun setupPatchingTasks() {
val hasFork = project.coreExt.forks.isNotEmpty()

if (hasFork) {
project.coreExt.paper.rootDirectory.set(
project.upstreamsDirectory().map { it.dir("paper") }
upstreamRootDirectory("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) }
upstreamRootDirectory(fork.name)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MinecraftPatchingTasks(
private val outputSrcFile: Path = outputRoot.resolve("file/src/minecraft/java"),
private val tasks: TaskContainer = project.tasks
) {
private val gitMutationLockService = project.gitMutationLockService

private val taskGroup = if (readOnly) "upstream minecraft patching" else "minecraft patching"
private fun Task.group() {
group = taskGroup
Expand All @@ -89,10 +91,16 @@ class MinecraftPatchingTasks(

val applySourcePatches = tasks.register<ApplyFilePatches>("apply${namePart}SourcePatches") {
configureApplyFilePatches()
if (!readOnly) {
usesService(gitMutationLockService)
}
}

val applySourcePatchesFuzzy = tasks.register<ApplyFilePatchesFuzzy>("apply${namePart}SourcePatchesFuzzy") {
configureApplyFilePatches()
if (!readOnly) {
usesService(gitMutationLockService)
}
}

val applyResourcePatches = tasks.register<ApplyFilePatches>("apply${namePart}ResourcePatches") {
Expand All @@ -103,6 +111,9 @@ class MinecraftPatchingTasks(
output.set(outputResources)
patches.set(resourcePatchDir.fileExists())
// TODO rejects?
if (!readOnly) {
usesService(gitMutationLockService)
}
gitFilePatches.set(this@MinecraftPatchingTasks.gitFilePatches)
identifier = configName
}
Expand All @@ -120,6 +131,8 @@ class MinecraftPatchingTasks(

if (readOnly) {
base.set(applySourcePatches.flatMap { it.output })
} else {
usesService(gitMutationLockService)
}
repo.set(outputSrc)
patches.set(featurePatchDir.fileExists())
Expand Down Expand Up @@ -202,6 +215,7 @@ class MinecraftPatchingTasks(
val rebuildSourcePatches = tasks.register<RebuildFilePatches>(rebuildSourcePatchesName) {
group()
description = "Rebuilds $configName file patches to the Minecraft sources"
usesService(gitMutationLockService)

base.set(baseSources)
input.set(outputSrc)
Expand All @@ -217,6 +231,7 @@ class MinecraftPatchingTasks(
val rebuildResourcePatches = tasks.register<RebuildFilePatches>(rebuildResourcePatchesName) {
group()
description = "Rebuilds $configName file patches to the Minecraft resources"
usesService(gitMutationLockService)

base.set(baseResources)
input.set(outputResources)
Expand All @@ -234,6 +249,7 @@ class MinecraftPatchingTasks(
group()
description = "Rebuilds all $configName feature patches to the Minecraft sources"
dependsOn(rebuildFilePatches)
usesService(gitMutationLockService)

inputDir.set(outputSrc)
patchDir.set(featurePatchDir)
Expand All @@ -250,6 +266,7 @@ class MinecraftPatchingTasks(
val fixupSourcePatches = tasks.register<FixupFilePatches>("fixup${namePart}SourcePatches") {
group()
description = "Puts the currently tracked source changes into the $configName Minecraft sources file patches commit"
usesService(gitMutationLockService)

repo.set(outputSrc)
upstream.set("upstream/main")
Expand All @@ -258,6 +275,7 @@ class MinecraftPatchingTasks(
val fixupResourcePatches = tasks.register<FixupFilePatches>("fixup${namePart}ResourcePatches") {
group()
description = "Puts the currently tracked resource changes into the $configName Minecraft resources file patches commit"
usesService(gitMutationLockService)

repo.set(outputResources)
upstream.set("upstream/main")
Expand All @@ -267,6 +285,7 @@ class MinecraftPatchingTasks(
configureApplyFilePatches()
description = "Applies $configName file patches to the Minecraft sources as Git patches, moving any failed patches to the rejects dir. " +
"Useful when updating to a new Minecraft version."
usesService(gitMutationLockService)
gitFilePatches = true
moveFailedGitPatchesToRejects = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class PatchingTasks(
private val baseDir: Provider<Directory>,
private val gitFilePatches: Provider<Boolean>,
private val filterPatches: Provider<Boolean>,
private val outputDir: Path,
private val outputDir: DirectoryProperty,
private val tasks: TaskContainer = project.tasks,
) {
private val namePart: String = if (readOnly) "${forkName.capitalized()}${patchSetName.capitalized()}" else patchSetName.capitalized()
private val gitMutationLockService = project.gitMutationLockService

private fun ApplyFilePatches.configureApplyFilePatches() {
group = taskGroup
Expand All @@ -75,10 +76,16 @@ class PatchingTasks(

val applyFilePatches = tasks.register<ApplyFilePatches>("apply${namePart}FilePatches") {
configureApplyFilePatches()
if (!readOnly) {
usesService(gitMutationLockService)
}
}

val applyFilePatchesFuzzy = tasks.register<ApplyFilePatchesFuzzy>("apply${namePart}FilePatchesFuzzy") {
configureApplyFilePatches()
if (!readOnly) {
usesService(gitMutationLockService)
}
}

val applyFeaturePatches = tasks.register<ApplyFeaturePatches>("apply${namePart}FeaturePatches") {
Expand All @@ -89,6 +96,8 @@ class PatchingTasks(
repo.set(outputDir)
if (readOnly) {
base.set(applyFilePatches.flatMap { it.output })
} else {
usesService(gitMutationLockService)
}
patches.set(featurePatchDir.fileExists())
}
Expand Down Expand Up @@ -124,6 +133,7 @@ class PatchingTasks(
val rebuildFilePatches = tasks.register<RebuildFilePatches>(rebuildFilePatchesName) {
group = taskGroup
description = "Rebuilds $patchSetName file patches"
usesService(gitMutationLockService)

base.set(baseDir)
input.set(outputDir)
Expand All @@ -134,6 +144,7 @@ class PatchingTasks(
val fixupFilePatches = tasks.register<FixupFilePatches>(fixupFilePatchesName) {
group = taskGroup
description = "Puts the currently tracked source changes into the $patchSetName file patches commit"
usesService(gitMutationLockService)

repo.set(outputDir)
upstream.set("base")
Expand All @@ -143,6 +154,7 @@ class PatchingTasks(
group = taskGroup
description = "Rebuilds $patchSetName feature patches"
dependsOn(rebuildFilePatches)
usesService(gitMutationLockService)

inputDir.set(outputDir)
patchDir.set(featurePatchDir)
Expand All @@ -160,6 +172,7 @@ class PatchingTasks(
configureApplyFilePatches()
description = "Applies $patchSetName file patches as Git patches, moving any failed patches to the rejects dir. " +
"Useful when updating to a new Minecraft version."
usesService(gitMutationLockService)
gitFilePatches = true
moveFailedGitPatchesToRejects = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.papermc.paperweight.core.tasks.RunNestedBuild
import io.papermc.paperweight.core.tasks.patching.ApplySingleFilePatches
import io.papermc.paperweight.core.tasks.patching.RebuildSingleFilePatches
import io.papermc.paperweight.util.*
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
Expand All @@ -48,10 +47,17 @@ class UpstreamConfigTasks(
private val setupUpstream: TaskProvider<out RunNestedBuild>?,
private val upstreamTasks: UpstreamConfigTasks?,
) {
private fun upstreamBaseDir(): Provider<Directory> =
if (upstreamCfg.applyUpstreamNested.get()) {
setupUpstream?.flatMap { it.outputDir } ?: upstreamDir
} else {
upstreamDir
}

private fun ApplySingleFilePatches.configureApplySingleFilePatches() {
group = taskGroup
description = "Applies all ${upstreamCfg.name} single-file patches"
upstream.set(upstreamDir)
upstream.set(upstreamBaseDir())
val patches = upstreamCfg.singleFilePatchSets.map {
it.map { cfg ->
ApplySingleFilePatches.Patch.patch(target.objects, upstream) {
Expand Down Expand Up @@ -89,14 +95,14 @@ class UpstreamConfigTasks(
target.tasks.register<RebuildSingleFilePatches>("rebuild${upstreamCfg.name.capitalized()}SingleFilePatches") {
group = taskGroup
description = "Rebuilds all ${upstreamCfg.name} single-file patches"
upstream.set(upstreamDir)
val upstream = objects.directoryProperty().convention(upstreamBaseDir())
val patches = upstreamCfg.singleFilePatchSets.map {
it.map { cfg ->
val p = objects.newInstance<RebuildSingleFilePatches.Patch>()
p.path = cfg.path
p.patchFile = cfg.patchFile
p.outputFile = cfg.outputFile
p
RebuildSingleFilePatches.Patch.patch(objects, upstream) {
path = cfg.path
patchFile = cfg.patchFile
outputFile = cfg.outputFile
}
}
}
this.patches.set(patches)
Expand Down Expand Up @@ -130,7 +136,7 @@ class UpstreamConfigTasks(
base,
gitFilePatches,
filterPatches,
cfg.outputDir.path,
cfg.outputDir,
)
}

Expand All @@ -146,7 +152,7 @@ class UpstreamConfigTasks(
val input = patchingTasksForDir.applyFeaturePatches.flatMap { it.repo }
inputDir.set(input)
} else {
inputDir.set(upstreamDir.flatMap { it.dir(cfg.upstreamPath) })
inputDir.set(upstreamBaseDir().flatMap { it.dir(cfg.upstreamPath) })
}
excludes.set(cfg.excludes)
setupUpstream?.let { dependsOn(it) }
Expand All @@ -158,8 +164,9 @@ class UpstreamConfigTasks(
val task = target.tasks.register<FilterRepo>(
"filter${cfg.name.capitalized()}From${upstreamCfg.name.capitalized()}"
) {
inputDir.set(upstreamDir.flatMap { it.dir(cfg.upstreamPath) })
gitDir.set(upstreamDir.map { it.dir(".git") })
val upstreamBase = upstreamBaseDir()
inputDir.set(upstreamBase.flatMap { it.dir(cfg.upstreamPath) })
gitDir.set(upstreamBase.map { it.dir(".git") })
excludes.set(cfg.excludes)
}
return task.flatMap { it.outputDir }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.UntrackedTask
import org.gradle.internal.build.NestedRootBuildRunner
Expand All @@ -49,12 +50,16 @@ abstract class RunNestedBuild : BaseTask() {
@get:InputDirectory
abstract val projectDir: DirectoryProperty

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

@get:Internal
abstract val workDir: DirectoryProperty

override fun init() {
super.init()
workDir.convention(project.upstreamsDirectory())
outputDir.convention(projectDir)
}

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,47 @@ import codechicken.diffpatch.util.LogLevel
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import java.io.PrintStream
import javax.inject.Inject
import kotlin.io.path.*
import org.gradle.api.Action
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.*

abstract class RebuildSingleFilePatches : BaseTask() {

@get:InputDirectory
abstract val upstream: DirectoryProperty

@get:Nested
abstract val patches: ListProperty<Patch>

abstract class Patch {
abstract class Patch @Inject constructor(
objects: ObjectFactory,
upstream: DirectoryProperty,
) {
companion object {
fun patch(
objects: ObjectFactory,
upstream: DirectoryProperty,
op: Action<Patch>
): Patch {
val patch = objects.newInstance<Patch>(upstream)
op.execute(patch)
return patch
}
}

@get:Input
abstract val path: Property<String>

@get:InputFile
val upstreamFile: RegularFileProperty = objects.fileProperty().convention(upstream.file(path))

@get:InputFile
abstract val outputFile: RegularFileProperty

Expand All @@ -73,7 +90,7 @@ abstract class RebuildSingleFilePatches : BaseTask() {
tmpPatch.deleteRecursive()

val baseFile = tmpA.resolve(patch.path.get()).createParentDirectories()
upstream.path.resolve(patch.path.get()).copyTo(baseFile, true)
patch.upstreamFile.path.copyTo(baseFile, true)

val patchedFile = tmpB.resolve(patch.path.get()).createParentDirectories()
patch.outputFile.path.copyTo(patchedFile, true)
Expand Down
Loading