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 @@ -28,6 +28,8 @@ import io.papermc.paperweight.core.extension.PaperweightCoreExtension
import io.papermc.paperweight.core.taskcontainers.CoreTasks
import io.papermc.paperweight.core.taskcontainers.DevBundleTasks
import io.papermc.paperweight.core.taskcontainers.PaperclipTasks
import io.papermc.paperweight.core.tasks.SetupForkUpstreamSources
import io.papermc.paperweight.core.tasks.patching.RebuildFilePatches
import io.papermc.paperweight.core.tasks.patchroulette.PatchRouletteTasks
import io.papermc.paperweight.core.util.coreExt
import io.papermc.paperweight.core.util.createBuildTasks
Expand All @@ -49,6 +51,7 @@ import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.withType

abstract class PaperweightCore : Plugin<Project> {
@get:Inject
Expand Down Expand Up @@ -189,6 +192,17 @@ abstract class PaperweightCore : Plugin<Project> {
mache.get().addRepositories(this)
mache.get().addDependencies(this)

// attach the mache minecraft jar so JST can properly create binary representations
target.tasks.withType<SetupForkUpstreamSources>().configureEach {
dependsOn(target.tasks.named("macheRemapJar"))
ats.jstClasspath.from(target.configurations.named(MACHE_MINECRAFT_CONFIG))
}

target.tasks.withType<RebuildFilePatches>().configureEach {
dependsOn(target.tasks.named("macheRemapJar"))
ats.jstClasspath.from(target.configurations.named(MACHE_MINECRAFT_CONFIG))
}

tasks.afterEvaluate()

devBundleTasks.configureAfterEvaluate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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.api.provider.ProviderFactory
import org.gradle.api.provider.SetProperty
import org.gradle.kotlin.dsl.*

Expand Down Expand Up @@ -93,6 +94,7 @@ abstract class UpstreamConfig @Inject constructor(

abstract class DirectoryPatchSet @Inject constructor(
objects: ObjectFactory,
providers: ProviderFactory,
private val setName: String,
) : Named {
override fun getName(): String = setName
Expand All @@ -101,6 +103,8 @@ abstract class UpstreamConfig @Inject constructor(
abstract val excludes: SetProperty<String>

abstract val outputDir: DirectoryProperty
val buildDataDir: DirectoryProperty = objects.directoryProperty().convention(outputDir.dir("../build-data"))
val additionalAts: RegularFileProperty = objects.fileFrom(buildDataDir, providers.provider { "$name.at" })

abstract val patchesDir: DirectoryProperty
val rejectsDir: DirectoryProperty = objects.dirFrom(patchesDir, "rejected")
Expand All @@ -110,8 +114,9 @@ abstract class UpstreamConfig @Inject constructor(

abstract class RepoPatchSet @Inject constructor(
objects: ObjectFactory,
providers: ProviderFactory,
name: String,
) : DirectoryPatchSet(objects, name) {
) : DirectoryPatchSet(objects, providers, name) {
abstract val upstreamRepo: Property<DirectoryPatchSet>

fun Provider<ForkConfig>.patchedRepo(name: String): Provider<DirectoryPatchSet> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@

package io.papermc.paperweight.core.taskcontainers

import io.papermc.paperweight.core.PaperweightCore
import io.papermc.paperweight.core.tasks.SetupForkUpstreamSources
import io.papermc.paperweight.core.tasks.patching.ApplyFeaturePatches
import io.papermc.paperweight.core.tasks.patching.ApplyFilePatches
import io.papermc.paperweight.core.tasks.patching.ApplyFilePatchesFuzzy
import io.papermc.paperweight.core.tasks.patching.FixupFilePatches
import io.papermc.paperweight.core.tasks.patching.RebuildFilePatches
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.JST_CONFIG
import io.papermc.paperweight.util.constants.paperTaskOutput
import java.nio.file.Path
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*
Expand All @@ -48,6 +53,7 @@ class PatchingTasks(
private val filePatchDir: DirectoryProperty,
private val rejectsDir: DirectoryProperty,
private val featurePatchDir: DirectoryProperty,
private val additionalAts: RegularFileProperty,
private val baseDir: Provider<Directory>,
private val gitFilePatches: Provider<Boolean>,
private val filterPatches: Provider<Boolean>,
Expand Down Expand Up @@ -110,6 +116,52 @@ class PatchingTasks(
}
}

fun setupUpstream() {
val collectAccessTransform = tasks.register<CollectATsFromPatches>("collect${namePart}ATsFromPatches") {
patchDir.set(featurePatchDir.fileExists())
}

val mergeCollectedAts = tasks.register<MergeAccessTransforms>("merge${namePart}ATs") {
firstFile.set(additionalAts.fileExists())
secondFile.set(collectAccessTransform.flatMap { it.outputFile })
}

val setup = tasks.register<SetupForkUpstreamSources>("run${namePart}Setup") {
description = "Applies $forkName ATs to $namePart sources"

inputDir.set(baseDir)
outputDir.set(layout.cache.resolve(paperTaskOutput()))
identifier.set(namePart)

atFile.set(mergeCollectedAts.flatMap { it.outputFile })
ats.jst.from(project.configurations.named(JST_CONFIG))
ats.jstClasspath.from(
project.configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME),
project.subprojects.mapNotNull {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapNotNull and then returning null. Shouldn't that fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, mapNotNull is for accepting elements that aren’t null and skipping those that are.

This whole logic tbh is a bit not to my liking as i’m worried if this won’t cause issues further down the road with isolated projects in gradle, so a better solution has to be found; Unfortunately it would probably mean rewriting paperweight to treat the api projects the same way as server projects and not pin them under the root project which is an effort i didn’t want to undertake as i’m not sure if that’s something remotely desirable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks. Didn't expect that it merges map and filter(nonNull) together.

if (!it.plugins.hasPlugin(PaperweightCore::class)) {
it.configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).map { it.files }
} else {
null
}
}
)
}

applyFilePatches.configure {
input.set(setup.flatMap { it.outputDir })
}

applyFilePatchesFuzzy.configure {
input.set(setup.flatMap { it.outputDir })
}
val name = "rebuild${namePart}FilePatches"
if (name in tasks.names) {
tasks.named<RebuildFilePatches>(name) {
base.set(setup.flatMap { it.outputDir })
}
}
}

private fun setupWritable() {
listOf(
applyFilePatches,
Expand All @@ -129,6 +181,20 @@ class PatchingTasks(
input.set(outputDir)
patches.set(filePatchDir)
gitFilePatches.set(this@PatchingTasks.gitFilePatches)

ats.jstClasspath.from(
project.configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME),
project.subprojects.mapNotNull {
if (!it.plugins.hasPlugin(PaperweightCore::class)) {
it.configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).map { it.files }
} else {
null
}
}
)
ats.jst.from(project.configurations.named(JST_CONFIG))
atFile.set(additionalAts.fileExists())
atFileOut.set(additionalAts.fileExists())
}

val fixupFilePatches = tasks.register<FixupFilePatches>(fixupFilePatchesName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class UpstreamConfigTasks(
createBaseFromDirectoryInRepo(cfg)
}

return PatchingTasks(
val tasks = PatchingTasks(
target,
forkName,
cfg.name,
Expand All @@ -127,11 +127,14 @@ class UpstreamConfigTasks(
cfg.filePatchDir,
cfg.rejectsDir,
cfg.featurePatchDir,
cfg.additionalAts,
base,
gitFilePatches,
filterPatches,
cfg.outputDir.path,
)
tasks.setupUpstream()
return tasks
}

private fun createBaseFromRepo(cfg: UpstreamConfig.RepoPatchSet): Provider<Directory> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* paperweight is a Gradle plugin for the PaperMC project.
*
* Copyright (c) 2023 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/

package io.papermc.paperweight.core.tasks

import io.papermc.paperweight.core.util.ApplySourceATs
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import kotlin.io.path.*
import org.eclipse.jgit.api.Git
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
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.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.*

abstract class SetupForkUpstreamSources : JavaLauncherTask() {

@get:InputDirectory
abstract val inputDir: DirectoryProperty

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

@get:Nested
val ats: ApplySourceATs = objects.newInstance()

@get:InputFile
@get:Optional
abstract val atFile: RegularFileProperty

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

@TaskAction
fun run() {
val out = outputDir.path.cleanDir()
inputDir.path.copyRecursivelyTo(out)

val git = Git.open(outputDir.path.toFile())

if (atFile.isPresent && atFile.path.readText().isNotBlank()) {
println("Applying access transformers...")
ats.run(
launcher.get(),
inputDir.path,
outputDir.path,
atFile.path,
temporaryDir.toPath(),
)
commitAndTag(git, "ATs", "${identifier.get()} ATs")
}
commitAndTag(git, "base")

git.close()
}
}
Loading