Allow dev imports to pull from spigot libraries (#168)

closes https://github.com/PaperMC/paperweight/issues/131
This commit is contained in:
Jake Potrebic 2022-11-19 13:21:35 -08:00 committed by GitHub
parent 50b4ca92cf
commit c280119859
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 17 deletions

View file

@ -94,6 +94,7 @@ class PaperweightCore : Plugin<Project> {
mcLibrariesFile.set(tasks.extractFromBundler.flatMap { it.serverLibrariesTxt })
mcLibrariesDir.set(tasks.extractFromBundler.flatMap { it.serverLibraryJars })
mcLibrariesSourcesDir.set(tasks.downloadMcLibrariesSources.flatMap { it.outputDir })
spigotLibrariesSourcesDir.set(tasks.downloadSpigotDependencies.flatMap { it.outputSourcesDir })
mappings.set(tasks.patchMappings.flatMap { it.outputMappings })
notchToSpigotMappings.set(tasks.generateSpigotMappings.flatMap { it.notchToSpigotMappings })
sourceMappings.set(tasks.generateMappings.flatMap { it.outputMappings })

View file

@ -95,7 +95,7 @@ open class AllTasks(
val downloadMcLibrariesSources by tasks.registering<DownloadMcLibraries> {
mcLibrariesFile.set(extractFromBundler.flatMap { it.serverLibrariesTxt })
mcRepo.set(MC_LIBRARY_URL)
repositories.set(listOf(MC_LIBRARY_URL, MAVEN_CENTRAL_URL))
outputDir.set(cache.resolve(MINECRAFT_SOURCES_PATH))
sources.set(true)
@ -119,6 +119,7 @@ open class AllTasks(
upstreamDir.set(patchSpigotServer.flatMap { it.outputDir })
sourceMcDevJar.set(decompileJar.flatMap { it.outputJar })
mcLibrariesDir.set(downloadMcLibrariesSources.flatMap { it.outputDir })
spigotLibrariesDir.set(downloadSpigotDependencies.flatMap { it.outputSourcesDir })
devImports.set(extension.paper.devImports.fileExists(project))
unneededFiles.value(listOf("nms-patches", "applyPatches.sh", "CONTRIBUTING.md", "makePatches.sh", "README.md"))

View file

@ -168,7 +168,9 @@ open class SpigotTasks(
dependsOn(patchSpigot)
apiPom.set(patchSpigotApi.flatMap { it.outputDir.file("pom.xml") })
serverPom.set(patchSpigotServer.flatMap { it.outputDir.file("pom.xml") })
mcLibrariesFile.set(extractFromBundler.flatMap { it.serverLibrariesTxt })
outputDir.set(cache.resolve(SPIGOT_JARS_PATH))
outputSourcesDir.set(cache.resolve(SPIGOT_SOURCES_JARS_PATH))
downloader.set(downloadService)
}

View file

@ -60,6 +60,9 @@ abstract class PaperweightCorePrepareForDownstream : DefaultTask() {
@get:InputDirectory
abstract val mcLibrariesSourcesDir: DirectoryProperty
@get:InputDirectory
abstract val spigotLibrariesSourcesDir: DirectoryProperty
@get:Input
abstract val vanillaJarIncludes: ListProperty<String>
@ -122,6 +125,7 @@ abstract class PaperweightCorePrepareForDownstream : DefaultTask() {
mcLibrariesDir.path,
mcLibrariesSourcesDir.path,
mcLibrariesFile.path,
spigotLibrariesSourcesDir.path,
mappings.path,
notchToSpigotMappings.path,
sourceMappings.path,

View file

@ -65,6 +65,9 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
@get:InputDirectory
abstract val mcLibrariesDir: DirectoryProperty
@get:InputDirectory
abstract val spigotLibrariesDir: DirectoryProperty
@get:Optional
@get:InputFile
abstract val devImports: RegularFileProperty
@ -123,8 +126,8 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
patches = patches,
decompJar = sourceMcDevJar.path,
importsFile = devImports.pathOrNull,
librariesDir = mcLibrariesDir.path,
targetDir = sourceDir,
librariesDirs = listOf(spigotLibrariesDir.path, mcLibrariesDir.path),
printOutput = printOutput.get()
)

View file

@ -24,6 +24,7 @@ package io.papermc.paperweight.tasks
import io.papermc.paperweight.DownloadService
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.MavenArtifact
import java.nio.file.Path
import javax.inject.Inject
@ -67,7 +68,7 @@ abstract class DownloadMcLibraries : BaseTask() {
abstract val mcLibrariesFile: RegularFileProperty
@get:Input
abstract val mcRepo: Property<String>
abstract val repositories: ListProperty<String>
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@ -92,7 +93,7 @@ abstract class DownloadMcLibraries : BaseTask() {
downloader,
workerExecutor,
outputDir.path,
mcRepo.get(),
repositories.get(),
mcLibrariesFile.path.readLines(),
sources.get()
)
@ -103,28 +104,26 @@ fun downloadMinecraftLibraries(
download: Provider<DownloadService>,
workerExecutor: WorkerExecutor,
targetDir: Path,
mcRepo: String,
repositories: List<String>,
mcLibraries: List<String>,
sources: Boolean
): WorkQueue {
val excludes = listOf(targetDir.fileSystem.getPathMatcher("glob:*.etag"))
targetDir.deleteRecursively(excludes)
val mcRepos = listOf(mcRepo)
val queue = workerExecutor.noIsolation()
for (lib in mcLibraries) {
if (sources) {
queue.submit(DownloadSourcesToDirAction::class) {
repos.set(mcRepos)
repos.set(repositories)
artifact.set(lib)
target.set(targetDir)
downloader.set(download)
}
} else {
queue.submit(DownloadWorker::class) {
repos.set(mcRepos)
repos.set(repositories)
artifact.set(lib)
target.set(targetDir)
downloadToDir.set(true)
@ -147,9 +146,16 @@ abstract class DownloadSpigotDependencies : BaseTask() {
@get:PathSensitive(PathSensitivity.NONE)
abstract val serverPom: RegularFileProperty
@get:InputFile
@get:PathSensitive(PathSensitivity.NONE)
abstract val mcLibrariesFile: RegularFileProperty
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@get:OutputDirectory
abstract val outputSourcesDir: DirectoryProperty
@get:Internal
abstract val downloader: Property<DownloadService>
@ -160,11 +166,16 @@ abstract class DownloadSpigotDependencies : BaseTask() {
fun run() {
val apiSetup = parsePom(apiPom.path)
val serverSetup = parsePom(serverPom.path)
val mcLibraries = mcLibrariesFile.path.readLines()
val out = outputDir.path
val excludes = listOf(out.fileSystem.getPathMatcher("glob:*.etag"))
out.deleteRecursively(excludes)
val outSources = outputSourcesDir.path
val excludesSources = listOf(outSources.fileSystem.getPathMatcher("glob:*.etag"))
outSources.deleteRecursively(excludesSources)
val spigotRepos = mutableSetOf<String>()
spigotRepos += apiSetup.repos
spigotRepos += serverSetup.repos
@ -182,6 +193,14 @@ abstract class DownloadSpigotDependencies : BaseTask() {
downloadToDir.set(true)
downloader.set(this@DownloadSpigotDependencies.downloader)
}
if (!mcLibraries.contains(art.toString())) {
queue.submit(DownloadSourcesToDirAction::class) {
repos.set(spigotRepos)
artifact.set(art.toString())
target.set(outSources)
downloader.set(this@DownloadSpigotDependencies.downloader)
}
}
}
}
@ -196,7 +215,7 @@ abstract class DownloadSpigotDependencies : BaseTask() {
depList += MavenArtifact(
"org.apache.logging.log4j",
"log4j-api",
"2.16.0"
"2.17.0"
)
depList += MavenArtifact(
"org.jetbrains",
@ -205,7 +224,7 @@ abstract class DownloadSpigotDependencies : BaseTask() {
)
val repoList = arrayListOf<String>()
// Maven Central is implicit
repoList += "https://repo.maven.apache.org/maven2/"
repoList += MAVEN_CENTRAL_URL
val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
val doc = pomFile.inputStream().buffered().use { stream ->

View file

@ -176,8 +176,8 @@ abstract class RemapPatches : BaseTask() {
patches = patchesToSkip + patchesToRemap,
decompJar = spigotDecompJar.path,
importsFile = devImports.path,
librariesDir = mcLibrarySourcesDir.path,
targetDir = tempInputDir.resolve("src/main/java")
targetDir = tempInputDir.resolve("src/main/java"),
librariesDirs = listOf(mcLibrarySourcesDir.path)
)
patchApplier.commitPlain("McDev imports")

View file

@ -41,8 +41,8 @@ object McDev {
patches: Iterable<Path>,
decompJar: Path,
importsFile: Path?,
librariesDir: Path?,
targetDir: Path,
librariesDirs: List<Path> = listOf(),
printOutput: Boolean = true
) {
val patchLines = readPatchLines(patches)
@ -100,7 +100,10 @@ object McDev {
}
}
val libFiles = librariesDir?.listDirectoryEntries("*-sources.jar") ?: return
if (librariesDirs.isEmpty()) {
return
}
val libFiles = librariesDirs.flatMap { it.listDirectoryEntries("*-sources.jar") }
if (libFiles.isEmpty()) {
throw PaperweightException("No library files found")
}

View file

@ -33,6 +33,8 @@ const val MC_MANIFEST_URL = "https://piston-meta.mojang.com/mc/game/version_mani
const val PAPER_MAVEN_REPO_URL = "https://repo.papermc.io/repository/maven-public/"
const val MAVEN_CENTRAL_URL = "https://repo.maven.apache.org/maven2/"
const val PARAM_MAPPINGS_CONFIG = "paramMappings"
const val REMAPPER_CONFIG = "remapper"
const val DECOMPILER_CONFIG = "decompiler"
@ -59,6 +61,7 @@ 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"
const val SPIGOT_SOURCES_JARS_PATH = "$JARS_PATH/spigot-sources"
private const val MAPPINGS_DIR = "$PAPER_PATH/mappings"
const val SERVER_MAPPINGS = "$MAPPINGS_DIR/server_mappings.txt"

View file

@ -35,6 +35,7 @@ data class UpstreamData(
val libDir: Path,
val libSourceDir: Path,
val libFile: Path,
val spigotLibSourcesDir: Path,
val mappings: Path,
val notchToSpigotMappings: Path,
val sourceMappings: Path,

View file

@ -151,6 +151,7 @@ class PaperweightPatcher : Plugin<Project> {
patchTask.patchTask {
sourceMcDevJar.convention(target, upstreamData.map { it.decompiledJar })
mcLibrariesDir.convention(target, upstreamData.map { it.libSourceDir })
spigotLibrariesSourceDir.convention(target, upstreamData.map { it.spigotLibSourcesDir })
}
}
}

View file

@ -24,6 +24,7 @@ package io.papermc.paperweight.patcher.tasks
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import java.nio.file.Path
import javax.inject.Inject
import kotlin.io.path.*
import org.gradle.api.file.DirectoryProperty
@ -67,6 +68,10 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() {
@get:InputDirectory
abstract val mcLibrariesDir: DirectoryProperty
@get:Optional
@get:InputDirectory
abstract val spigotLibrariesSourceDir: DirectoryProperty
@get:Input
abstract val ignoreGitIgnore: Property<Boolean>
@ -119,14 +124,17 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() {
val srcDir = output.resolve("src/main/java")
val patches = patchDir.pathOrNull?.listDirectoryEntries("*.patch") ?: listOf()
val librarySources = ArrayList<Path>()
spigotLibrariesSourceDir.pathOrNull?.let { librarySources.add(it) }
mcLibrariesDir.pathOrNull?.let { librarySources.add(it) }
if (sourceMcDevJar.isPresent && importMcDev.get()) {
McDev.importMcDev(
patches = patches,
decompJar = sourceMcDevJar.path,
importsFile = devImports.pathOrNull,
librariesDir = mcLibrariesDir.pathOrNull,
targetDir = srcDir,
librariesDirs = librarySources,
printOutput = printOutput.get()
)
}

View file

@ -74,7 +74,7 @@ class SetupHandlerImplV2(
download = service.parameters.downloadService,
workerExecutor = context.workerExecutor,
targetDir = minecraftLibraryJars,
mcRepo = MC_LIBRARY_URL,
repositories = listOf(MC_LIBRARY_URL, MAVEN_CENTRAL_URL),
mcLibraries = bundle.config.buildData.vanillaServerLibraries,
sources = false
).await()