Skip to content

Commit 13eaac0

Browse files
committed
Move downloads from DownloadService to using Gradle Configurations
1 parent abfb717 commit 13eaac0

31 files changed

+480
-919
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group = io.papermc.paperweight
2-
version = 1.1.12
2+
version = 1.1.13-SNAPSHOT

gradle/libs.versions.toml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ hypo = "1.2.1"
77
asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" }
88
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
99

10-
httpclient = "org.apache.httpcomponents:httpclient:4.5.13"
1110
kotson = "com.github.salomonbrys.kotson:kotson:2.5.0"
1211

1312
cadix-lorenz-core = { module = "org.cadixdev:lorenz", version.ref = "lorenz" }

paperweight-core/src/main/kotlin/PaperweightCore.kt

+5-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
package io.papermc.paperweight.core
2424

25-
import io.papermc.paperweight.DownloadService
2625
import io.papermc.paperweight.core.extension.PaperweightCoreExtension
2726
import io.papermc.paperweight.core.taskcontainers.AllTasks
2827
import io.papermc.paperweight.core.tasks.PaperweightCoreUpstreamData
@@ -46,8 +45,6 @@ class PaperweightCore : Plugin<Project> {
4645

4746
val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class)
4847

49-
target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {}
50-
5148
target.tasks.register<Delete>("cleanCache") {
5249
group = "paper"
5350
description = "Delete the project setup cache and task outputs."
@@ -69,7 +66,7 @@ class PaperweightCore : Plugin<Project> {
6966
devBundleTasks.configure(
7067
ext.serverProject,
7168
ext.minecraftVersion,
72-
tasks.downloadServerJar.map { it.outputJar.path },
69+
tasks.serverJar.map { it.path },
7370
tasks.decompileJar.map { it.outputJar.path },
7471
tasks.inspectVanillaJar.map { it.serverLibraries.path },
7572
tasks.mergeAdditionalAts.map { it.outputFile.path }
@@ -89,13 +86,11 @@ class PaperweightCore : Plugin<Project> {
8986

9087
target.tasks.register<PaperweightCoreUpstreamData>(PAPERWEIGHT_PREPARE_DOWNSTREAM) {
9188
dependsOn(tasks.applyPatches)
92-
vanillaJar.set(tasks.downloadServerJar.flatMap { it.outputJar })
89+
vanillaJar.set(tasks.serverJar)
9390
remappedJar.set(tasks.copyResources.flatMap { it.outputJar })
9491
decompiledJar.set(tasks.decompileJar.flatMap { it.outputJar })
9592
mcVersion.set(target.ext.minecraftVersion)
9693
mcLibrariesFile.set(tasks.inspectVanillaJar.flatMap { it.serverLibraries })
97-
mcLibrariesDir.set(tasks.downloadMcLibraries.flatMap { it.outputDir })
98-
mcLibrariesSourcesDir.set(tasks.downloadMcLibraries.flatMap { it.sourcesOutputDir })
9994
mappings.set(tasks.patchMappings.flatMap { it.outputMappings })
10095
notchToSpigotMappings.set(tasks.generateSpigotMappings.flatMap { it.notchToSpigotMappings })
10196
sourceMappings.set(tasks.generateMappings.flatMap { it.outputMappings })
@@ -157,7 +152,7 @@ class PaperweightCore : Plugin<Project> {
157152
} ?: return@afterEvaluate
158153

159154
val generatePaperclipPatch by target.tasks.registering<GeneratePaperclipPatch> {
160-
originalJar.set(tasks.downloadServerJar.flatMap { it.outputJar })
155+
originalJar.set(tasks.serverJar)
161156
patchedJar.set(reobfJar.flatMap { it.outputJar })
162157
mcVersion.set(target.ext.minecraftVersion)
163158
}
@@ -196,14 +191,14 @@ class PaperweightCore : Plugin<Project> {
196191
// Pull in as many jars as possible to reduce the possibility of type bindings not resolving
197192
classpathJars.from(allTasks.applyMergedAt.flatMap { it.outputJar }.get()) // final remapped jar
198193
classpathJars.from(allTasks.remapSpigotSources.flatMap { it.vanillaRemappedSpigotJar }.get()) // Spigot remapped jar
199-
classpathJars.from(allTasks.downloadServerJar.flatMap { it.outputJar }.get()) // pure vanilla jar
194+
classpathJars.from(allTasks.serverJar) // pure vanilla jar
200195

201196
spigotApiDir.set(allTasks.patchSpigotApi.flatMap { it.outputDir }.get())
202197
spigotServerDir.set(allTasks.patchSpigotServer.flatMap { it.outputDir }.get())
203198
spigotDecompJar.set(allTasks.spigotDecompileJar.flatMap { it.outputJar }.get())
204199

205200
// library class imports
206-
mcLibrarySourcesDir.set(allTasks.downloadMcLibraries.flatMap { it.sourcesOutputDir }.get())
201+
mcLibrariesSources.from(allTasks.minecraftLibrariesSources)
207202
devImports.set(extension.paper.devImports)
208203

209204
outputPatchDir.set(extension.paper.remappedSpigotServerPatchDir)

paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ open class AllTasks(
5353

5454
val copyResources by tasks.registering<CopyResources> {
5555
inputJar.set(applyMergedAt.flatMap { it.outputJar })
56-
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
56+
vanillaJar.set(serverJar)
5757
includes.set(listOf("/data/**", "/assets/**", "version.json", "yggdrasil_session_pubkey.der", "pack.mcmeta"))
5858

5959
outputJar.set(cache.resolve(FINAL_REMAPPED_JAR))
@@ -63,7 +63,7 @@ open class AllTasks(
6363
executable.from(project.configurations.named(DECOMPILER_CONFIG))
6464

6565
inputJar.set(copyResources.flatMap { it.outputJar })
66-
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
66+
libraries.from(minecraftLibraries)
6767

6868
outputJar.set(cache.resolve(FINAL_DECOMPILE_JAR))
6969
}
@@ -102,7 +102,7 @@ open class AllTasks(
102102
caseOnlyClassNameChanges.set(cleanupMappings.flatMap { it.caseOnlyNameChanges })
103103
upstreamDir.set(patchSpigotServer.flatMap { it.outputDir })
104104
sourceMcDevJar.set(decompileJar.flatMap { it.outputJar })
105-
mcLibrariesDir.set(downloadMcLibraries.flatMap { it.sourcesOutputDir })
105+
mcLibrariesSources.from(minecraftLibrariesSources)
106106
devImports.set(extension.paper.devImports.fileExists(project))
107107
unneededFiles.value(listOf("nms-patches", "applyPatches.sh", "CONTRIBUTING.md", "makePatches.sh", "README.md"))
108108

paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ open class GeneralTasks(
4747
}
4848

4949
val filterVanillaJar by tasks.registering<FilterJar> {
50-
inputJar.set(downloadServerJar.flatMap { it.outputJar })
50+
inputJar.set(serverJar)
5151
includes.set(extension.vanillaJarIncludes)
5252
}
5353
}

paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt

+24-57
Original file line numberDiff line numberDiff line change
@@ -26,78 +26,45 @@ import com.github.salomonbrys.kotson.array
2626
import com.github.salomonbrys.kotson.get
2727
import com.github.salomonbrys.kotson.string
2828
import com.google.gson.JsonObject
29-
import io.papermc.paperweight.DownloadService
3029
import io.papermc.paperweight.core.ext
3130
import io.papermc.paperweight.core.extension.PaperweightCoreExtension
32-
import io.papermc.paperweight.tasks.*
3331
import io.papermc.paperweight.util.*
3432
import io.papermc.paperweight.util.constants.*
35-
import java.nio.file.Path
3633
import org.gradle.api.Project
37-
import org.gradle.api.provider.Provider
38-
import org.gradle.api.tasks.TaskContainer
39-
import org.gradle.kotlin.dsl.*
4034

4135
@Suppress("MemberVisibilityCanBePrivate")
4236
open class InitialTasks(
4337
project: Project,
44-
tasks: TaskContainer = project.tasks,
45-
cache: Path = project.layout.cache,
4638
extension: PaperweightCoreExtension = project.ext,
47-
downloadService: Provider<DownloadService> = project.download
4839
) {
4940

50-
val downloadMcManifest by tasks.registering<DownloadTask> {
51-
url.set(MC_MANIFEST_URL)
52-
outputFile.set(cache.resolve(MC_MANIFEST))
41+
private val mcManifest = project.downloadFile(MC_MANIFEST_URL, MINECRAFT_MANIFEST)
42+
.map { gson.fromJson<MinecraftManifest>(it) }
5343

54-
outputs.upToDateWhen { false }
44+
private val versionManifest = project.downloadFile(
45+
mcManifest.zip(extension.minecraftVersion) { manifest, version ->
46+
manifest.versions.first { it.id == version }.url
47+
},
48+
MINECRAFT_VERSION_MANIFEST
49+
).map { gson.fromJson<JsonObject>(it) }
5550

56-
downloader.set(downloadService)
51+
val minecraftLibrariesList = versionManifest.map { version ->
52+
version["libraries"].array.map { library ->
53+
library["name"].string
54+
}
5755
}
58-
private val mcManifest = downloadMcManifest.flatMap { it.outputFile }.map { gson.fromJson<MinecraftManifest>(it) }
5956

60-
val downloadMcVersionManifest by tasks.registering<DownloadTask> {
61-
url.set(
62-
mcManifest.zip(extension.minecraftVersion) { manifest, version ->
63-
manifest.versions.first { it.id == version }.url
64-
}
65-
)
66-
outputFile.set(cache.resolve(VERSION_JSON))
57+
val serverMappings = project.downloadFile(
58+
versionManifest.map { version ->
59+
version["downloads"]["server_mappings"]["url"].string
60+
},
61+
MOJANG_SERVER_MAPPINGS
62+
)
6763

68-
downloader.set(downloadService)
69-
}
70-
private val versionManifest = downloadMcVersionManifest.flatMap { it.outputFile }.map { gson.fromJson<JsonObject>(it) }
71-
72-
val setupMcLibraries by tasks.registering<SetupMcLibraries> {
73-
dependencies.set(
74-
versionManifest.map { version ->
75-
version["libraries"].array.map { library ->
76-
library["name"].string
77-
}
78-
}
79-
)
80-
outputFile.set(cache.resolve(MC_LIBRARIES))
81-
}
82-
83-
val downloadMappings by tasks.registering<DownloadTask> {
84-
url.set(
85-
versionManifest.map { version ->
86-
version["downloads"]["server_mappings"]["url"].string
87-
}
88-
)
89-
outputFile.set(cache.resolve(SERVER_MAPPINGS))
90-
91-
downloader.set(downloadService)
92-
}
93-
94-
val downloadServerJar by tasks.registering<DownloadServerJar> {
95-
downloadUrl.set(
96-
versionManifest.map { version ->
97-
version["downloads"]["server"]["url"].string
98-
}
99-
)
100-
101-
downloader.set(downloadService)
102-
}
64+
val serverJar = project.downloadFile(
65+
versionManifest.map { version ->
66+
version["downloads"]["server"]["url"].string
67+
},
68+
VANILLA_SERVER_JAR
69+
)
10370
}

paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt

+13-18
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222

2323
package io.papermc.paperweight.core.taskcontainers
2424

25-
import io.papermc.paperweight.DownloadService
2625
import io.papermc.paperweight.core.ext
2726
import io.papermc.paperweight.core.extension.PaperweightCoreExtension
27+
import io.papermc.paperweight.core.tasks.DetermineSpigotDependencies
2828
import io.papermc.paperweight.tasks.*
2929
import io.papermc.paperweight.util.*
3030
import io.papermc.paperweight.util.constants.*
3131
import java.nio.file.Path
32+
import kotlin.io.path.*
3233
import org.gradle.api.Project
3334
import org.gradle.api.Task
34-
import org.gradle.api.provider.Provider
3535
import org.gradle.api.tasks.TaskContainer
3636
import org.gradle.kotlin.dsl.*
3737

@@ -41,7 +41,6 @@ open class SpigotTasks(
4141
tasks: TaskContainer = project.tasks,
4242
cache: Path = project.layout.cache,
4343
extension: PaperweightCoreExtension = project.ext,
44-
downloadService: Provider<DownloadService> = project.download,
4544
) : VanillaTasks(project) {
4645

4746
val addAdditionalSpigotMappings by tasks.registering<AddAdditionalSpigotMappings> {
@@ -52,14 +51,6 @@ open class SpigotTasks(
5251
additionalMemberEntriesSrg.set(extension.paper.additionalSpigotMemberMappings.fileExists(project))
5352
}
5453

55-
val inspectVanillaJar by tasks.registering<InspectVanillaJar> {
56-
inputJar.set(downloadServerJar.flatMap { it.outputJar })
57-
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
58-
mcLibraries.set(setupMcLibraries.flatMap { it.outputFile })
59-
60-
serverLibraries.set(cache.resolve(SERVER_LIBRARIES))
61-
}
62-
6354
val generateSpigotMappings by tasks.registering<GenerateSpigotMappings> {
6455
classMappings.set(addAdditionalSpigotMappings.flatMap { it.outputClassSrg })
6556
memberMappings.set(addAdditionalSpigotMappings.flatMap { it.outputMemberSrg })
@@ -97,7 +88,7 @@ open class SpigotTasks(
9788

9889
val cleanupMappings by tasks.registering<CleanupMappings> {
9990
sourceJar.set(spigotRemapJar.flatMap { it.outputJar })
100-
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
91+
libraries.from(minecraftLibraries)
10192
inputMappings.set(generateSpigotMappings.flatMap { it.outputMappings })
10293

10394
outputMappings.set(cache.resolve(CLEANED_SPIGOT_MOJANG_YARN_MAPPINGS))
@@ -172,13 +163,18 @@ open class SpigotTasks(
172163
dependsOn(patchSpigotApi, patchSpigotServer)
173164
}
174165

175-
val downloadSpigotDependencies by tasks.registering<DownloadSpigotDependencies> {
166+
val determineSpigotDependencies by tasks.registering<DetermineSpigotDependencies> {
176167
dependsOn(patchSpigot)
177168
apiPom.set(patchSpigotApi.flatMap { it.outputDir.file("pom.xml") })
178169
serverPom.set(patchSpigotServer.flatMap { it.outputDir.file("pom.xml") })
179-
outputDir.set(cache.resolve(SPIGOT_JARS_PATH))
170+
}
180171

181-
downloader.set(downloadService)
172+
val spigotDependencies = determineSpigotDependencies.flatMap { determine ->
173+
project.resolveWithRepos(
174+
determine.dependencies.map { deps -> deps.path.readLines() },
175+
determine.repositories.map { repos -> repos.path.readLines() },
176+
SPIGOT_DEPENDENCIES
177+
)
182178
}
183179

184180
val remapSpigotAt by tasks.registering<RemapSpigotAt> {
@@ -187,15 +183,14 @@ open class SpigotTasks(
187183
spigotAt.set(extension.craftBukkit.atFile)
188184
}
189185

190-
@Suppress("DuplicatedCode")
191186
val remapSpigotSources by tasks.registering<RemapSources> {
192187
spigotServerDir.set(patchSpigotServer.flatMap { it.outputDir })
193188
spigotApiDir.set(patchSpigotApi.flatMap { it.outputDir })
194189
mappings.set(patchMappings.flatMap { it.outputMappings })
195-
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
190+
vanillaJar.set(serverJar)
196191
mojangMappedVanillaJar.set(fixJar.flatMap { it.outputJar })
197192
vanillaRemappedSpigotJar.set(filterSpigotExcludes.flatMap { it.outputZip })
198-
spigotDeps.from(downloadSpigotDependencies.map { it.outputDir.asFileTree })
193+
spigotDeps.from(spigotDependencies)
199194
additionalAts.set(extension.paper.additionalAts.fileExists(project))
200195
}
201196

paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt

+15-12
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222

2323
package io.papermc.paperweight.core.taskcontainers
2424

25-
import io.papermc.paperweight.DownloadService
2625
import io.papermc.paperweight.tasks.*
2726
import io.papermc.paperweight.util.*
2827
import io.papermc.paperweight.util.constants.*
2928
import java.nio.file.Path
29+
import kotlin.io.path.*
3030
import org.gradle.api.Project
31-
import org.gradle.api.provider.Provider
3231
import org.gradle.api.tasks.TaskContainer
3332
import org.gradle.kotlin.dsl.*
3433

@@ -37,23 +36,27 @@ open class VanillaTasks(
3736
project: Project,
3837
tasks: TaskContainer = project.tasks,
3938
cache: Path = project.layout.cache,
40-
downloadService: Provider<DownloadService> = project.download,
4139
) : GeneralTasks(project) {
4240

43-
val downloadMcLibraries by tasks.registering<DownloadMcLibraries> {
44-
mcLibrariesFile.set(setupMcLibraries.flatMap { it.outputFile })
45-
mcRepo.set(MC_LIBRARY_URL)
46-
outputDir.set(cache.resolve(MINECRAFT_JARS_PATH))
47-
sourcesOutputDir.set(cache.resolve(MINECRAFT_SOURCES_PATH))
41+
val minecraftLibraries = project.downloadMinecraftLibraries(minecraftLibrariesList)
4842

49-
downloader.set(downloadService)
43+
val inspectVanillaJar by tasks.registering<InspectVanillaJar> {
44+
inputJar.set(serverJar)
45+
libraries.from(minecraftLibraries)
46+
mcLibraries.set(minecraftLibrariesList)
47+
48+
serverLibraries.set(cache.resolve(SERVER_LIBRARIES))
49+
}
50+
51+
val minecraftLibrariesSources = inspectVanillaJar.map {
52+
project.downloadMinecraftLibrariesSources(it.serverLibraries.map { libs -> libs.path.readLines() })
5053
}
5154

5255
val generateMappings by tasks.registering<GenerateMappings> {
5356
vanillaJar.set(filterVanillaJar.flatMap { it.outputJar })
54-
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
57+
libraries.from(minecraftLibraries)
5558

56-
vanillaMappings.set(downloadMappings.flatMap { it.outputFile })
59+
vanillaMappings.set(serverMappings)
5760
paramMappings.fileProvider(project.configurations.named(PARAM_MAPPINGS_CONFIG).map { it.singleFile })
5861

5962
outputMappings.set(cache.resolve(MOJANG_YARN_MAPPINGS))
@@ -69,6 +72,6 @@ open class VanillaTasks(
6972

7073
val fixJar by tasks.registering<FixJar> {
7174
inputJar.set(remapJar.flatMap { it.outputJar })
72-
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
75+
vanillaJar.set(serverJar)
7376
}
7477
}

0 commit comments

Comments
 (0)