Skip to content

Commit

Permalink
More cleanup, update source generator helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Dec 8, 2024
1 parent f361b18 commit 88bd533
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,20 @@ class PaperweightCore : Plugin<Project> {
*/

target.afterEvaluate {
println("SoftSpoon: ${ext.softSpoon.get()}")

target.repositories {
if (!ext.softSpoon.get()) {
maven(ext.remapRepo) {
name = REMAPPER_REPO_NAME
content { onlyForConfigurations(REMAPPER_CONFIG) }
}
} else {
maven(ext.macheRepo) {
name = MACHE_REPO_NAME
content { onlyForConfigurations(MACHE_CONFIG) }
}
/* TODO
maven(ext.remapRepo) {
name = REMAPPER_REPO_NAME
content { onlyForConfigurations(REMAPPER_CONFIG) }
}
*/
maven(ext.macheRepo) {
name = MACHE_REPO_NAME
content { onlyForConfigurations(MACHE_CONFIG) }
}
}

if (ext.softSpoon.get()) {
softSpoonTasks.afterEvaluate()
return@afterEvaluate
}
softSpoonTasks.afterEvaluate()

/*
// Setup the server jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,18 @@ import org.gradle.kotlin.dsl.*

open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) {

@Suppress("MemberVisibilityCanBePrivate")
val baseTargetDir: DirectoryProperty = objects.dirWithDefault(layout, ".")
val spigotApiPatchDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "patches/api")
val spigotServerPatchDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "patches/server")
val remappedSpigotServerPatchDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "patches/server-remapped")
val unmappedSpigotServerPatchDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "patches/server-unmapped")
val paperApiDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "paper-api")
val paperServerDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "paper-server")
val paperServerDir: DirectoryProperty = objects.directoryProperty().convention(layout.projectDirectory)
val rejectsDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/rejected")
val sourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/sources")
val resourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/resources")
val featurePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/features")

@Suppress("MemberVisibilityCanBePrivate")
val buildDataDir: DirectoryProperty = objects.dirWithDefault(layout, "../build-data")
val additionalSpigotClassMappings: RegularFileProperty = objects.fileProperty()
val devImports: RegularFileProperty = objects.fileFrom(buildDataDir, "dev-imports.txt")
val additionalAts: RegularFileProperty = objects.fileFrom(buildDataDir, "paper.at")
val reobfMappingsPatch: RegularFileProperty = objects.fileProperty()
val mappingsPatch: RegularFileProperty = objects.fileProperty()

val craftBukkitPatchPatchesDir: DirectoryProperty = objects.directoryProperty()
val spigotServerPatchPatchesDir: DirectoryProperty = objects.directoryProperty()
val spigotApiPatchPatchesDir: DirectoryProperty = objects.directoryProperty()

val reobfPackagesToFix: ListProperty<String> = objects.listProperty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package io.papermc.paperweight.core.extension

import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import java.util.Locale
import org.gradle.api.Action
Expand All @@ -36,23 +35,13 @@ import org.gradle.kotlin.dsl.*

open class PaperweightCoreExtension(project: Project, objects: ObjectFactory, layout: ProjectLayout) {

val softSpoon: Property<Boolean> = objects.property<Boolean>().convention(false)

@Suppress("MemberVisibilityCanBePrivate")
val workDir: DirectoryProperty = objects.dirWithDefault(layout, "work")

val minecraftVersion: Property<String> = objects.property()
val minecraftManifestUrl: Property<String> = objects.property<String>().convention(MC_MANIFEST_URL)
val serverProject: Property<Project> = objects.property()

val mainClass: Property<String> = objects.property<String>().convention("org.bukkit.craftbukkit.Main")
val bundlerJarName: Property<String> = objects.property<String>().convention(project.name.lowercase(Locale.ENGLISH))

val mcDevSourceDir: DirectoryProperty = objects.directoryProperty().convention(serverProject.map { it.layout.cacheDir(MC_DEV_SOURCES_DIR) })

val paramMappingsRepo: Property<String> = objects.property()
val decompileRepo: Property<String> = objects.property()
val remapRepo: Property<String> = objects.property()
val remapRepo: Property<String> = objects.property<String>().convention(PAPER_MAVEN_REPO_URL)
val macheRepo: Property<String> = objects.property<String>().convention(PAPER_MAVEN_REPO_URL)

val macheOldPath: DirectoryProperty = objects.directoryProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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.tasks.TaskContainer
import org.gradle.kotlin.dsl.*
Expand All @@ -34,6 +36,7 @@ import org.gradle.kotlin.dsl.*
open class GeneralTasks(
project: Project,
tasks: TaskContainer = project.tasks,
cache: Path = project.layout.cache,
extension: PaperweightCoreExtension = project.ext,
) : InitialTasks(project) {

Expand All @@ -42,12 +45,12 @@ open class GeneralTasks(
includes.set(extension.vanillaJarIncludes)
}

val collectAtsFromPatches by tasks.registering<CollectATsFromPatches> {
patchDir.set(extension.paper.spigotServerPatchDir)
}
val generateMappings by tasks.registering<GenerateMappings> {
vanillaJar.set(filterVanillaJar.flatMap { it.outputJar })
libraries.from(extractFromBundler.map { it.serverLibraryJars.asFileTree })

vanillaMappings.set(downloadMappings.flatMap { it.outputFile })

val mergePaperAts by tasks.registering<MergeAccessTransforms> {
firstFile.set(extension.paper.additionalAts.fileExists(project))
secondFile.set(collectAtsFromPatches.flatMap { it.outputFile })
outputMappings.set(cache.resolve(MOJANG_YARN_MAPPINGS))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ package io.papermc.paperweight.core.taskcontainers
import io.papermc.paperweight.core.ext
import io.papermc.paperweight.restamp.RestampVersion
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.tasks.mache.*
import io.papermc.paperweight.tasks.mache.DecompileJar
import io.papermc.paperweight.tasks.mache.RemapJar
import io.papermc.paperweight.tasks.mache.SetupVanilla
import io.papermc.paperweight.tasks.softspoon.ApplyFeaturePatches
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatches
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatchesFuzzy
Expand All @@ -42,6 +43,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*
Expand All @@ -52,7 +54,7 @@ open class SoftSpoonTasks(
tasks: TaskContainer = project.tasks
) {

lateinit var mache: MacheMeta
private val mache: Property<MacheMeta> = project.objects.property()

val macheCodebook by project.configurations.registering {
isTransitive = false
Expand All @@ -69,8 +71,9 @@ open class SoftSpoonTasks(
val macheConstants by project.configurations.registering {
isTransitive = false
}
val macheMinecraftLibraries by project.configurations.registering
val mappedJarOutgoing = project.configurations.consumable("mappedJarOutgoing") // For source generator modules
val macheMinecraft by project.configurations.registering
val macheMinecraftExtended by project.configurations.registering
val restampConfig = project.configurations.register(RESTAMP_CONFIG) {
defaultDependencies {
add(project.dependencies.create("io.papermc.restamp:restamp:${RestampVersion.VERSION}"))
Expand All @@ -82,9 +85,9 @@ open class SoftSpoonTasks(
serverJar.set(allTasks.extractFromBundler.flatMap { it.serverJar })
serverMappings.set(allTasks.downloadMappings.flatMap { it.outputFile })

remapperArgs.set(mache.remapperArgs)
remapperArgs.set(mache.map { it.remapperArgs })
codebookClasspath.from(macheCodebook)
minecraftClasspath.from(macheMinecraft)
minecraftClasspath.from(macheMinecraftLibraries)
remapperClasspath.from(macheRemapper)
paramMappings.from(macheParamMappings)
constants.from(macheConstants)
Expand All @@ -95,9 +98,9 @@ open class SoftSpoonTasks(
val macheDecompileJar by tasks.registering(DecompileJar::class) {
group = "mache"
inputJar.set(macheRemapJar.flatMap { it.outputJar })
decompilerArgs.set(mache.decompilerArgs)
decompilerArgs.set(mache.map { it.decompilerArgs })

minecraftClasspath.from(macheMinecraft)
minecraftClasspath.from(macheMinecraftLibraries)
decompiler.from(macheDecompiler)

outputJar.set(layout.cache.resolve(FINAL_DECOMPILE_JAR))
Expand All @@ -122,7 +125,7 @@ open class SoftSpoonTasks(
macheOld.set(project.ext.macheOldPath)
machePatches.set(layout.cache.resolve(PATCHES_FOLDER))
ats.set(mergeCollectedAts.flatMap { it.outputFile })
minecraftClasspath.from(macheMinecraft)
minecraftClasspath.from(macheMinecraftLibraries)

libraries.from(
allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir },
Expand Down Expand Up @@ -203,7 +206,7 @@ open class SoftSpoonTasks(
group = "softspoon"
description = "Rebuilds patches to the vanilla sources"

minecraftClasspath.from(macheMinecraftExtended)
minecraftClasspath.from(macheMinecraft)
atFile.set(project.ext.paper.additionalAts.fileExists(project))
atFileOut.set(project.ext.paper.additionalAts.fileExists(project))

Expand Down Expand Up @@ -269,11 +272,18 @@ open class SoftSpoonTasks(

fun afterEvaluate() {
// load mache
mache = this.project.configurations.named(MACHE_CONFIG).get().singleFile.toPath().openZip().use { zip ->
return@use gson.fromJson<MacheMeta>(zip.getPath("/mache.json").readLines().joinToString("\n"))
}
mache.set(
project.configurations.getByName(MACHE_CONFIG).singleFile.toPath().openZip().use { zip ->
gson.fromJson<MacheMeta>(zip.getPath("/mache.json").readLines().joinToString("\n"))
}
)
val mache = mache.get()
println("Loaded mache ${mache.macheVersion} for minecraft ${mache.minecraftVersion}")

mappedJarOutgoing {
outgoing.artifact(macheRemapJar)
}

// setup repos
this.project.repositories {
println("setup repos for ${project.name}")
Expand All @@ -290,11 +300,11 @@ open class SoftSpoonTasks(
}

// setup mc deps
macheMinecraft {
macheMinecraftLibraries {
extendsFrom(project.configurations.getByName(MACHE_CONFIG))
}
macheMinecraftExtended {
extendsFrom(macheMinecraft.get())
macheMinecraft {
extendsFrom(macheMinecraftLibraries.get())
withDependencies {
add(
project.dependencies.create(
Expand Down Expand Up @@ -325,7 +335,7 @@ open class SoftSpoonTasks(

// impl extends minecraft
project.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME) {
extendsFrom(macheMinecraft.get())
extendsFrom(macheMinecraftLibraries.get())
}

// add vanilla source set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class SpigotTasks(
tasks: TaskContainer = project.tasks,
cache: Path = project.layout.cache,
extension: PaperweightCoreExtension = project.ext,
) : VanillaTasks(project) {
) : GeneralTasks(project) {

val cloneSpigotBuildData by tasks.registering<CloneRepo> {
url.set("https://hub.spigotmc.org/stash/scm/spigot/builddata.git")
Expand All @@ -57,8 +57,6 @@ open class SpigotTasks(
val generateSpigotMappings by tasks.registering<GenerateSpigotMappings> {
classMappings.set(unpackSpigotBuildData.flatMap { it.classMappings })

// todo hypo update breaks generate mappings, hardcode for now
// sourceMappings.set(Path.of("D:\\IntellijProjects\\PaperClean\\.gradle\\caches\\paperweight\\mappings\\official-mojang+yarn.tiny"))
sourceMappings.set(generateMappings.flatMap { it.outputMappings })

outputMappings.set(cache.resolve(SPIGOT_MOJANG_YARN_MAPPINGS))
Expand All @@ -75,8 +73,6 @@ open class SpigotTasks(

mcVersion.set(extension.minecraftVersion)

// workDirName.set(extension.craftBukkit.buildDataInfo.asFile.map { it.parentFile.parentFile.name })

specialSourceJar.set(unpackSpigotBuildData.flatMap { it.specialSourceJar })
specialSource2Jar.set(unpackSpigotBuildData.flatMap { it.specialSource2Jar })

Expand Down

This file was deleted.

Loading

0 comments on commit 88bd533

Please sign in to comment.