diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt index e79c8fd..9f9d6ae 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt @@ -57,7 +57,6 @@ open class AllTasks( val copyResources by tasks.registering { inputJar.set(applyMergedAt.flatMap { it.outputJar }) vanillaJar.set(extractFromBundler.flatMap { it.serverJar }) - includes.set(listOf("/data/**", "/assets/**", "version.json", "yggdrasil_session_pubkey.der", "pack.mcmeta", "flightrecorder-config.jfc")) } val decompileJar by tasks.registering { diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/PaperweightSourceGeneratorHelper.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/PaperweightSourceGeneratorHelper.kt new file mode 100644 index 0000000..9ab54dc --- /dev/null +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/PaperweightSourceGeneratorHelper.kt @@ -0,0 +1,75 @@ +/* + * 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.extension.PaperweightSourceGeneratorExt +import io.papermc.paperweight.tasks.* +import io.papermc.paperweight.util.* +import io.papermc.paperweight.util.constants.* +import kotlin.io.path.* +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.* + +abstract class PaperweightSourceGeneratorHelper : Plugin { + override fun apply(target: Project) = with(target) { + val ext = extensions.create("paperweight", PaperweightSourceGeneratorExt::class) + + val applyAts by tasks.registering { + inputJar.set(rootProject.tasks.named("fixJar").flatMap { it.outputJar }) + atFile.set(ext.atFile) + } + + val copyResources by tasks.registering { + inputJar.set(applyAts.flatMap { it.outputJar }) + vanillaJar.set(rootProject.tasks.named("extractFromBundler").flatMap { it.serverJar }) + } + + val libsFile = rootProject.layout.cache.resolve(SERVER_LIBRARIES_TXT) + val vanilla = configurations.register("vanillaServer") { + withDependencies { + dependencies { + val libs = libsFile.convertToPathOrNull() + if (libs != null && libs.exists()) { + libs.forEachLine { line -> + add(create(line)) + } + } + } + } + } + + dependencies { + vanilla.name(files(copyResources.flatMap { it.outputJar })) + } + + + afterEvaluate { + if (ext.addVanillaServerToImplementation.get()) { + configurations.named("implementation") { + extendsFrom(vanilla.get()) + } + } + } + } +} diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/PaperweightSourceGeneratorExt.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/PaperweightSourceGeneratorExt.kt new file mode 100644 index 0000000..9244a57 --- /dev/null +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/extension/PaperweightSourceGeneratorExt.kt @@ -0,0 +1,36 @@ +/* + * 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.extension + +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property + +@Suppress("LeakingThis") +abstract class PaperweightSourceGeneratorExt { + abstract val atFile: RegularFileProperty + abstract val addVanillaServerToImplementation: Property + + init { + addVanillaServerToImplementation.convention(true) + } +} diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CopyResources.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CopyResources.kt index 1063f7d..4259e46 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CopyResources.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CopyResources.kt @@ -49,6 +49,16 @@ abstract class CopyResources : BaseTask() { override fun init() { outputJar.convention(defaultOutput()) + includes.convention( + listOf( + "/data/**", + "/assets/**", + "version.json", + "yggdrasil_session_pubkey.der", + "pack.mcmeta", + "flightrecorder-config.jfc", + ) + ) } @TaskAction