Skip to content

Commit 5e28021

Browse files
authored
Make SetupMinecraftSources cacheable (#329)
To preserve the Git repo integrity we must zip the outputs ourselves
1 parent a181c63 commit 5e28021

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package io.papermc.paperweight.core.taskcontainers
2424

2525
import io.papermc.paperweight.PaperweightException
2626
import io.papermc.paperweight.core.extension.ForkConfig
27+
import io.papermc.paperweight.core.tasks.ExtractMinecraftSources
2728
import io.papermc.paperweight.core.tasks.ImportLibraryFiles
2829
import io.papermc.paperweight.core.tasks.IndexLibraryFiles
2930
import io.papermc.paperweight.core.tasks.SetupMinecraftSources
@@ -106,16 +107,26 @@ class CoreTasks(
106107
description = "Setup Minecraft source dir (applying mache patches and paper ATs)."
107108
configureSetupMacheSources()
108109
libraryImports.set(importLibraryFiles.flatMap { it.outputDir })
109-
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources"))
110+
outputZip.set(layout.cache.resolve(BASE_PROJECT).resolve("sources.zip"))
110111

111112
atFile.set(mergePaperATs.flatMap { it.outputFile })
112113
ats.jstClasspath.from(project.configurations.named(MACHE_MINECRAFT_LIBRARIES_CONFIG))
113114
ats.jst.from(project.configurations.named(JST_CONFIG))
114115
}
115116

117+
val extractMacheSources by tasks.registering(ExtractMinecraftSources::class) {
118+
zip.set(setupMacheSources.flatMap { it.outputZip })
119+
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources"))
120+
}
121+
116122
val setupMacheSourcesForDevBundle by tasks.registering(SetupMinecraftSources::class) {
117123
description = "Setup Minecraft source dir (applying mache patches)."
118124
configureSetupMacheSources()
125+
outputZip.set(layout.cache.resolve(BASE_PROJECT).resolve("sources_dev_bundle.zip"))
126+
}
127+
128+
val extractMacheSourcesForDevBundle by tasks.registering(ExtractMinecraftSources::class) {
129+
zip.set(setupMacheSourcesForDevBundle.flatMap { it.outputZip })
119130
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources_dev_bundle"))
120131
}
121132

@@ -124,6 +135,11 @@ class CoreTasks(
124135

125136
inputFile.set(extractFromBundler.flatMap { it.serverJar })
126137
predicate.set { Files.isRegularFile(it) && !it.toString().endsWith(".class") }
138+
outputZip.set(layout.cache.resolve(BASE_PROJECT).resolve("resources.zip"))
139+
}
140+
141+
val extractMacheResources by tasks.registering(ExtractMinecraftSources::class) {
142+
zip.set(setupMacheResources.flatMap { it.outputZip })
127143
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("resources"))
128144
}
129145

@@ -174,8 +190,8 @@ class CoreTasks(
174190
project.coreExt.paper.resourcePatchDir,
175191
project.coreExt.paper.featurePatchDir,
176192
project.coreExt.paper.additionalAts,
177-
setupMacheSources.flatMap { it.outputDir },
178-
setupMacheResources.flatMap { it.outputDir },
193+
extractMacheSources.flatMap { it.outputDir },
194+
extractMacheResources.flatMap { it.outputDir },
179195
project.coreExt.gitFilePatches,
180196
project.coreExt.filterPatches,
181197
paperOutputRoot,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DevBundleTasks(
6464
.getByName("main")
6565
.allJava
6666
)
67-
vanillaJavaDir.set(coreTasks.setupMacheSourcesForDevBundle.flatMap { it.outputDir })
67+
vanillaJavaDir.set(coreTasks.extractMacheSourcesForDevBundle.flatMap { it.outputDir })
6868

6969
minecraftVersion.set(project.coreExt.minecraftVersion)
7070
mojangMappedPaperclipFile.set(paperclipForDevBundle.flatMap { it.outputZip })
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.core.tasks
24+
25+
import io.papermc.paperweight.tasks.BaseTask
26+
import io.papermc.paperweight.util.deleteRecursive
27+
import io.papermc.paperweight.util.path
28+
import io.papermc.paperweight.util.unzip
29+
import org.gradle.api.file.DirectoryProperty
30+
import org.gradle.api.file.RegularFileProperty
31+
import org.gradle.api.tasks.InputFile
32+
import org.gradle.api.tasks.OutputDirectory
33+
import org.gradle.api.tasks.TaskAction
34+
35+
// To make the Git repos cacheable they must be zipped, this tasks extracts them again...
36+
abstract class ExtractMinecraftSources : BaseTask() {
37+
@get:InputFile
38+
abstract val zip: RegularFileProperty
39+
40+
@get:OutputDirectory
41+
abstract val outputDir: DirectoryProperty
42+
43+
@TaskAction
44+
fun run() {
45+
val output = outputDir.path
46+
output.deleteRecursive()
47+
unzip(zip, output)
48+
}
49+
}

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupMinecraftSources.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import org.gradle.api.provider.Property
4646
import org.gradle.api.tasks.*
4747
import org.gradle.kotlin.dsl.*
4848

49-
abstract class SetupMinecraftSources : JavaLauncherTask() {
49+
@CacheableTask
50+
abstract class SetupMinecraftSources : JavaLauncherZippedTask() {
5051

5152
@get:PathSensitive(PathSensitivity.NONE)
5253
@get:InputFile
@@ -55,11 +56,9 @@ abstract class SetupMinecraftSources : JavaLauncherTask() {
5556
@get:Internal
5657
abstract val predicate: Property<Predicate<Path>>
5758

58-
@get:OutputDirectory
59-
abstract val outputDir: DirectoryProperty
60-
6159
@get:Optional
6260
@get:InputDirectory
61+
@get:PathSensitive(PathSensitivity.RELATIVE)
6362
abstract val libraryImports: DirectoryProperty
6463

6564
@get:Optional
@@ -75,12 +74,10 @@ abstract class SetupMinecraftSources : JavaLauncherTask() {
7574

7675
@get:InputFile
7776
@get:Optional
77+
@get:PathSensitive(PathSensitivity.NONE)
7878
abstract val atFile: RegularFileProperty
7979

80-
@TaskAction
81-
fun run() {
82-
val outputPath = outputDir.convertToPath()
83-
80+
override fun run(outputPath: Path) {
8481
val git: Git
8582
if (oldPaperCommit.isPresent) {
8683
val oldPaperDir = setupOldPaper()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ import java.nio.file.Path
2929
import kotlin.io.path.*
3030
import org.gradle.api.file.DirectoryProperty
3131
import org.gradle.api.file.RegularFileProperty
32-
import org.gradle.api.tasks.CacheableTask
3332
import org.gradle.api.tasks.Classpath
3433
import org.gradle.api.tasks.OutputDirectory
3534
import org.gradle.api.tasks.OutputFile
3635
import org.gradle.api.tasks.TaskAction
3736

38-
@CacheableTask
3937
abstract class ExtractFromBundler : BaseTask() {
4038

4139
@get:Classpath

0 commit comments

Comments
 (0)