Skip to content

Commit

Permalink
Move downloads from DownloadService to using Gradle Configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Oct 11, 2021
1 parent abfb717 commit 13eaac0
Show file tree
Hide file tree
Showing 31 changed files with 480 additions and 919 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = io.papermc.paperweight
version = 1.1.12
version = 1.1.13-SNAPSHOT
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ hypo = "1.2.1"
asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }

httpclient = "org.apache.httpcomponents:httpclient:4.5.13"
kotson = "com.github.salomonbrys.kotson:kotson:2.5.0"

cadix-lorenz-core = { module = "org.cadixdev:lorenz", version.ref = "lorenz" }
Expand Down
15 changes: 5 additions & 10 deletions paperweight-core/src/main/kotlin/PaperweightCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package io.papermc.paperweight.core

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

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

target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {}

target.tasks.register<Delete>("cleanCache") {
group = "paper"
description = "Delete the project setup cache and task outputs."
Expand All @@ -69,7 +66,7 @@ class PaperweightCore : Plugin<Project> {
devBundleTasks.configure(
ext.serverProject,
ext.minecraftVersion,
tasks.downloadServerJar.map { it.outputJar.path },
tasks.serverJar.map { it.path },
tasks.decompileJar.map { it.outputJar.path },
tasks.inspectVanillaJar.map { it.serverLibraries.path },
tasks.mergeAdditionalAts.map { it.outputFile.path }
Expand All @@ -89,13 +86,11 @@ class PaperweightCore : Plugin<Project> {

target.tasks.register<PaperweightCoreUpstreamData>(PAPERWEIGHT_PREPARE_DOWNSTREAM) {
dependsOn(tasks.applyPatches)
vanillaJar.set(tasks.downloadServerJar.flatMap { it.outputJar })
vanillaJar.set(tasks.serverJar)
remappedJar.set(tasks.copyResources.flatMap { it.outputJar })
decompiledJar.set(tasks.decompileJar.flatMap { it.outputJar })
mcVersion.set(target.ext.minecraftVersion)
mcLibrariesFile.set(tasks.inspectVanillaJar.flatMap { it.serverLibraries })
mcLibrariesDir.set(tasks.downloadMcLibraries.flatMap { it.outputDir })
mcLibrariesSourcesDir.set(tasks.downloadMcLibraries.flatMap { it.sourcesOutputDir })
mappings.set(tasks.patchMappings.flatMap { it.outputMappings })
notchToSpigotMappings.set(tasks.generateSpigotMappings.flatMap { it.notchToSpigotMappings })
sourceMappings.set(tasks.generateMappings.flatMap { it.outputMappings })
Expand Down Expand Up @@ -157,7 +152,7 @@ class PaperweightCore : Plugin<Project> {
} ?: return@afterEvaluate

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

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

// library class imports
mcLibrarySourcesDir.set(allTasks.downloadMcLibraries.flatMap { it.sourcesOutputDir }.get())
mcLibrariesSources.from(allTasks.minecraftLibrariesSources)
devImports.set(extension.paper.devImports)

outputPatchDir.set(extension.paper.remappedSpigotServerPatchDir)
Expand Down
6 changes: 3 additions & 3 deletions paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ open class AllTasks(

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

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

inputJar.set(copyResources.flatMap { it.outputJar })
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
libraries.from(minecraftLibraries)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class GeneralTasks(
}

val filterVanillaJar by tasks.registering<FilterJar> {
inputJar.set(downloadServerJar.flatMap { it.outputJar })
inputJar.set(serverJar)
includes.set(extension.vanillaJarIncludes)
}
}
81 changes: 24 additions & 57 deletions paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,78 +26,45 @@ import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonObject
import io.papermc.paperweight.DownloadService
import io.papermc.paperweight.core.ext
import io.papermc.paperweight.core.extension.PaperweightCoreExtension
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import java.nio.file.Path
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*

@Suppress("MemberVisibilityCanBePrivate")
open class InitialTasks(
project: Project,
tasks: TaskContainer = project.tasks,
cache: Path = project.layout.cache,
extension: PaperweightCoreExtension = project.ext,
downloadService: Provider<DownloadService> = project.download
) {

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

outputs.upToDateWhen { false }
private val versionManifest = project.downloadFile(
mcManifest.zip(extension.minecraftVersion) { manifest, version ->
manifest.versions.first { it.id == version }.url
},
MINECRAFT_VERSION_MANIFEST
).map { gson.fromJson<JsonObject>(it) }

downloader.set(downloadService)
val minecraftLibrariesList = versionManifest.map { version ->
version["libraries"].array.map { library ->
library["name"].string
}
}
private val mcManifest = downloadMcManifest.flatMap { it.outputFile }.map { gson.fromJson<MinecraftManifest>(it) }

val downloadMcVersionManifest by tasks.registering<DownloadTask> {
url.set(
mcManifest.zip(extension.minecraftVersion) { manifest, version ->
manifest.versions.first { it.id == version }.url
}
)
outputFile.set(cache.resolve(VERSION_JSON))
val serverMappings = project.downloadFile(
versionManifest.map { version ->
version["downloads"]["server_mappings"]["url"].string
},
MOJANG_SERVER_MAPPINGS
)

downloader.set(downloadService)
}
private val versionManifest = downloadMcVersionManifest.flatMap { it.outputFile }.map { gson.fromJson<JsonObject>(it) }

val setupMcLibraries by tasks.registering<SetupMcLibraries> {
dependencies.set(
versionManifest.map { version ->
version["libraries"].array.map { library ->
library["name"].string
}
}
)
outputFile.set(cache.resolve(MC_LIBRARIES))
}

val downloadMappings by tasks.registering<DownloadTask> {
url.set(
versionManifest.map { version ->
version["downloads"]["server_mappings"]["url"].string
}
)
outputFile.set(cache.resolve(SERVER_MAPPINGS))

downloader.set(downloadService)
}

val downloadServerJar by tasks.registering<DownloadServerJar> {
downloadUrl.set(
versionManifest.map { version ->
version["downloads"]["server"]["url"].string
}
)

downloader.set(downloadService)
}
val serverJar = project.downloadFile(
versionManifest.map { version ->
version["downloads"]["server"]["url"].string
},
VANILLA_SERVER_JAR
)
}
31 changes: 13 additions & 18 deletions paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

package io.papermc.paperweight.core.taskcontainers

import io.papermc.paperweight.DownloadService
import io.papermc.paperweight.core.ext
import io.papermc.paperweight.core.extension.PaperweightCoreExtension
import io.papermc.paperweight.core.tasks.DetermineSpigotDependencies
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*

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

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

val inspectVanillaJar by tasks.registering<InspectVanillaJar> {
inputJar.set(downloadServerJar.flatMap { it.outputJar })
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
mcLibraries.set(setupMcLibraries.flatMap { it.outputFile })

serverLibraries.set(cache.resolve(SERVER_LIBRARIES))
}

val generateSpigotMappings by tasks.registering<GenerateSpigotMappings> {
classMappings.set(addAdditionalSpigotMappings.flatMap { it.outputClassSrg })
memberMappings.set(addAdditionalSpigotMappings.flatMap { it.outputMemberSrg })
Expand Down Expand Up @@ -97,7 +88,7 @@ open class SpigotTasks(

val cleanupMappings by tasks.registering<CleanupMappings> {
sourceJar.set(spigotRemapJar.flatMap { it.outputJar })
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
libraries.from(minecraftLibraries)
inputMappings.set(generateSpigotMappings.flatMap { it.outputMappings })

outputMappings.set(cache.resolve(CLEANED_SPIGOT_MOJANG_YARN_MAPPINGS))
Expand Down Expand Up @@ -172,13 +163,18 @@ open class SpigotTasks(
dependsOn(patchSpigotApi, patchSpigotServer)
}

val downloadSpigotDependencies by tasks.registering<DownloadSpigotDependencies> {
val determineSpigotDependencies by tasks.registering<DetermineSpigotDependencies> {
dependsOn(patchSpigot)
apiPom.set(patchSpigotApi.flatMap { it.outputDir.file("pom.xml") })
serverPom.set(patchSpigotServer.flatMap { it.outputDir.file("pom.xml") })
outputDir.set(cache.resolve(SPIGOT_JARS_PATH))
}

downloader.set(downloadService)
val spigotDependencies = determineSpigotDependencies.flatMap { determine ->
project.resolveWithRepos(
determine.dependencies.map { deps -> deps.path.readLines() },
determine.repositories.map { repos -> repos.path.readLines() },
SPIGOT_DEPENDENCIES
)
}

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

@Suppress("DuplicatedCode")
val remapSpigotSources by tasks.registering<RemapSources> {
spigotServerDir.set(patchSpigotServer.flatMap { it.outputDir })
spigotApiDir.set(patchSpigotApi.flatMap { it.outputDir })
mappings.set(patchMappings.flatMap { it.outputMappings })
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
vanillaJar.set(serverJar)
mojangMappedVanillaJar.set(fixJar.flatMap { it.outputJar })
vanillaRemappedSpigotJar.set(filterSpigotExcludes.flatMap { it.outputZip })
spigotDeps.from(downloadSpigotDependencies.map { it.outputDir.asFileTree })
spigotDeps.from(spigotDependencies)
additionalAts.set(extension.paper.additionalAts.fileExists(project))
}

Expand Down
27 changes: 15 additions & 12 deletions paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

package io.papermc.paperweight.core.taskcontainers

import io.papermc.paperweight.DownloadService
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*

Expand All @@ -37,23 +36,27 @@ open class VanillaTasks(
project: Project,
tasks: TaskContainer = project.tasks,
cache: Path = project.layout.cache,
downloadService: Provider<DownloadService> = project.download,
) : GeneralTasks(project) {

val downloadMcLibraries by tasks.registering<DownloadMcLibraries> {
mcLibrariesFile.set(setupMcLibraries.flatMap { it.outputFile })
mcRepo.set(MC_LIBRARY_URL)
outputDir.set(cache.resolve(MINECRAFT_JARS_PATH))
sourcesOutputDir.set(cache.resolve(MINECRAFT_SOURCES_PATH))
val minecraftLibraries = project.downloadMinecraftLibraries(minecraftLibrariesList)

downloader.set(downloadService)
val inspectVanillaJar by tasks.registering<InspectVanillaJar> {
inputJar.set(serverJar)
libraries.from(minecraftLibraries)
mcLibraries.set(minecraftLibrariesList)

serverLibraries.set(cache.resolve(SERVER_LIBRARIES))
}

val minecraftLibrariesSources = inspectVanillaJar.map {
project.downloadMinecraftLibrariesSources(it.serverLibraries.map { libs -> libs.path.readLines() })
}

val generateMappings by tasks.registering<GenerateMappings> {
vanillaJar.set(filterVanillaJar.flatMap { it.outputJar })
libraries.from(downloadMcLibraries.map { it.outputDir.asFileTree })
libraries.from(minecraftLibraries)

vanillaMappings.set(downloadMappings.flatMap { it.outputFile })
vanillaMappings.set(serverMappings)
paramMappings.fileProvider(project.configurations.named(PARAM_MAPPINGS_CONFIG).map { it.singleFile })

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

val fixJar by tasks.registering<FixJar> {
inputJar.set(remapJar.flatMap { it.outputJar })
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
vanillaJar.set(serverJar)
}
}
Loading

0 comments on commit 13eaac0

Please sign in to comment.