From 13eaac011f31e5e31af560269902e3390644a2b2 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Fri, 8 Oct 2021 03:12:33 -0700 Subject: [PATCH] Move downloads from DownloadService to using Gradle Configurations --- gradle.properties | 2 +- gradle/libs.versions.toml | 1 - .../src/main/kotlin/PaperweightCore.kt | 15 +- .../main/kotlin/taskcontainers/AllTasks.kt | 6 +- .../kotlin/taskcontainers/GeneralTasks.kt | 2 +- .../kotlin/taskcontainers/InitialTasks.kt | 81 ++--- .../main/kotlin/taskcontainers/SpigotTasks.kt | 31 +- .../kotlin/taskcontainers/VanillaTasks.kt | 27 +- .../tasks/DetermineSpigotDependencies.kt | 148 +++++++++ .../tasks/PaperweightCoreUpstreamData.kt | 14 +- paperweight-lib/build.gradle.kts | 1 - .../src/main/kotlin/DownloadService.kt | 143 --------- .../main/kotlin/tasks/ApplyPaperPatches.kt | 14 +- .../main/kotlin/tasks/DownloadServerJar.kt | 56 ---- .../main/kotlin/tasks/InspectVanillaJar.kt | 22 +- .../src/main/kotlin/tasks/SetupMcLibraries.kt | 59 ---- .../src/main/kotlin/tasks/download-task.kt | 280 ------------------ .../kotlin/tasks/patchremap/RemapPatches.kt | 14 +- .../src/main/kotlin/util/MavenArtifact.kt | 5 +- paperweight-lib/src/main/kotlin/util/McDev.kt | 5 +- .../src/main/kotlin/util/PaperAt.kt | 88 ------ .../src/main/kotlin/util/UpstreamData.kt | 4 +- .../kotlin/util/configuration-downloads.kt | 112 +++++++ .../main/kotlin/util/constants/constants.kt | 20 +- .../src/main/kotlin/util/dependencies.kt | 5 +- .../main/kotlin/util/download-mc-libraries.kt | 61 ++++ paperweight-lib/src/main/kotlin/util/utils.kt | 19 +- .../src/main/kotlin/PaperweightPatcher.kt | 19 +- .../kotlin/tasks/SimpleApplyGitPatches.kt | 15 +- .../src/main/kotlin/PaperweightUser.kt | 4 - .../kotlin/internal/setup/UserdevSetup.kt | 126 +++----- 31 files changed, 480 insertions(+), 919 deletions(-) create mode 100644 paperweight-core/src/main/kotlin/tasks/DetermineSpigotDependencies.kt delete mode 100644 paperweight-lib/src/main/kotlin/DownloadService.kt delete mode 100644 paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt delete mode 100644 paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt delete mode 100644 paperweight-lib/src/main/kotlin/tasks/download-task.kt delete mode 100644 paperweight-lib/src/main/kotlin/util/PaperAt.kt create mode 100644 paperweight-lib/src/main/kotlin/util/configuration-downloads.kt create mode 100644 paperweight-lib/src/main/kotlin/util/download-mc-libraries.kt diff --git a/gradle.properties b/gradle.properties index e7b1fa899..443248bf0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = io.papermc.paperweight -version = 1.1.12 +version = 1.1.13-SNAPSHOT diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ced057a55..0e233dfa4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/paperweight-core/src/main/kotlin/PaperweightCore.kt b/paperweight-core/src/main/kotlin/PaperweightCore.kt index d0d48ce54..6148b4bd0 100644 --- a/paperweight-core/src/main/kotlin/PaperweightCore.kt +++ b/paperweight-core/src/main/kotlin/PaperweightCore.kt @@ -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 @@ -46,8 +45,6 @@ class PaperweightCore : Plugin { val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class) - target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {} - target.tasks.register("cleanCache") { group = "paper" description = "Delete the project setup cache and task outputs." @@ -69,7 +66,7 @@ class PaperweightCore : Plugin { 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 } @@ -89,13 +86,11 @@ class PaperweightCore : Plugin { target.tasks.register(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 }) @@ -157,7 +152,7 @@ class PaperweightCore : Plugin { } ?: return@afterEvaluate val generatePaperclipPatch by target.tasks.registering { - originalJar.set(tasks.downloadServerJar.flatMap { it.outputJar }) + originalJar.set(tasks.serverJar) patchedJar.set(reobfJar.flatMap { it.outputJar }) mcVersion.set(target.ext.minecraftVersion) } @@ -196,14 +191,14 @@ class PaperweightCore : Plugin { // 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) diff --git a/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt index b67c2870a..07924f054 100644 --- a/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt @@ -53,7 +53,7 @@ open class AllTasks( val copyResources by tasks.registering { 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)) @@ -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)) } @@ -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")) diff --git a/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt index 4147bc4ae..6780a9190 100644 --- a/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt @@ -47,7 +47,7 @@ open class GeneralTasks( } val filterVanillaJar by tasks.registering { - inputJar.set(downloadServerJar.flatMap { it.outputJar }) + inputJar.set(serverJar) includes.set(extension.vanillaJarIncludes) } } diff --git a/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt index 14064ab63..65ee5f9a2 100644 --- a/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt @@ -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 = project.download ) { - val downloadMcManifest by tasks.registering { - url.set(MC_MANIFEST_URL) - outputFile.set(cache.resolve(MC_MANIFEST)) + private val mcManifest = project.downloadFile(MC_MANIFEST_URL, MINECRAFT_MANIFEST) + .map { gson.fromJson(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(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(it) } - val downloadMcVersionManifest by tasks.registering { - 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(it) } - - val setupMcLibraries by tasks.registering { - dependencies.set( - versionManifest.map { version -> - version["libraries"].array.map { library -> - library["name"].string - } - } - ) - outputFile.set(cache.resolve(MC_LIBRARIES)) - } - - val downloadMappings by tasks.registering { - 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 { - 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 + ) } diff --git a/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt index e1cd6dcc1..5ca827ab1 100644 --- a/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt @@ -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.* @@ -41,7 +41,6 @@ open class SpigotTasks( tasks: TaskContainer = project.tasks, cache: Path = project.layout.cache, extension: PaperweightCoreExtension = project.ext, - downloadService: Provider = project.download, ) : VanillaTasks(project) { val addAdditionalSpigotMappings by tasks.registering { @@ -52,14 +51,6 @@ open class SpigotTasks( additionalMemberEntriesSrg.set(extension.paper.additionalSpigotMemberMappings.fileExists(project)) } - val inspectVanillaJar by tasks.registering { - 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 { classMappings.set(addAdditionalSpigotMappings.flatMap { it.outputClassSrg }) memberMappings.set(addAdditionalSpigotMappings.flatMap { it.outputMemberSrg }) @@ -97,7 +88,7 @@ open class SpigotTasks( val cleanupMappings by tasks.registering { 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)) @@ -172,13 +163,18 @@ open class SpigotTasks( dependsOn(patchSpigotApi, patchSpigotServer) } - val downloadSpigotDependencies by tasks.registering { + val determineSpigotDependencies by tasks.registering { 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 { @@ -187,15 +183,14 @@ open class SpigotTasks( spigotAt.set(extension.craftBukkit.atFile) } - @Suppress("DuplicatedCode") val remapSpigotSources by tasks.registering { 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)) } diff --git a/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt index 6ec85de53..628339bb1 100644 --- a/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt @@ -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.* @@ -37,23 +36,27 @@ open class VanillaTasks( project: Project, tasks: TaskContainer = project.tasks, cache: Path = project.layout.cache, - downloadService: Provider = project.download, ) : GeneralTasks(project) { - val downloadMcLibraries by tasks.registering { - 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 { + 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 { 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)) @@ -69,6 +72,6 @@ open class VanillaTasks( val fixJar by tasks.registering { inputJar.set(remapJar.flatMap { it.outputJar }) - vanillaJar.set(downloadServerJar.flatMap { it.outputJar }) + vanillaJar.set(serverJar) } } diff --git a/paperweight-core/src/main/kotlin/tasks/DetermineSpigotDependencies.kt b/paperweight-core/src/main/kotlin/tasks/DetermineSpigotDependencies.kt new file mode 100644 index 000000000..7797b0300 --- /dev/null +++ b/paperweight-core/src/main/kotlin/tasks/DetermineSpigotDependencies.kt @@ -0,0 +1,148 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.core.tasks + +import io.papermc.paperweight.tasks.* +import io.papermc.paperweight.util.* +import java.nio.file.Path +import javax.xml.parsers.DocumentBuilderFactory +import kotlin.io.path.* +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.* +import org.w3c.dom.Element + +@CacheableTask +abstract class DetermineSpigotDependencies : BaseTask() { + + @get:InputFile + @get:PathSensitive(PathSensitivity.NONE) + abstract val apiPom: RegularFileProperty + + @get:InputFile + @get:PathSensitive(PathSensitivity.NONE) + abstract val serverPom: RegularFileProperty + + @get:OutputFile + abstract val dependencies: RegularFileProperty + + @get:OutputFile + abstract val repositories: RegularFileProperty + + override fun init() { + dependencies.convention(defaultOutput("$name-dependencies", "txt")) + repositories.convention(defaultOutput("$name-repositories", "txt")) + } + + @TaskAction + fun run() { + val apiSetup = parsePom(apiPom.path) + val serverSetup = parsePom(serverPom.path) + + val spigotRepos = mutableSetOf() + spigotRepos += apiSetup.repos + spigotRepos += serverSetup.repos + + val artifacts = mutableSetOf() + artifacts += apiSetup.artifacts + artifacts += serverSetup.artifacts + + dependencies.path.parent.createDirectories() + dependencies.path.writeLines(artifacts.map { it.toString() }) + repositories.path.writeLines(spigotRepos) + } + + private fun parsePom(pomFile: Path): MavenSetup { + val depList = arrayListOf() + val repoList = arrayListOf() + // Maven Central is implicit + repoList += "https://repo.maven.apache.org/maven2/" + + val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder() + val doc = pomFile.inputStream().buffered().use { stream -> + stream.buffered().use { buffered -> + builder.parse(buffered) + } + } + + doc.documentElement.normalize() + + val list = doc.getElementsByTagName("dependencies") + for (i in 0 until list.length) { + val node = list.item(i) as? Element ?: continue + + val depNode = node.getElementsByTagName("dependency") + for (j in 0 until depNode.length) { + val dependency = depNode.item(j) as? Element ?: continue + val artifact = getDependency(dependency) ?: continue + depList += artifact + } + } + + val repos = doc.getElementsByTagName("repositories") + for (i in 0 until repos.length) { + val node = repos.item(i) as? Element ?: continue + val depNode = node.getElementsByTagName("repository") + for (j in 0 until depNode.length) { + val repo = depNode.item(j) as? Element ?: continue + val repoUrl = repo.getElementsByTagName("url").item(0).textContent + repoList += repoUrl + } + } + + return MavenSetup(repos = repoList, artifacts = depList) + } + + private fun getDependency(node: Element): MavenArtifact? { + val scopeNode = node.getElementsByTagName("scope") + val scope = if (scopeNode.length == 0) { + "compile" + } else { + scopeNode.item(0).textContent + } + + if (scope != "compile") { + return null + } + + val group = node.getElementsByTagName("groupId").item(0).textContent + val artifact = node.getElementsByTagName("artifactId").item(0).textContent + val version = node.getElementsByTagName("version").item(0).textContent + + if (version.contains("\${")) { + // Don't handle complicated things + // We don't need to (for now anyways) + return null + } + + return MavenArtifact( + group = group, + artifact = artifact, + version = version + ) + } + + data class MavenSetup( + val repos: List, + val artifacts: List + ) +} diff --git a/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt b/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt index b0f58eefa..1598556fd 100644 --- a/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt +++ b/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt @@ -27,16 +27,13 @@ import javax.inject.Inject import kotlin.io.path.* import org.gradle.api.DefaultTask import org.gradle.api.artifacts.Configuration -import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.provider.ProviderFactory import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction @@ -54,16 +51,9 @@ abstract class PaperweightCoreUpstreamData : DefaultTask() { @get:Input abstract val mcVersion: Property - @get:InputDirectory - abstract val mcLibrariesDir: DirectoryProperty - - @get:InputDirectory - abstract val mcLibrariesSourcesDir: DirectoryProperty - @get:Input abstract val vanillaJarIncludes: ListProperty - @get:Optional @get:InputFile abstract val mcLibrariesFile: RegularFileProperty @@ -105,9 +95,7 @@ abstract class PaperweightCoreUpstreamData : DefaultTask() { remappedJar.path, decompiledJar.path, mcVersion.get(), - mcLibrariesDir.path, - mcLibrariesSourcesDir.path, - mcLibrariesFile.pathOrNull, + mcLibrariesFile.path, mappings.path, notchToSpigotMappings.path, sourceMappings.path, diff --git a/paperweight-lib/build.gradle.kts b/paperweight-lib/build.gradle.kts index f58708fe5..b505b440d 100644 --- a/paperweight-lib/build.gradle.kts +++ b/paperweight-lib/build.gradle.kts @@ -3,7 +3,6 @@ plugins { } dependencies { - implementation(libs.httpclient) implementation(libs.kotson) // ASM for inspection diff --git a/paperweight-lib/src/main/kotlin/DownloadService.kt b/paperweight-lib/src/main/kotlin/DownloadService.kt deleted file mode 100644 index 1616c6725..000000000 --- a/paperweight-lib/src/main/kotlin/DownloadService.kt +++ /dev/null @@ -1,143 +0,0 @@ -/* - * paperweight is a Gradle plugin for the PaperMC project. - * - * Copyright (c) 2021 Kyle Wood (DenWav) - * Contributors - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 only, no later versions. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -package io.papermc.paperweight - -import io.papermc.paperweight.util.* -import java.net.URL -import java.nio.file.Path -import java.nio.file.attribute.FileTime -import java.time.Instant -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter -import java.util.concurrent.TimeUnit -import kotlin.io.path.* -import org.apache.http.HttpHost -import org.apache.http.HttpStatus -import org.apache.http.client.config.CookieSpecs -import org.apache.http.client.config.RequestConfig -import org.apache.http.client.methods.CloseableHttpResponse -import org.apache.http.client.methods.HttpGet -import org.apache.http.client.utils.DateUtils -import org.apache.http.impl.client.CloseableHttpClient -import org.apache.http.impl.client.HttpClientBuilder -import org.gradle.api.services.BuildService -import org.gradle.api.services.BuildServiceParameters - -abstract class DownloadService : BuildService, AutoCloseable { - - private val httpClient: CloseableHttpClient = HttpClientBuilder.create().let { builder -> - builder.setRetryHandler { _, count, _ -> count < 3 } - builder.useSystemProperties() - builder.build() - } - - fun download(source: Any, target: Any) { - val url = source.convertToUrl() - val file = target.convertToPath() - download(url, file) - } - - private fun download(source: URL, target: Path) { - target.parent.createDirectories() - - val etagDir = target.resolveSibling("etags") - etagDir.createDirectories() - - val etagFile = etagDir.resolve(target.name + ".etag") - val etag = if (etagFile.exists()) etagFile.readText() else null - - val host = HttpHost(source.host, source.port, source.protocol) - val time = if (target.exists()) target.getLastModifiedTime().toInstant() else Instant.EPOCH - - val httpGet = HttpGet(source.file) - // high timeout, reduce chances of weird things going wrong - val timeouts = TimeUnit.MINUTES.toMillis(5).toInt() - - httpGet.config = RequestConfig.custom() - .setConnectTimeout(timeouts) - .setConnectionRequestTimeout(timeouts) - .setSocketTimeout(timeouts) - .setCookieSpec(CookieSpecs.STANDARD) - .build() - - if (target.exists()) { - if (time != Instant.EPOCH) { - val value = DateTimeFormatter.RFC_1123_DATE_TIME.format(time.atZone(ZoneOffset.UTC)) - httpGet.setHeader("If-Modified-Since", value) - } - if (etag != null) { - httpGet.setHeader("If-None-Match", etag) - } - } - - httpClient.execute(host, httpGet).use { response -> - val code = response.statusLine.statusCode - if (code !in 200..299 && code != HttpStatus.SC_NOT_MODIFIED) { - val reason = response.statusLine.reasonPhrase - throw PaperweightException("Download failed, HTTP code: $code; URL: $source; Reason: $reason") - } - - val lastModified = handleResponse(response, time, target) - saveEtag(response, lastModified, target, etagFile) - } - } - - private fun handleResponse(response: CloseableHttpResponse, time: Instant, target: Path): Instant { - val lastModified = with(response.getLastHeader("Last-Modified")) { - if (this == null) { - return@with Instant.EPOCH - } - if (value.isNullOrBlank()) { - return@with Instant.EPOCH - } - return@with DateUtils.parseDate(value).toInstant() ?: Instant.EPOCH - } - if (response.statusLine.statusCode == HttpStatus.SC_NOT_MODIFIED) { - return lastModified - } - - val entity = response.entity ?: return lastModified - target.outputStream().use { output -> - entity.content.use { input -> - input.copyTo(output) - } - } - - return lastModified - } - - private fun saveEtag(response: CloseableHttpResponse, lastModified: Instant, target: Path, etagFile: Path) { - if (lastModified != Instant.EPOCH) { - target.setLastModifiedTime(FileTime.from(lastModified)) - } - - val header = response.getFirstHeader("ETag") ?: return - val etag = header.value - - etagFile.writeText(etag) - } - - override fun close() { - httpClient.close() - } -} diff --git a/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt b/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt index 94f4cee47..b7b5dd53f 100644 --- a/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt @@ -27,17 +27,13 @@ import io.papermc.paperweight.util.* import java.nio.file.Path import javax.inject.Inject import kotlin.io.path.* +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.provider.ProviderFactory -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* abstract class ApplyPaperPatches : ControllableOutputTask() { @@ -62,8 +58,8 @@ abstract class ApplyPaperPatches : ControllableOutputTask() { @get:InputFile abstract val sourceMcDevJar: RegularFileProperty - @get:InputDirectory - abstract val mcLibrariesDir: DirectoryProperty + @get:InputFiles + abstract val mcLibrariesSources: ConfigurableFileCollection @get:Optional @get:InputFile @@ -123,7 +119,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() { patches = patches, decompJar = sourceMcDevJar.path, importsFile = devImports.pathOrNull, - librariesDir = mcLibrariesDir.path, + librarySources = mcLibrariesSources.asFileTree, targetDir = sourceDir, printOutput = printOutput.get() ) diff --git a/paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt b/paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt deleted file mode 100644 index b3a9643b6..000000000 --- a/paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * paperweight is a Gradle plugin for the PaperMC project. - * - * Copyright (c) 2021 Kyle Wood (DenWav) - * Contributors - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 only, no later versions. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -package io.papermc.paperweight.tasks - -import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.util.* -import kotlin.io.path.* -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction - -// Not cached since this is Mojang's server jar -abstract class DownloadServerJar : BaseTask() { - - @get:Input - abstract val downloadUrl: Property - - @get:OutputFile - abstract val outputJar: RegularFileProperty - - @get:Internal - abstract val downloader: Property - - override fun init() { - outputJar.convention(defaultOutput()) - } - - @TaskAction - fun run() { - outputJar.path.parent.createDirectories() - downloader.get().download(downloadUrl, outputJar) - } -} diff --git a/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt b/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt index 5c28bb01b..84b85b6ae 100644 --- a/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt @@ -26,13 +26,8 @@ import io.papermc.paperweight.util.* import kotlin.io.path.* import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty -import org.gradle.api.tasks.CacheableTask -import org.gradle.api.tasks.Classpath -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.PathSensitive -import org.gradle.api.tasks.PathSensitivity -import org.gradle.api.tasks.TaskAction +import org.gradle.api.provider.ListProperty +import org.gradle.api.tasks.* import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassVisitor import org.objectweb.asm.FieldVisitor @@ -49,9 +44,8 @@ abstract class InspectVanillaJar : BaseTask() { @get:Classpath abstract val libraries: ConfigurableFileCollection - @get:InputFile - @get:PathSensitive(PathSensitivity.NONE) - abstract val mcLibraries: RegularFileProperty + @get:Input + abstract val mcLibraries: ListProperty @get:OutputFile abstract val loggerFile: RegularFileProperty @@ -124,11 +118,9 @@ abstract class InspectVanillaJar : BaseTask() { } private fun checkLibraries(): Set { - val mcLibs = mcLibraries.path.useLines { lines -> - lines.map { MavenArtifact.parse(it) } - .map { it.file to it } - .toMap() - } + val mcLibs = mcLibraries.get() + .map { MavenArtifact.parse(it) } + .associateBy { it.file } val serverLibs = mutableSetOf() diff --git a/paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt b/paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt deleted file mode 100644 index 70630b04b..000000000 --- a/paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * paperweight is a Gradle plugin for the PaperMC project. - * - * Copyright (c) 2021 Kyle Wood (DenWav) - * Contributors - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 only, no later versions. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -package io.papermc.paperweight.tasks - -import io.papermc.paperweight.util.* -import java.nio.file.Path -import kotlin.io.path.* -import org.gradle.api.DefaultTask -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.ListProperty -import org.gradle.api.tasks.CacheableTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction - -@CacheableTask -abstract class SetupMcLibraries : DefaultTask() { - - @get:Input - abstract val dependencies: ListProperty - - @get:OutputFile - abstract val outputFile: RegularFileProperty - - @TaskAction - fun run() { - setupMinecraftLibraries(dependencies.get(), outputFile.path) - } -} - -fun setupMinecraftLibraries(dependencies: List, outputFile: Path) { - val list = dependencies.sorted() - - outputFile.bufferedWriter().use { writer -> - for (line in list) { - writer.appendLine(line) - } - } -} diff --git a/paperweight-lib/src/main/kotlin/tasks/download-task.kt b/paperweight-lib/src/main/kotlin/tasks/download-task.kt deleted file mode 100644 index b2091bfeb..000000000 --- a/paperweight-lib/src/main/kotlin/tasks/download-task.kt +++ /dev/null @@ -1,280 +0,0 @@ -/* - * paperweight is a Gradle plugin for the PaperMC project. - * - * Copyright (c) 2021 Kyle Wood (DenWav) - * Contributors - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 only, no later versions. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -package io.papermc.paperweight.tasks - -import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.util.* -import java.nio.file.Path -import javax.inject.Inject -import javax.xml.parsers.DocumentBuilderFactory -import kotlin.io.path.* -import org.gradle.api.DefaultTask -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.ListProperty -import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider -import org.gradle.api.tasks.* -import org.gradle.kotlin.dsl.* -import org.gradle.workers.WorkAction -import org.gradle.workers.WorkParameters -import org.gradle.workers.WorkQueue -import org.gradle.workers.WorkerExecutor -import org.w3c.dom.Element - -// Not cached since these are Mojang's files -abstract class DownloadTask : DefaultTask() { - - @get:Input - abstract val url: Property - - @get:OutputFile - abstract val outputFile: RegularFileProperty - - @get:Internal - abstract val downloader: Property - - @TaskAction - fun run() = downloader.get().download(url, outputFile) -} - -@CacheableTask -abstract class DownloadMcLibraries : DefaultTask() { - - @get:InputFile - @get:PathSensitive(PathSensitivity.NONE) - abstract val mcLibrariesFile: RegularFileProperty - - @get:Input - abstract val mcRepo: Property - - @get:OutputDirectory - abstract val outputDir: DirectoryProperty - - @get:OutputDirectory - abstract val sourcesOutputDir: DirectoryProperty - - @get:Internal - abstract val downloader: Property - - @get:Inject - abstract val workerExecutor: WorkerExecutor - - @TaskAction - fun run() { - downloadMinecraftLibraries( - downloader, - workerExecutor, - outputDir.path, - sourcesOutputDir.path, - mcRepo.get(), - mcLibrariesFile.path - ) - } -} - -fun downloadMinecraftLibraries( - download: Provider, - workerExecutor: WorkerExecutor, - out: Path, - sourcesOut: Path?, - mcRepo: String, - mcLibrariesFile: Path -): WorkQueue { - val excludes = listOf(out.fileSystem.getPathMatcher("glob:*.etag")) - out.deleteRecursively(excludes) - sourcesOut?.deleteRecursively(excludes) - - val mcRepos = listOf(mcRepo) - - val queue = workerExecutor.noIsolation() - mcLibrariesFile.useLines { lines -> - lines.forEach { line -> - queue.submit(DownloadWorker::class) { - repos.set(mcRepos) - artifact.set(line) - target.set(out) - sourcesTarget.set(sourcesOut) - downloadToDir.set(true) - downloader.set(download) - } - } - } - - return queue -} - -@CacheableTask -abstract class DownloadSpigotDependencies : BaseTask() { - - @get:InputFile - @get:PathSensitive(PathSensitivity.NONE) - abstract val apiPom: RegularFileProperty - - @get:InputFile - @get:PathSensitive(PathSensitivity.NONE) - abstract val serverPom: RegularFileProperty - - @get:OutputDirectory - abstract val outputDir: DirectoryProperty - - @get:Internal - abstract val downloader: Property - - @get:Inject - abstract val workerExecutor: WorkerExecutor - - @TaskAction - fun run() { - val apiSetup = parsePom(apiPom.path) - val serverSetup = parsePom(serverPom.path) - - val out = outputDir.path - val excludes = listOf(out.fileSystem.getPathMatcher("glob:*.etag")) - out.deleteRecursively(excludes) - - val spigotRepos = mutableSetOf() - spigotRepos += apiSetup.repos - spigotRepos += serverSetup.repos - - val artifacts = mutableSetOf() - artifacts += apiSetup.artifacts - artifacts += serverSetup.artifacts - - val queue = workerExecutor.noIsolation() - for (art in artifacts) { - queue.submit(DownloadWorker::class) { - repos.set(spigotRepos) - artifact.set(art.toString()) - target.set(out) - downloadToDir.set(true) - downloader.set(this@DownloadSpigotDependencies.downloader) - } - } - } - - private fun parsePom(pomFile: Path): MavenSetup { - val depList = arrayListOf() - val repoList = arrayListOf() - // Maven Central is implicit - repoList += "https://repo.maven.apache.org/maven2/" - - val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder() - val doc = pomFile.inputStream().buffered().use { stream -> - stream.buffered().use { buffered -> - builder.parse(buffered) - } - } - - doc.documentElement.normalize() - - val list = doc.getElementsByTagName("dependencies") - for (i in 0 until list.length) { - val node = list.item(i) as? Element ?: continue - - val depNode = node.getElementsByTagName("dependency") - for (j in 0 until depNode.length) { - val dependency = depNode.item(j) as? Element ?: continue - val artifact = getDependency(dependency) ?: continue - depList += artifact - } - } - - val repos = doc.getElementsByTagName("repositories") - for (i in 0 until repos.length) { - val node = repos.item(i) as? Element ?: continue - val depNode = node.getElementsByTagName("repository") - for (j in 0 until depNode.length) { - val repo = depNode.item(j) as? Element ?: continue - val repoUrl = repo.getElementsByTagName("url").item(0).textContent - repoList += repoUrl - } - } - - return MavenSetup(repos = repoList, artifacts = depList) - } - - private fun getDependency(node: Element): MavenArtifact? { - val scopeNode = node.getElementsByTagName("scope") - val scope = if (scopeNode.length == 0) { - "compile" - } else { - scopeNode.item(0).textContent - } - - if (scope != "compile") { - return null - } - - val group = node.getElementsByTagName("groupId").item(0).textContent - val artifact = node.getElementsByTagName("artifactId").item(0).textContent - val version = node.getElementsByTagName("version").item(0).textContent - - if (version.contains("\${")) { - // Don't handle complicated things - // We don't need to (for now anyways) - return null - } - - return MavenArtifact( - group = group, - artifact = artifact, - version = version - ) - } -} - -data class MavenSetup( - val repos: List, - val artifacts: List -) - -interface DownloadParams : WorkParameters { - val repos: ListProperty - val artifact: Property - val target: RegularFileProperty - val sourcesTarget: RegularFileProperty - val downloadToDir: Property - val downloader: Property -} - -abstract class DownloadWorker : WorkAction { - - override fun execute() { - val target = parameters.target.path - val artifact = MavenArtifact.parse(parameters.artifact.get()) - - if (parameters.downloadToDir.get()) { - artifact.downloadToDir(parameters.downloader.get(), target, parameters.repos.get()) - parameters.sourcesTarget.pathOrNull?.let { sourceDir -> - try { - val sourceArtifact = artifact.copy(classifier = "sources") - sourceArtifact.downloadToDir(parameters.downloader.get(), sourceDir, parameters.repos.get()) - } catch (ignored: Exception) { - } - } - } else { - artifact.downloadToFile(parameters.downloader.get(), target, parameters.repos.get()) - } - } -} diff --git a/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt b/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt index bb9391dab..61379c628 100644 --- a/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt @@ -34,13 +34,7 @@ import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.provider.ProviderFactory -import org.gradle.api.tasks.Classpath -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* import org.gradle.api.tasks.options.Option import org.gradle.kotlin.dsl.* @@ -70,8 +64,8 @@ abstract class RemapPatches : BaseTask() { @get:InputFile abstract val spigotDecompJar: RegularFileProperty - @get:InputDirectory - abstract val mcLibrarySourcesDir: DirectoryProperty + @get:InputFiles + abstract val mcLibrariesSources: ConfigurableFileCollection @get:InputFile abstract val devImports: RegularFileProperty @@ -176,7 +170,7 @@ abstract class RemapPatches : BaseTask() { patches = patchesToSkip + patchesToRemap, decompJar = spigotDecompJar.path, importsFile = devImports.path, - librariesDir = mcLibrarySourcesDir.path, + librarySources = mcLibrariesSources.asFileTree, targetDir = tempInputDir.resolve("src/main/java") ) diff --git a/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt b/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt index e0ede856a..413785122 100644 --- a/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt +++ b/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt @@ -22,10 +22,7 @@ package io.papermc.paperweight.util -import io.papermc.paperweight.DownloadService import io.papermc.paperweight.PaperweightException -import java.nio.file.Path -import kotlin.io.path.* data class MavenArtifact( private val group: String, @@ -46,6 +43,7 @@ data class MavenArtifact( val file: String get() = "$artifact-$version$classifierText.$ext" + /* fun downloadToFile(downloadService: DownloadService, targetFile: Path, repos: List) { targetFile.parent.createDirectories() @@ -70,6 +68,7 @@ data class MavenArtifact( downloadToFile(downloadService, out, repos) return out } + */ override fun toString(): String { return buildString(50) { diff --git a/paperweight-lib/src/main/kotlin/util/McDev.kt b/paperweight-lib/src/main/kotlin/util/McDev.kt index fc346f159..e0ae74015 100644 --- a/paperweight-lib/src/main/kotlin/util/McDev.kt +++ b/paperweight-lib/src/main/kotlin/util/McDev.kt @@ -25,6 +25,7 @@ package io.papermc.paperweight.util import io.papermc.paperweight.PaperweightException import java.nio.file.Path import kotlin.io.path.* +import org.gradle.api.file.FileCollection import org.gradle.api.logging.LogLevel import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging @@ -42,7 +43,7 @@ object McDev { patches: Iterable, decompJar: Path, importsFile: Path?, - librariesDir: Path?, + librarySources: FileCollection, targetDir: Path, printOutput: Boolean = true ) { @@ -93,7 +94,7 @@ object McDev { } } - val libFiles = librariesDir?.listDirectoryEntries("*-sources.jar") ?: return + val libFiles = librarySources.map { it.toPath() } if (libFiles.isEmpty()) { throw PaperweightException("No library files found") } diff --git a/paperweight-lib/src/main/kotlin/util/PaperAt.kt b/paperweight-lib/src/main/kotlin/util/PaperAt.kt deleted file mode 100644 index aaee5359e..000000000 --- a/paperweight-lib/src/main/kotlin/util/PaperAt.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * paperweight is a Gradle plugin for the PaperMC project. - * - * Copyright (c) 2021 Kyle Wood (DenWav) - * Contributors - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 only, no later versions. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -package io.papermc.paperweight.util - -import java.nio.file.Path -import org.cadixdev.at.io.AccessTransformFormats -import org.cadixdev.mercury.Mercury -import org.cadixdev.mercury.at.AccessTransformerRewriter -import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty -import org.gradle.kotlin.dsl.* -import org.gradle.workers.WorkAction -import org.gradle.workers.WorkParameters -import org.gradle.workers.WorkerExecutor - -object PaperAt { - - fun apply(workerExecutor: WorkerExecutor, apiDir: Path, serverDir: Path, atFile: Path?) { - if (atFile == null) { - return - } - - val queue = workerExecutor.processIsolation { - forkOptions.jvmArgs("-Xmx2G") - } - - val srcDir = serverDir.resolve("src/main/java") - - // Remap sources - queue.submit(AtAction::class) { - classpath.from(apiDir.resolve("src/main/java")) - - inputDir.set(srcDir) - outputDir.set(srcDir) - ats.set(atFile) - } - - queue.await() - } - - interface AtParams : WorkParameters { - val classpath: ConfigurableFileCollection - val inputDir: DirectoryProperty - val outputDir: DirectoryProperty - val ats: RegularFileProperty - } - - abstract class AtAction : WorkAction { - override fun execute() { - Mercury().let { merc -> - merc.classPath.addAll(parameters.classpath.map { it.toPath() }) - merc.isGracefulClasspathChecks = true - - merc.process(parameters.inputDir.path) - - merc.processors.clear() - merc.processors.addAll( - listOf( - AccessTransformerRewriter.create(AccessTransformFormats.FML.read(parameters.ats.path)) - ) - ) - - merc.rewrite(parameters.inputDir.path, parameters.outputDir.path) - } - } - } -} diff --git a/paperweight-lib/src/main/kotlin/util/UpstreamData.kt b/paperweight-lib/src/main/kotlin/util/UpstreamData.kt index 9a1003d17..03c3eb01b 100644 --- a/paperweight-lib/src/main/kotlin/util/UpstreamData.kt +++ b/paperweight-lib/src/main/kotlin/util/UpstreamData.kt @@ -31,9 +31,7 @@ data class UpstreamData( val remappedJar: Path, val decompiledJar: Path, val mcVersion: String, - val libDir: Path, - val libSourceDir: Path, - val libFile: Path?, + val serverLibsFile: Path, val mappings: Path, val notchToSpigotMappings: Path, val sourceMappings: Path, diff --git a/paperweight-lib/src/main/kotlin/util/configuration-downloads.kt b/paperweight-lib/src/main/kotlin/util/configuration-downloads.kt new file mode 100644 index 000000000..dcf7355a0 --- /dev/null +++ b/paperweight-lib/src/main/kotlin/util/configuration-downloads.kt @@ -0,0 +1,112 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.util + +import io.papermc.paperweight.util.constants.* +import java.nio.file.Path +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ExternalModuleDependency +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.* + +fun Project.resolveWithRepos( + deps: Provider>, + repos: Provider>, + downloadName: String, + configurationConfig: Configuration.() -> Unit = {} +): Provider = + deps.zip(repos) { depCoords, repoList -> + resolveWithRepos(depCoords, repoList, downloadName, configurationConfig) + } + +fun Project.resolveWithRepos( + deps: List, + repos: List, + downloadName: String, + configurationConfig: Configuration.() -> Unit = {} +): Configuration { + val configName = downloadConfigName(downloadName) + val config = configurations.findByName(configName) ?: configurations.create(configName) { + configurationConfig() + withDependencies { + deps.map { project.dependencies.create(it) } + .forEach { dep -> add(dep) } + } + } + + val added = repos.map { repo -> + repositories.maven(repo) { + name = "$repo for $configName" + content { onlyForConfigurations(configName) } + } + } + + try { + return config.also { it.resolvedConfiguration } + } finally { + repositories.removeAll(added) + } +} + +fun Project.downloadFile(fileUrl: Provider, downloadName: String): Provider = + fileUrl.flatMap { downloadFile(it, downloadName) } + +fun Project.downloadFile(url: String, downloadName: String): Provider = + layout.file(provider { downloadFileNow(url, downloadName).toFile() }) + +fun Project.downloadFileNow( + url: String, + downloadName: String +): Path { + val urlHash = toHex(url.byteInputStream().hash(digestSha256())) + val dependencyNotation = "$PAPERWEIGHT_DOWNLOAD:$downloadName:$urlHash" + + val configName = downloadConfigName(downloadName) + val config = configurations.findByName(configName) ?: configurations.create(configName) { + withDependencies { + add( + project.dependencies.create(dependencyNotation).also { + (it as ExternalModuleDependency).isChanging = true + } + ) + } + } + + val ivy = repositories.ivy { + name = "$url for $configName" + artifactPattern(url) + metadataSources { artifact() } + content { + onlyForConfigurations(configName) + includeFromDependencyNotation(dependencyNotation) + } + } + + try { + return config.singleFile.toPath() + } finally { + repositories.remove(ivy) + } +} diff --git a/paperweight-lib/src/main/kotlin/util/constants/constants.kt b/paperweight-lib/src/main/kotlin/util/constants/constants.kt index 61f21b708..efe7b6f13 100644 --- a/paperweight-lib/src/main/kotlin/util/constants/constants.kt +++ b/paperweight-lib/src/main/kotlin/util/constants/constants.kt @@ -41,6 +41,15 @@ const val DEV_BUNDLE_CONFIG = "paperweightDevelopmentBundle" const val MOJANG_MAPPED_SERVER_CONFIG = "mojangMappedServer" const val REOBF_CONFIG = "reobf" +const val PAPERWEIGHT_DOWNLOAD = "paperweightDownload" +const val MINECRAFT_LIBRARIES = "minecraftLibraries" +const val MINECRAFT_LIBRARIES_SOURCES = "minecraftLibrariesSources" +const val MINECRAFT_MANIFEST = "minecraftManifest" +const val MINECRAFT_VERSION_MANIFEST = "minecraftVersionManifest" +const val MOJANG_SERVER_MAPPINGS = "mojangServerMappings" +const val VANILLA_SERVER_JAR = "vanillaServerJar" +const val SPIGOT_DEPENDENCIES = "spigotDependencies" + const val PARAM_MAPPINGS_REPO_NAME = "paperweightParamMappingsRepository" const val DECOMPILER_REPO_NAME = "paperweightDecompilerRepository" const val REMAPPER_REPO_NAME = "paperweightRemapperRepository" @@ -53,14 +62,7 @@ const val UPSTREAM_WORK_DIR_PROPERTY = "paperweightUpstreamWorkDir" const val PAPERWEIGHT_PREPARE_DOWNSTREAM = "prepareForDownstream" const val PAPERWEIGHT_DOWNSTREAM_FILE_PROPERTY = "paperweightDownstreamDataFile" -private const val JARS_PATH = "$PAPER_PATH/jars" -const val MINECRAFT_JARS_PATH = "$JARS_PATH/minecraft" -const val MINECRAFT_SOURCES_PATH = "$JARS_PATH/minecraft-sources" - -const val SPIGOT_JARS_PATH = "$JARS_PATH/spigot" - private const val MAPPINGS_DIR = "$PAPER_PATH/mappings" -const val SERVER_MAPPINGS = "$MAPPINGS_DIR/server_mappings.txt" const val MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/official-mojang+yarn.tiny" const val SPIGOT_MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yarn.tiny" @@ -76,9 +78,6 @@ const val SPIGOT_NAMESPACE = "spigot" const val DEOBF_NAMESPACE = "mojang+yarn" private const val DATA_PATH = "$PAPER_PATH/data" -const val MC_MANIFEST = "$DATA_PATH/McManifest.json" -const val VERSION_JSON = "$DATA_PATH/McVersion.json" -const val MC_LIBRARIES = "$DATA_PATH/McLibraries.txt" const val SERVER_LIBRARIES = "$DATA_PATH/ServerLibraries.txt" private const val SETUP_CACHE = "$PAPER_PATH/setupCache" @@ -96,3 +95,4 @@ const val RELOCATION_EXTENSION = "relocation" fun paperSetupOutput(name: String, ext: String) = "$SETUP_CACHE/$name.$ext" fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext) fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext" +fun downloadConfigName(downloadName: String): String = "$PAPERWEIGHT_DOWNLOAD${downloadName.capitalize()}" diff --git a/paperweight-lib/src/main/kotlin/util/dependencies.kt b/paperweight-lib/src/main/kotlin/util/dependencies.kt index 6c80db5da..842100807 100644 --- a/paperweight-lib/src/main/kotlin/util/dependencies.kt +++ b/paperweight-lib/src/main/kotlin/util/dependencies.kt @@ -54,9 +54,6 @@ fun RepositoryContentDescriptor.includeFromDependencyNotation(dependencyNotation when { split.size == 1 -> includeGroup(split[0]) split.size == 2 -> includeModule(split[0], split[1]) - split.size >= 3 -> { - includeModule(split[0], split[1]) - includeVersion(split[0], split[1], split[2]) - } + split.size >= 3 -> includeVersion(split[0], split[1], split[2]) } } diff --git a/paperweight-lib/src/main/kotlin/util/download-mc-libraries.kt b/paperweight-lib/src/main/kotlin/util/download-mc-libraries.kt new file mode 100644 index 000000000..a43f0194e --- /dev/null +++ b/paperweight-lib/src/main/kotlin/util/download-mc-libraries.kt @@ -0,0 +1,61 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.util + +import io.papermc.paperweight.util.constants.* +import java.nio.file.Path +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.provider.Provider + +fun Project.downloadMinecraftLibraries( + libs: List +): Configuration = resolveWithRepos( + libs, + listOf(MC_LIBRARY_URL), + MINECRAFT_LIBRARIES +) + +fun Project.downloadMinecraftLibraries( + libs: Provider> +): Provider = libs.map { + downloadMinecraftLibraries(it) +} + +fun Project.downloadMinecraftLibrariesSources( + libs: List +): List = resolveWithRepos( + // use sources classifier, attributes didn't work for some reason (probably no gradle meta on mojang repo) + libs.map { line -> "$line:sources" }, + listOf(MC_LIBRARY_URL), + MINECRAFT_LIBRARIES_SOURCES +).let { config -> + // use lenientConfiguration as not all artifacts have sources + config.resolvedConfiguration.lenientConfiguration.files.map { it.toPath() } +} + +fun Project.downloadMinecraftLibrariesSources( + libs: Provider> +): Provider> = libs.map { + downloadMinecraftLibrariesSources(it) +} diff --git a/paperweight-lib/src/main/kotlin/util/utils.kt b/paperweight-lib/src/main/kotlin/util/utils.kt index 5216e47f1..ca1f76e43 100644 --- a/paperweight-lib/src/main/kotlin/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/util/utils.kt @@ -24,7 +24,6 @@ package io.papermc.paperweight.util import com.github.salomonbrys.kotson.fromJson import com.google.gson.* -import io.papermc.paperweight.DownloadService import io.papermc.paperweight.PaperweightException import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.constants.* @@ -48,9 +47,15 @@ import org.cadixdev.lorenz.model.ClassMapping import org.cadixdev.lorenz.model.MemberMapping import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.attributes.AttributeContainer +import org.gradle.api.attributes.Bundling +import org.gradle.api.attributes.Category +import org.gradle.api.attributes.DocsType +import org.gradle.api.attributes.Usage import org.gradle.api.file.FileSystemLocation import org.gradle.api.file.ProjectLayout import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -107,10 +112,6 @@ inline fun TaskContainer.configureTask(name: String, noinline } } -@Suppress("UNCHECKED_CAST") -val Project.download: Provider - get() = gradle.sharedServices.registrations.getByName("download").service as Provider - fun commentRegex(): Regex { return Regex("\\s*#.*") } @@ -272,5 +273,13 @@ fun JavaToolchainService.defaultJavaLauncher(project: Project): Provider> P.withDisallowChanges(): P = apply { disallowChanges() } +fun

> P.withFinalizeValueOnRead(): P = apply { finalizeValueOnRead() } fun

> P.withDisallowUnsafeRead(): P = apply { disallowUnsafeRead() } diff --git a/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt b/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt index d9d95312d..c5b5f474d 100644 --- a/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt +++ b/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt @@ -22,8 +22,6 @@ package io.papermc.paperweight.patcher -import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.PaperweightException import io.papermc.paperweight.patcher.tasks.CheckoutRepo import io.papermc.paperweight.patcher.tasks.PaperweightPatcherUpstreamData import io.papermc.paperweight.patcher.tasks.SimpleApplyGitPatches @@ -37,6 +35,7 @@ import io.papermc.paperweight.util.* import io.papermc.paperweight.util.constants.* import java.io.File import java.util.concurrent.atomic.AtomicReference +import kotlin.io.path.* import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task @@ -55,8 +54,6 @@ class PaperweightPatcher : Plugin { val patcher = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightPatcherExtension::class) - target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {} - target.tasks.register("cleanCache") { group = "paperweight" description = "Delete the project setup cache and task outputs." @@ -111,19 +108,19 @@ class PaperweightPatcher : Plugin { val upstreamDataTask = upstreamDataTaskRef.get() ?: return@afterEvaluate + val upstreamData = upstreamDataTask.readUpstreamData() + val serverProj = patcher.serverProject.forUseAtConfigurationTime().orNull ?: return@afterEvaluate + serverProj.apply(plugin = "com.github.johnrengelman.shadow") + for (upstream in patcher.upstreams) { for (patchTask in upstream.patchTasks) { patchTask.patchTask { sourceMcDevJar.convention(target, upstreamDataTask.mapUpstreamData { it.decompiledJar }) - mcLibrariesDir.convention(target, upstreamDataTask.mapUpstreamData { it.libSourceDir }) + mcLibrariesSources.from(target.downloadMinecraftLibrariesSources(upstreamData.map { it.serverLibsFile.readLines() })) } } } - val upstreamData = upstreamDataTask.readUpstreamData() - val serverProj = patcher.serverProject.forUseAtConfigurationTime().orNull ?: return@afterEvaluate - serverProj.apply(plugin = "com.github.johnrengelman.shadow") - generateReobfMappings { inputMappings.pathProvider(upstreamData.map { it.mappings }) notchToSpigotMappings.pathProvider(upstreamData.map { it.notchToSpigotMappings }) @@ -138,7 +135,7 @@ class PaperweightPatcher : Plugin { upstreamData.map { it.mcVersion }, upstreamData.map { it.vanillaJar }, upstreamData.map { it.decompiledJar }, - upstreamData.map { it.libFile ?: throw PaperweightException("No libs file?") }, + upstreamData.map { it.serverLibsFile }, upstreamData.map { it.accessTransform } ) { vanillaJarIncludes.set(upstreamData.map { it.vanillaIncludes }) @@ -153,7 +150,7 @@ class PaperweightPatcher : Plugin { upstreamData.map { it.remappedJar }, upstreamData.map { it.decompiledJar }, patcher.mcDevSourceDir.path, - upstreamData.flatMap { provider { it.libFile } }, + upstreamData.flatMap { provider { it.serverLibsFile } }, upstreamData.flatMap { provider { it.reobfPackagesToFix } } ) { mappingsFile.set(generateReobfMappings.flatMap { it.reobfMappings }) diff --git a/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt b/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt index 512700f2f..6dbfb2843 100644 --- a/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt +++ b/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt @@ -26,16 +26,12 @@ import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.* import javax.inject.Inject import kotlin.io.path.* +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.provider.ProviderFactory -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* abstract class SimpleApplyGitPatches : ControllableOutputTask() { @@ -63,9 +59,8 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() { @get:InputFile abstract val devImports: RegularFileProperty - @get:Optional - @get:InputDirectory - abstract val mcLibrariesDir: DirectoryProperty + @get:InputFiles + abstract val mcLibrariesSources: ConfigurableFileCollection @get:Input abstract val ignoreGitIgnore: Property @@ -125,7 +120,7 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() { patches = patches, decompJar = sourceMcDevJar.path, importsFile = devImports.pathOrNull, - librariesDir = mcLibrariesDir.pathOrNull, + librarySources = mcLibrariesSources.asFileTree, targetDir = srcDir, printOutput = printOutput.get() ) diff --git a/paperweight-userdev/src/main/kotlin/PaperweightUser.kt b/paperweight-userdev/src/main/kotlin/PaperweightUser.kt index af83a77f8..3bdcf43d5 100644 --- a/paperweight-userdev/src/main/kotlin/PaperweightUser.kt +++ b/paperweight-userdev/src/main/kotlin/PaperweightUser.kt @@ -22,7 +22,6 @@ package io.papermc.paperweight.userdev -import io.papermc.paperweight.DownloadService import io.papermc.paperweight.PaperweightException import io.papermc.paperweight.tasks.* import io.papermc.paperweight.userdev.attribute.Obfuscation @@ -53,8 +52,6 @@ abstract class PaperweightUser : Plugin { abstract val javaToolchainService: JavaToolchainService override fun apply(target: Project) { - target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {} - val cleanCache by target.tasks.registering { group = "paperweight" description = "Delete the project setup cache and task outputs." @@ -77,7 +74,6 @@ abstract class PaperweightUser : Plugin { parameters { cache.set(target.layout.cache) bundleZip.set(devBundleZip) - downloadService.set(target.download) } } .get() diff --git a/paperweight-userdev/src/main/kotlin/internal/setup/UserdevSetup.kt b/paperweight-userdev/src/main/kotlin/internal/setup/UserdevSetup.kt index fe0a33fe6..dc09ba91c 100644 --- a/paperweight-userdev/src/main/kotlin/internal/setup/UserdevSetup.kt +++ b/paperweight-userdev/src/main/kotlin/internal/setup/UserdevSetup.kt @@ -26,7 +26,6 @@ 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.tasks.* import io.papermc.paperweight.util.* import io.papermc.paperweight.util.constants.* @@ -38,7 +37,6 @@ import org.gradle.api.Project import org.gradle.api.file.RegularFileProperty import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging -import org.gradle.api.provider.Property import org.gradle.api.services.BuildService import org.gradle.api.services.BuildServiceParameters import org.gradle.jvm.toolchain.JavaLauncher @@ -64,7 +62,6 @@ abstract class UserdevSetup : BuildService { interface Parameters : BuildServiceParameters { val bundleZip: RegularFileProperty val cache: RegularFileProperty - val downloadService: Property } private val cache: Path @@ -78,34 +75,33 @@ abstract class UserdevSetup : BuildService { private val devBundleChanged = extractDevBundle.first val devBundleConfig = extractDevBundle.second - private val minecraftVersionManifest: JsonObject by lazy { - val minecraftManifestJson = download( - "minecraft manifest", + private lateinit var minecraftVersionManifest: JsonObject + private fun initMinecraftVersionManifest(context: Context) { + val minecraftManifestJson = context.project.downloadFileNow( MC_MANIFEST_URL, - cache.resolve(MC_MANIFEST) + MINECRAFT_MANIFEST ) val minecraftManifest = gson.fromJson(minecraftManifestJson) - val minecraftVersionManifestJson = download( - "minecraft version manifest", + val minecraftVersionManifestJson = context.project.downloadFileNow( minecraftManifest.versions.first { it.id == devBundleConfig.minecraftVersion }.url, - cache.resolve(VERSION_JSON) + MINECRAFT_VERSION_MANIFEST ) - gson.fromJson(minecraftVersionManifestJson) + minecraftVersionManifest = gson.fromJson(minecraftVersionManifestJson) } - private val vanillaServerJar: Path = cache.resolve(paperSetupOutput("downloadServerJar", "jar")) - private fun downloadVanillaServerJar() { - download( - "vanilla minecraft server jar", + private lateinit var vanillaServerJar: Path + private fun downloadVanillaServerJar(context: Context) { + initMinecraftVersionManifest(context) + vanillaServerJar = context.project.downloadFileNow( minecraftVersionManifest["downloads"]["server"]["url"].string, - vanillaServerJar + VANILLA_SERVER_JAR ) } private val filteredVanillaServerJar: Path = cache.resolve(paperSetupOutput("filterJar", "jar")) - private fun filterVanillaServerJar() { - downloadVanillaServerJar() + private fun filterVanillaServerJar(context: Context) { + downloadVanillaServerJar(context) val filteredJar = filteredVanillaServerJar val hashFile = filteredJar.resolveSibling(filteredJar.nameWithoutExtension + ".hashes") @@ -123,75 +119,44 @@ abstract class UserdevSetup : BuildService { hashFile.writeText(hash()) } - private val mojangServerMappings: Path = cache.resolve(SERVER_MAPPINGS) - private fun downloadMojangServerMappings() { - download( - "mojang server mappings", + private lateinit var mojangServerMappings: Path + private fun downloadMojangServerMappings(context: Context) { + initMinecraftVersionManifest(context) + mojangServerMappings = context.project.downloadFileNow( minecraftVersionManifest["downloads"]["server_mappings"]["url"].string, - mojangServerMappings + MOJANG_SERVER_MAPPINGS ) } - private val minecraftLibrariesFile: Path = cache.resolve(MC_LIBRARIES) - private fun writeMinecraftLibrariesFile() { - setupMinecraftLibraries( - minecraftVersionManifest["libraries"].array.map { lib -> - lib["name"].string - }, - minecraftLibrariesFile - ) - } - - private fun hashLibraries(jars: Path, sources: Path): String = - hashFiles( - sequenceOf(jars, sources) - .filter { it.isDirectory() } - .flatMap { it.listDirectoryEntries("*.jar") } - .toList() - ) - - private val minecraftLibraryJars = cache.resolve(MINECRAFT_JARS_PATH) - private val minecraftLibrarySources = cache.resolve(MINECRAFT_SOURCES_PATH) + private lateinit var minecraftLibraryJars: List private fun downloadMinecraftLibraries(context: Context) { - writeMinecraftLibrariesFile() - val jars = minecraftLibraryJars - val sources = minecraftLibrarySources - - val hashesFile = cache.resolve(paperSetupOutput("libraries", "hashes")) - val hash = { hash(hashLibraries(jars, sources), minecraftLibrariesFile) } - val upToDate = hashesFile.isRegularFile() && hashesFile.readText() == hash() - if (upToDate) return - - LOGGER.lifecycle(":downloading minecraft libraries") - downloadMinecraftLibraries( - download = parameters.downloadService, - workerExecutor = context.workerExecutor, - out = jars, - sourcesOut = null, // sources, // we don't use sources jars for anything in userdev currently - mcRepo = MC_LIBRARY_URL, - mcLibrariesFile = minecraftLibrariesFile - ).await() - hashesFile.parent.createDirectories() - hashesFile.writeText(hash()) + initMinecraftVersionManifest(context) + minecraftLibraryJars = context.project + .downloadMinecraftLibraries( + minecraftVersionManifest["libraries"].array.map { lib -> + lib["name"].string + } + ) + .map { it.toPath() } } private val mojangPlusYarnMappings: Path = cache.resolve(MOJANG_YARN_MAPPINGS) private fun generateMappings(context: Context) { downloadMinecraftLibraries(context) - downloadMojangServerMappings() - filterVanillaServerJar() + downloadMojangServerMappings(context) + filterVanillaServerJar(context) val mappingsFile = mojangPlusYarnMappings val hashFile = cache.resolve(paperSetupOutput("generateMappings", "hashes")) - val hash = { hash(hashLibraries(minecraftLibraryJars, minecraftLibrarySources), mojangServerMappings, filteredVanillaServerJar) } + val hash = { hash(minecraftLibraryJars, mojangServerMappings, filteredVanillaServerJar) } val upToDate = hashFile.isRegularFile() && hashFile.readText() == hash() if (upToDate) return LOGGER.lifecycle(":generating mappings") generateMappings( vanillaJarPath = filteredVanillaServerJar, - libraryPaths = minecraftLibraryJars.listDirectoryEntries("*.jar"), + libraryPaths = minecraftLibraryJars, vanillaMappingsPath = mojangServerMappings, paramMappingsPath = context.project.configurations.named(PARAM_MAPPINGS_CONFIG).map { it.singleFile }.convertToPath(), outputMappingsPath = mappingsFile, @@ -212,7 +177,7 @@ abstract class UserdevSetup : BuildService { val hash = { hash( - hashLibraries(minecraftLibraryJars, minecraftLibrarySources), + minecraftLibraryJars, mojangPlusYarnMappings, filteredVanillaServerJar, devBundleConfig.remap.args, @@ -230,7 +195,7 @@ abstract class UserdevSetup : BuildService { mappingsFile = mojangPlusYarnMappings, fromNamespace = OBF_NAMESPACE, toNamespace = DEOBF_NAMESPACE, - remapClasspath = minecraftLibraryJars.listDirectoryEntries("*.jar"), + remapClasspath = minecraftLibraryJars, remapper = context.project.configurations.named(REMAPPER_CONFIG).get(), outputJar = output, launcher = context.defaultJavaLauncher, @@ -292,7 +257,7 @@ abstract class UserdevSetup : BuildService { val hash = { hash( - hashLibraries(minecraftLibraryJars, minecraftLibrarySources), + minecraftLibraryJars, accessTransformedServerJar, devBundleConfig.decompile.args, output @@ -308,7 +273,7 @@ abstract class UserdevSetup : BuildService { workingDir = cache, executable = context.project.configurations.named(DECOMPILER_CONFIG).get(), inputJar = accessTransformedServerJar, - libraries = minecraftLibraryJars.listDirectoryEntries("*.jar"), + libraries = minecraftLibraryJars, outputJar = output, javaLauncher = context.defaultJavaLauncher ) @@ -450,23 +415,4 @@ abstract class UserdevSetup : BuildService { private fun hashDirectory(dir: Path): String = Files.walk(dir).use { stream -> hashFiles(stream.filter { it.isRegularFile() }.collect(Collectors.toList())) } - - private fun download( - downloadName: String, - remote: String, - destination: Path - ): Path { - val hashFile = destination.resolveSibling(destination.name + ".hashes") - - val upToDate = hashFile.isRegularFile() && - hashFile.readText() == hash(remote, destination) - if (upToDate) return destination - - LOGGER.lifecycle(":downloading $downloadName") - destination.parent.createDirectories() - parameters.downloadService.get().download(remote, destination) - hashFile.writeText(hash(remote, destination)) - - return destination - } }