Skip to content

Commit 4934411

Browse files
committed
Import library files in separate task from SetupVanilla
This means SetupVanilla only needs to rerun when ATs or imports change, not whenever a patch changes
1 parent 66a73c9 commit 4934411

File tree

4 files changed

+95
-23
lines changed

4 files changed

+95
-23
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/SoftSpoonTasks.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import io.papermc.paperweight.tasks.softspoon.ApplyFeaturePatches
3232
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatches
3333
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatchesFuzzy
3434
import io.papermc.paperweight.tasks.softspoon.FixupFilePatches
35+
import io.papermc.paperweight.tasks.softspoon.ImportLibraryFiles
3536
import io.papermc.paperweight.tasks.softspoon.RebuildFilePatches
3637
import io.papermc.paperweight.tasks.softspoon.SetupPaperScript
3738
import io.papermc.paperweight.util.*
@@ -116,27 +117,29 @@ open class SoftSpoonTasks(
116117
secondFile.set(collectAccessTransform.flatMap { it.outputFile })
117118
}
118119

120+
val importLibraryFiles = tasks.register<ImportLibraryFiles>("importLibraryFiles") {
121+
paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir)
122+
devImports.set(project.ext.paper.devImports.fileExists(project))
123+
libraries.from(
124+
allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir },
125+
allTasks.downloadMcLibrariesSources.flatMap { it.outputDir }
126+
)
127+
}
128+
119129
private fun SetupVanilla.configureSetupMacheSources() {
120130
group = "mache"
121131

122132
mache.from(project.configurations.named(MACHE_CONFIG))
123133
macheOld.set(project.ext.macheOldPath)
124134
minecraftClasspath.from(macheMinecraftLibraries)
125-
126-
paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir)
127-
devImports.set(project.ext.paper.devImports.fileExists(project))
128-
129135
inputFile.set(macheDecompileJar.flatMap { it.outputJar })
130136
predicate.set { Files.isRegularFile(it) && it.toString().endsWith(".java") }
131137
}
132138

133139
val setupMacheSources by tasks.registering(SetupVanilla::class) {
134140
description = "Setup vanilla source dir (applying mache patches and paper ATs)."
135141
configureSetupMacheSources()
136-
libraries.from(
137-
allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir },
138-
allTasks.downloadMcLibrariesSources.flatMap { it.outputDir }
139-
)
142+
libraryImports.set(importLibraryFiles.flatMap { it.outputDir })
140143
ats.set(mergeCollectedAts.flatMap { it.outputFile })
141144
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources"))
142145
restamp.from(restampConfig)

paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/mache/SetupVanilla.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,8 @@ abstract class SetupVanilla : JavaLauncherTask() {
6464
abstract val ats: RegularFileProperty
6565

6666
@get:Optional
67-
@get:InputFiles
68-
abstract val libraries: ConfigurableFileCollection
69-
70-
@get:Optional
71-
@get:InputFiles
72-
abstract val paperPatches: ConfigurableFileCollection
73-
74-
@get:Optional
75-
@get:InputFile
76-
abstract val devImports: RegularFileProperty
67+
@get:InputDirectory
68+
abstract val libraryImports: DirectoryProperty
7769

7870
@get:Optional
7971
@get:CompileClasspath
@@ -197,9 +189,8 @@ abstract class SetupVanilla : JavaLauncherTask() {
197189
commitAndTag(git, "ATs")
198190
}
199191

200-
if (!libraries.isEmpty && !paperPatches.isEmpty) {
201-
val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() }
202-
McDev.importMcDev(patches, null, devImports.pathOrNull, outputPath, null, libraries.files.map { it.toPath() }, true, "")
192+
if (libraryImports.isPresent) {
193+
libraryImports.path.copyRecursivelyTo(outputPath)
203194

204195
commitAndTag(git, "Imports")
205196
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* paperweight is a Gradle plugin for the PaperMC project.
3+
*
4+
* Copyright (c) 2023 Kyle Wood (DenWav)
5+
* Contributors
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation;
10+
* version 2.1 only, no later versions.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20+
* USA
21+
*/
22+
23+
package io.papermc.paperweight.tasks.softspoon
24+
25+
import io.papermc.paperweight.tasks.*
26+
import io.papermc.paperweight.util.*
27+
import io.papermc.paperweight.util.constants.*
28+
import kotlin.io.path.*
29+
import org.gradle.api.file.ConfigurableFileCollection
30+
import org.gradle.api.file.DirectoryProperty
31+
import org.gradle.api.file.RegularFileProperty
32+
import org.gradle.api.tasks.InputFile
33+
import org.gradle.api.tasks.InputFiles
34+
import org.gradle.api.tasks.Optional
35+
import org.gradle.api.tasks.OutputDirectory
36+
import org.gradle.api.tasks.TaskAction
37+
38+
abstract class ImportLibraryFiles : BaseTask() {
39+
40+
@get:Optional
41+
@get:InputFiles
42+
abstract val libraries: ConfigurableFileCollection
43+
44+
@get:Optional
45+
@get:InputFiles
46+
abstract val paperPatches: ConfigurableFileCollection
47+
48+
@get:Optional
49+
@get:InputFile
50+
abstract val devImports: RegularFileProperty
51+
52+
@get:OutputDirectory
53+
abstract val outputDir: DirectoryProperty
54+
55+
override fun init() {
56+
super.init()
57+
outputDir.set(layout.cache.resolve(paperTaskOutput()))
58+
}
59+
60+
@TaskAction
61+
fun run() {
62+
outputDir.path.deleteRecursive()
63+
outputDir.path.createDirectories()
64+
if (!libraries.isEmpty && !paperPatches.isEmpty) {
65+
val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() }
66+
McDev.importMcDev(
67+
patches,
68+
null,
69+
devImports.pathOrNull,
70+
outputDir.path,
71+
null,
72+
libraries.files.map { it.toPath() },
73+
true,
74+
""
75+
)
76+
}
77+
}
78+
}

paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,5 @@ private const val MACHE_PATH = "$PAPER_PATH/mache"
129129
const val BASE_PROJECT = "$MACHE_PATH/base"
130130

131131
fun paperSetupOutput(name: String, ext: String) = "$SETUP_CACHE/$name.$ext"
132-
fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext)
133-
fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext"
132+
fun Task.paperTaskOutput(ext: String? = null) = paperTaskOutput(name, ext)
133+
fun paperTaskOutput(name: String, ext: String? = null) = "$TASK_CACHE/$name" + (ext?.let { ".$it" } ?: "")

0 commit comments

Comments
 (0)