Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move downloads from DownloadService to using Gradle Configurations #90

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.PaperweightCorePrepareForDownstream
Expand All @@ -45,8 +44,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 @@ -68,7 +65,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 @@ -88,13 +85,11 @@ class PaperweightCore : Plugin<Project> {

target.tasks.register<PaperweightCorePrepareForDownstream>(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.downloadMcLibrariesSources.flatMap { it.outputDir })
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 @@ -154,7 +149,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 @@ -193,14 +188,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.downloadMcLibrariesSources.flatMap { it.outputDir }.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(downloadMcLibrariesSources.flatMap { it.outputDir })
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
)
}
23 changes: 13 additions & 10 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 Down Expand Up @@ -89,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 @@ -164,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 @@ -179,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
33 changes: 10 additions & 23 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,39 +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))

downloader.set(downloadService)
}
val minecraftLibraries = project.downloadMinecraftLibraries(minecraftLibrariesList)

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 })
inputJar.set(serverJar)
libraries.from(minecraftLibraries)
mcLibraries.set(minecraftLibrariesList)

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

val downloadMcLibrariesSources by tasks.registering<DownloadMcLibraries> {
mcLibrariesFile.set(inspectVanillaJar.flatMap { it.serverLibraries })
mcRepo.set(MC_LIBRARY_URL)
outputDir.set(cache.resolve(MINECRAFT_SOURCES_PATH))
sources.set(true)

downloader.set(downloadService)
val minecraftLibrariesSources = inspectVanillaJar.flatMap {
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 @@ -85,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