diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/PaperweightDependencyBridge.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/PaperweightDependencyBridge.kt new file mode 100644 index 000000000..8a513ee8c --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/PaperweightDependencyBridge.kt @@ -0,0 +1,42 @@ +/* + * 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 + +import io.papermc.paperweight.util.constants.JST_CLASSPATH_ATTRIBUTE +import io.papermc.paperweight.util.constants.JST_CLASSPATH_CONFIG +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin + +abstract class PaperweightDependencyBridge : Plugin { + override fun apply(target: Project) { + target.configurations.register(JST_CLASSPATH_CONFIG) { + isCanBeConsumed = true + attributes { + attribute(JST_CLASSPATH_ATTRIBUTE, true) + } + extendsFrom(target.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)) + } + target.rootProject.dependencies.add(JST_CLASSPATH_CONFIG, target) + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt index 00009043b..d383232fe 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/PaperweightCore.kt @@ -106,6 +106,16 @@ abstract class PaperweightCore : Plugin { } } + target.configurations.register(JST_CLASSPATH_CONFIG) { + attributes { + attribute(JST_CLASSPATH_ATTRIBUTE, true) + } + extendsFrom( + target.configurations.getByName(MACHE_MINECRAFT_CONFIG), + target.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) + ) + } + // impl extends minecraft target.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME) { extendsFrom(macheMinecraftLibrariesConfig.get()) diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/UpstreamConfig.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/UpstreamConfig.kt index c448db831..2b1dbf803 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/UpstreamConfig.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/UpstreamConfig.kt @@ -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.* @@ -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 @@ -101,6 +103,8 @@ abstract class UpstreamConfig @Inject constructor( abstract val excludes: SetProperty 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") @@ -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 fun Provider.patchedRepo(name: String): Provider = diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/MinecraftPatchingTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/MinecraftPatchingTasks.kt index 8de9acb5a..c41484812 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/MinecraftPatchingTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/MinecraftPatchingTasks.kt @@ -170,7 +170,7 @@ class MinecraftPatchingTasks( libraryImports.set(importLibFiles.flatMap { it.outputDir }) atFile.set(mergeCollectedAts.flatMap { it.outputFile }) ats.jst.from(project.configurations.named(JST_CONFIG)) - ats.jstClasspath.from(project.configurations.named(MACHE_MINECRAFT_LIBRARIES_CONFIG)) + ats.jstClasspath.from(project.configurations.named(JST_CLASSPATH_CONFIG)) } applySourcePatches.configure { diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/PatchingTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/PatchingTasks.kt index d9cf03739..ff2a41fb4 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/PatchingTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/PatchingTasks.kt @@ -22,6 +22,7 @@ package io.papermc.paperweight.core.taskcontainers +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 @@ -29,12 +30,15 @@ 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_CLASSPATH_CONFIG +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.provider.Provider import org.gradle.api.tasks.TaskContainer import org.gradle.kotlin.dsl.* @@ -48,6 +52,7 @@ class PatchingTasks( private val filePatchDir: DirectoryProperty, private val rejectsDir: DirectoryProperty, private val featurePatchDir: DirectoryProperty, + private val additionalAts: RegularFileProperty, private val baseDir: Provider, private val gitFilePatches: Provider, private val filterPatches: Provider, @@ -110,6 +115,43 @@ class PatchingTasks( } } + fun setupUpstream() { + val collectAccessTransform = tasks.register("collect${namePart}ATsFromPatches") { + patchDir.set(featurePatchDir.fileExists()) + } + + val mergeCollectedAts = tasks.register("merge${namePart}ATs") { + firstFile.set(additionalAts.fileExists()) + secondFile.set(collectAccessTransform.flatMap { it.outputFile }) + } + + val setup = tasks.register("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(JST_CLASSPATH_CONFIG)) + } + + 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(name) { + base.set(setup.flatMap { it.outputDir }) + } + } + } + private fun setupWritable() { listOf( applyFilePatches, @@ -129,6 +171,11 @@ class PatchingTasks( input.set(outputDir) patches.set(filePatchDir) gitFilePatches.set(this@PatchingTasks.gitFilePatches) + + ats.jstClasspath.from(project.configurations.named(JST_CLASSPATH_CONFIG)) + ats.jst.from(project.configurations.named(JST_CONFIG)) + atFile.set(additionalAts.fileExists()) + atFileOut.set(additionalAts.fileExists()) } val fixupFilePatches = tasks.register(fixupFilePatchesName) { diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/UpstreamConfigTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/UpstreamConfigTasks.kt index ab22724d8..322825661 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/UpstreamConfigTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/UpstreamConfigTasks.kt @@ -118,7 +118,7 @@ class UpstreamConfigTasks( createBaseFromDirectoryInRepo(cfg) } - return PatchingTasks( + val tasks = PatchingTasks( target, forkName, cfg.name, @@ -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 { diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupForkUpstreamSources.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupForkUpstreamSources.kt new file mode 100644 index 000000000..fd42e5de2 --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupForkUpstreamSources.kt @@ -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 + + @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() + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt index cbfc38877..e7b7b8cd3 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt @@ -47,7 +47,34 @@ abstract class PaperweightPatcher : Plugin { delete(target.layout.cache) } - target.afterEvaluate { afterEvaluate(patcher) } + target.configurations.register(JST_CONFIG) { + defaultDependencies { + // add(project.dependencies.create("net.neoforged.jst:jst-cli-bundle:${LibraryVersions.JST}")) + add(target.dependencies.create("io.papermc.jst:jst-cli-bundle:${LibraryVersions.JST}")) + } + } + + target.configurations.register(JST_CLASSPATH_CONFIG) { + attributes { + attribute(JST_CLASSPATH_ATTRIBUTE, true) + } + } + + target.afterEvaluate { + repositories { + maven(patcher.jstRepo) { + name = JST_REPO_NAME + content { onlyForConfigurations(JST_CONFIG) } + } + maven(PAPER_MAVEN_REPO_URL) { + content { onlyForConfigurations(JST_CLASSPATH_CONFIG) } + } + mavenCentral { + content { onlyForConfigurations(JST_CLASSPATH_CONFIG) } + } + } + afterEvaluate(patcher) + } } private fun Project.afterEvaluate(patcher: PaperweightPatcherExtension) { diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/extension/PaperweightPatcherExtension.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/extension/PaperweightPatcherExtension.kt index 18fbc9591..fb5056c68 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/extension/PaperweightPatcherExtension.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/patcher/extension/PaperweightPatcherExtension.kt @@ -23,6 +23,7 @@ package io.papermc.paperweight.patcher.extension import io.papermc.paperweight.core.extension.UpstreamConfig +import io.papermc.paperweight.util.constants.PAPER_MAVEN_REPO_URL import javax.inject.Inject import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer @@ -37,6 +38,8 @@ abstract class PaperweightPatcherExtension @Inject constructor(private val objec val gitFilePatches: Property = objects.property().convention(false) val filterPatches: Property = objects.property().convention(true) + val jstRepo: Property = objects.property().convention(PAPER_MAVEN_REPO_URL) + val upstreams: NamedDomainObjectContainer = objects.domainObjectContainer(UpstreamConfig::class) { objects.newInstance(it, true) } diff --git a/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.dependency-bridge.properties b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.dependency-bridge.properties new file mode 100644 index 000000000..8a5fb9178 --- /dev/null +++ b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.dependency-bridge.properties @@ -0,0 +1 @@ +implementation-class=io.papermc.paperweight.PaperweightDependencyBridge diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt index fc8c114a3..9e256739a 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt @@ -23,6 +23,7 @@ package io.papermc.paperweight.util.constants import org.gradle.api.Task +import org.gradle.api.attributes.Attribute const val PAPERWEIGHT_EXTENSION = "paperweight" const val PAPER_CHECKSTYLE_EXTENSION = "paperCheckstyle" @@ -53,16 +54,20 @@ const val MACHE_MINECRAFT_LIBRARIES_CONFIG = "macheMinecraftLibraries" const val MACHE_MINECRAFT_CONFIG = "macheMinecraft" const val MAPPED_JAR_OUTGOING_CONFIG = "mappedJarOutgoing" const val JST_CONFIG = "javaSourceTransformer" +const val JST_CLASSPATH_CONFIG = "jstClasspath" const val DEV_BUNDLE_CONFIG = "paperweightDevelopmentBundle" const val MOJANG_MAPPED_SERVER_CONFIG = "mojangMappedServer" const val MOJANG_MAPPED_SERVER_RUNTIME_CONFIG = "mojangMappedServerRuntime" const val REOBF_CONFIG = "reobf" +val JST_CLASSPATH_ATTRIBUTE = Attribute.of("io.papermc.paperweight.jst-classpath", Boolean::class.javaObjectType) + const val PARAM_MAPPINGS_REPO_NAME = "paperweightParamMappingsRepository" const val DECOMPILER_REPO_NAME = "paperweightDecompilerRepository" const val REMAPPER_REPO_NAME = "paperweightRemapperRepository" const val PLUGIN_REMAPPER_REPO_NAME = "paperweightPluginRemapperRepository" const val MACHE_REPO_NAME = "paperweightMacheRepository" +const val JST_REPO_NAME = "paperweightJstRepository" const val CACHE_PATH = "caches" private const val PAPER_PATH = "paperweight"