diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/SoftSpoonTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/SoftSpoonTasks.kt index b6d0ad323..489f89246 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/SoftSpoonTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/SoftSpoonTasks.kt @@ -32,6 +32,7 @@ import io.papermc.paperweight.tasks.softspoon.ApplyFeaturePatches import io.papermc.paperweight.tasks.softspoon.ApplyFilePatches import io.papermc.paperweight.tasks.softspoon.ApplyFilePatchesFuzzy import io.papermc.paperweight.tasks.softspoon.FixupFilePatches +import io.papermc.paperweight.tasks.softspoon.ImportLibraryFiles import io.papermc.paperweight.tasks.softspoon.RebuildFilePatches import io.papermc.paperweight.tasks.softspoon.SetupPaperScript import io.papermc.paperweight.util.* @@ -116,16 +117,21 @@ open class SoftSpoonTasks( secondFile.set(collectAccessTransform.flatMap { it.outputFile }) } + val importLibraryFiles = tasks.register("importLibraryFiles") { + paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir) + devImports.set(project.ext.paper.devImports.fileExists(project)) + libraries.from( + allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir }, + allTasks.downloadMcLibrariesSources.flatMap { it.outputDir } + ) + } + private fun SetupVanilla.configureSetupMacheSources() { group = "mache" mache.from(project.configurations.named(MACHE_CONFIG)) macheOld.set(project.ext.macheOldPath) minecraftClasspath.from(macheMinecraftLibraries) - - paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir) - devImports.set(project.ext.paper.devImports.fileExists(project)) - inputFile.set(macheDecompileJar.flatMap { it.outputJar }) predicate.set { Files.isRegularFile(it) && it.toString().endsWith(".java") } } @@ -133,10 +139,7 @@ open class SoftSpoonTasks( val setupMacheSources by tasks.registering(SetupVanilla::class) { description = "Setup vanilla source dir (applying mache patches and paper ATs)." configureSetupMacheSources() - libraries.from( - allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir }, - allTasks.downloadMcLibrariesSources.flatMap { it.outputDir } - ) + libraryImports.set(importLibraryFiles.flatMap { it.outputDir }) ats.set(mergeCollectedAts.flatMap { it.outputFile }) outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources")) restamp.from(restampConfig) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/SetupVanilla.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/SetupVanilla.kt index 82e78f1f2..f3523e7b2 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/SetupVanilla.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/SetupVanilla.kt @@ -64,16 +64,8 @@ abstract class SetupVanilla : JavaLauncherTask() { abstract val ats: RegularFileProperty @get:Optional - @get:InputFiles - abstract val libraries: ConfigurableFileCollection - - @get:Optional - @get:InputFiles - abstract val paperPatches: ConfigurableFileCollection - - @get:Optional - @get:InputFile - abstract val devImports: RegularFileProperty + @get:InputDirectory + abstract val libraryImports: DirectoryProperty @get:Optional @get:CompileClasspath @@ -197,9 +189,8 @@ abstract class SetupVanilla : JavaLauncherTask() { commitAndTag(git, "ATs") } - if (!libraries.isEmpty && !paperPatches.isEmpty) { - val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() } - McDev.importMcDev(patches, null, devImports.pathOrNull, outputPath, null, libraries.files.map { it.toPath() }, true, "") + if (libraryImports.isPresent) { + libraryImports.path.copyRecursivelyTo(outputPath) commitAndTag(git, "Imports") } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/softspoon/ImportLibraryFiles.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/softspoon/ImportLibraryFiles.kt new file mode 100644 index 000000000..6534bfab7 --- /dev/null +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/softspoon/ImportLibraryFiles.kt @@ -0,0 +1,78 @@ +/* + * 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.tasks.softspoon + +import io.papermc.paperweight.tasks.* +import io.papermc.paperweight.util.* +import io.papermc.paperweight.util.constants.* +import kotlin.io.path.* +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +abstract class ImportLibraryFiles : BaseTask() { + + @get:Optional + @get:InputFiles + abstract val libraries: ConfigurableFileCollection + + @get:Optional + @get:InputFiles + abstract val paperPatches: ConfigurableFileCollection + + @get:Optional + @get:InputFile + abstract val devImports: RegularFileProperty + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty + + override fun init() { + super.init() + outputDir.set(layout.cache.resolve(paperTaskOutput())) + } + + @TaskAction + fun run() { + outputDir.path.deleteRecursive() + outputDir.path.createDirectories() + if (!libraries.isEmpty && !paperPatches.isEmpty) { + val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() } + McDev.importMcDev( + patches, + null, + devImports.pathOrNull, + outputDir.path, + null, + libraries.files.map { it.toPath() }, + true, + "" + ) + } + } +} 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 a5a82451e..52ee8edff 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 @@ -129,5 +129,5 @@ private const val MACHE_PATH = "$PAPER_PATH/mache" const val BASE_PROJECT = "$MACHE_PATH/base" fun paperSetupOutput(name: String, ext: String) = "$SETUP_CACHE/$name.$ext" -fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext) -fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext" +fun Task.paperTaskOutput(ext: String? = null) = paperTaskOutput(name, ext) +fun paperTaskOutput(name: String, ext: String? = null) = "$TASK_CACHE/$name" + (ext?.let { ".$it" } ?: "")