Skip to content

Commit

Permalink
Move general configuration from CoreTasks to PaperweightCore
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 6, 2025
1 parent ef8e7d4 commit 01f4198
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,35 @@ import io.papermc.paperweight.core.extension.PaperweightCoreExtension
import io.papermc.paperweight.core.taskcontainers.CoreTasks
import io.papermc.paperweight.core.taskcontainers.DevBundleTasks
import io.papermc.paperweight.core.taskcontainers.PaperclipTasks
import io.papermc.paperweight.core.util.createBuildTasks
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.DependencyFactory
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.kotlin.dsl.*

abstract class PaperweightCore : Plugin<Project> {
@get:Inject
abstract val layout: ProjectLayout

@get:Inject
abstract val dependencyFactory: DependencyFactory

@get:Inject
abstract val objects: ObjectFactory

override fun apply(target: Project) {
Git.checkForGit(target.providers)
printId<PaperweightCore>("paperweight-core", target.gradle)
Expand All @@ -53,53 +70,71 @@ abstract class PaperweightCore : Plugin<Project> {
target.tasks.register<Delete>("cleanCache") {
group = GENERAL_TASK_GROUP
description = "Delete the project setup cache and task outputs."
delete(target.layout.cache)
delete(layout.cache)
}

target.configurations.create(REMAPPER_CONFIG) {
defaultDependencies {
add(
target.dependencies.create(
"${listOf("net", "fabricmc").joinToString(".")}:tiny-remapper:${LibraryVersions.TINY_REMAPPER}:fat"
) {
isTransitive = false
}
)
// Join list to avoid relocations breaking the string
val coordinates = "${listOf("net", "fabricmc").joinToString(".")}:tiny-remapper:${LibraryVersions.TINY_REMAPPER}:fat"
val remapper = dependencyFactory.create(coordinates).also { it.isTransitive = false }
add(remapper)
}
}
target.configurations.create(PAPERCLIP_CONFIG)
target.configurations.create(MACHE_CONFIG) {
attributes.attribute(MacheOutput.ATTRIBUTE, target.objects.named(MacheOutput.ZIP))
val macheConfig = target.configurations.create(MACHE_CONFIG) {
attributes.attribute(MacheOutput.ATTRIBUTE, objects.named(MacheOutput.ZIP))
}
target.configurations.register(MACHE_CODEBOOK_CONFIG) { isTransitive = false }
target.configurations.register(MACHE_REMAPPER_CONFIG) { isTransitive = false }
target.configurations.register(MACHE_DECOMPILER_CONFIG) { isTransitive = false }
target.configurations.register(MACHE_PARAM_MAPPINGS_CONFIG) { isTransitive = false }
target.configurations.register(MACHE_CONSTANTS_CONFIG) { isTransitive = false }
target.configurations.register(MACHE_MINECRAFT_LIBRARIES_CONFIG)
val macheMinecraftLibrariesConfig = target.configurations.register(MACHE_MINECRAFT_LIBRARIES_CONFIG) {
extendsFrom(macheConfig)
}
target.configurations.register(MACHE_MINECRAFT_CONFIG) {
extendsFrom(macheMinecraftLibrariesConfig.get())
}
target.configurations.consumable(MAPPED_JAR_OUTGOING_CONFIG) // For source generator modules
target.configurations.register(MACHE_MINECRAFT_CONFIG)
target.configurations.register(JST_CONFIG) {
defaultDependencies {
// add(project.dependencies.create("net.neoforged.jst:jst-cli-bundle:${JSTVersion.VERSION}"))
// add(project.dependencies.create("net.neoforged.jst:jst-cli-bundle:${LibraryVersions.JST}"))
add(target.dependencies.create("io.papermc.jst:jst-cli-bundle:${LibraryVersions.JST}"))
}
}

// impl extends minecraft
target.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME) {
extendsFrom(macheMinecraftLibrariesConfig.get())
}

if (target.providers.gradleProperty("paperweight.dev").orNull == "true") {
target.tasks.register<CreateDiffOutput>("diff") {
inputDir.convention(ext.paper.paperServerDir.map { it.dir("src/main/java") })
val prop = target.providers.gradleProperty("paperweight.diff.output")
if (prop.isPresent) {
baseDir.convention(target.layout.projectDirectory.dir(prop))
baseDir.convention(layout.projectDirectory.dir(prop))
}
}
}

val mache: Property<MacheMeta> = target.objects.property()
val mache: Property<MacheMeta> = objects.property()
val tasks = CoreTasks(target, mache)
val devBundleTasks = DevBundleTasks(target, tasks)

target.configurations.named(MAPPED_JAR_OUTGOING_CONFIG) {
outgoing.artifact(tasks.macheRemapJar)
}
target.configurations.named(MACHE_MINECRAFT_CONFIG) {
withDependencies {
val minecraftJar = dependencyFactory.create(
layout.files(tasks.macheRemapJar.flatMap { it.outputJar })
)
add(minecraftJar)
}
}

val jar = target.tasks.named("jar", AbstractArchiveTask::class)
tasks.generateReobfMappings {
inputJar.set(jar.flatMap { it.archiveFile })
Expand All @@ -110,8 +145,9 @@ abstract class PaperweightCore : Plugin<Project> {
val (includeMappings, reobfJar) = target.createBuildTasks(
ext.spigot.packageVersion,
ext.reobfPackagesToFix,
tasks.generateRelocatedReobfMappings
tasks.generateRelocatedReobfMappings.flatMap { it.outputMappings },
)

PaperclipTasks(
target,
ext.bundlerJarName,
Expand All @@ -125,15 +161,30 @@ abstract class PaperweightCore : Plugin<Project> {
)

target.afterEvaluate {
target.repositories {
// add Minecraft source dirs
// for some reason doing this in #apply instead of afterEvaluate causes fork compileJava to take 5x longer (due to order of source dirs)
target.extensions.configure<JavaPluginExtension> {
sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) {
java {
srcDirs(layout.projectDirectory.dir("src/minecraft/java"))
}
resources {
srcDirs(layout.projectDirectory.dir("src/minecraft/resources"))
}
}
}

repositories {
maven(ext.macheRepo) {
name = MACHE_REPO_NAME
content { onlyForConfigurations(MACHE_CONFIG) }
}
}

// load mache
mache.set(project.configurations.resolveMacheMeta())
mache.set(configurations.resolveMacheMeta())
mache.get().addRepositories(this)
mache.get().addDependencies(this)

tasks.afterEvaluate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
import java.nio.file.Files
import org.gradle.api.Project
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 Down Expand Up @@ -128,49 +125,7 @@ class CoreTasks(
}

fun afterEvaluate() {
val mache = mache.get()

setupPatchingTasks()

project.configurations.named(MAPPED_JAR_OUTGOING_CONFIG) {
outgoing.artifact(macheRemapJar)
}

// setup repos
mache.addRepositories(project)

// setup mc deps
project.configurations.named(MACHE_MINECRAFT_LIBRARIES_CONFIG) {
extendsFrom(project.configurations.getByName(MACHE_CONFIG))
}
project.configurations.named(MACHE_MINECRAFT_CONFIG) {
extendsFrom(project.configurations.getByName(MACHE_MINECRAFT_LIBRARIES_CONFIG))
withDependencies {
add(
project.dependencies.create(
project.files(macheRemapJar.flatMap { it.outputJar })
)
)
}
}

// setup mache deps
mache.addDependencies(project)

// impl extends minecraft
project.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME) {
extendsFrom(project.configurations.getByName(MACHE_MINECRAFT_LIBRARIES_CONFIG))
}

// add Minecraft source dir
project.the<JavaPluginExtension>().sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) {
java {
srcDirs(project.projectDir.resolve("src/minecraft/java"))
}
resources {
srcDirs(project.projectDir.resolve("src/minecraft/resources"))
}
}
}

private fun setupPatchingTasks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package io.papermc.paperweight.core.taskcontainers

import com.google.gson.JsonObject
import io.papermc.paperweight.core.util.reobfRequiresDebug
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
* USA
*/

package io.papermc.paperweight.util
package io.papermc.paperweight.core.util

import io.papermc.paperweight.PaperweightException
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.AbstractArchiveTask
Expand All @@ -35,8 +37,8 @@ import org.gradle.kotlin.dsl.*
fun Project.createBuildTasks(
craftBukkitPackageVersion: Provider<String>,
packagesToFix: Provider<List<String>?>,
relocatedReobfMappings: TaskProvider<GenerateRelocatedReobfMappings>
): ServerTasks {
relocatedReobfMappings: Provider<RegularFile>
): ServerBuildTasks {
val fixJarForReobf by tasks.registering<FixJarForReobf> {
group = "build"
inputJar.set(tasks.named("jar", AbstractArchiveTask::class).flatMap { it.archiveFile })
Expand All @@ -46,7 +48,7 @@ fun Project.createBuildTasks(
val includeMappings by tasks.registering<IncludeMappings> {
group = "build"
inputJar.set(fixJarForReobf.flatMap { it.outputJar })
mappings.set(relocatedReobfMappings.flatMap { it.outputMappings })
mappings.set(relocatedReobfMappings)
mappingsDest.set("META-INF/mappings/reobf.tiny")
}

Expand All @@ -72,7 +74,7 @@ fun Project.createBuildTasks(

inputJar.set(relocateConstants.flatMap { it.outputJar })

mappingsFile.set(relocatedReobfMappings.flatMap { it.outputMappings })
mappingsFile.set(relocatedReobfMappings)

fromNamespace.set(DEOBF_NAMESPACE)
toNamespace.set(SPIGOT_NAMESPACE)
Expand All @@ -83,7 +85,7 @@ fun Project.createBuildTasks(
outputJar.set(layout.buildDirectory.map { it.dir("libs").file("${project.name}-${project.version}-reobf.jar") })
}

return ServerTasks(includeMappings, reobfJar)
return ServerBuildTasks(includeMappings, reobfJar)
}

fun Task.reobfRequiresDebug() {
Expand All @@ -98,7 +100,7 @@ fun Task.reobfRequiresDebug() {
}
}

data class ServerTasks(
data class ServerBuildTasks(
val includeMappings: TaskProvider<IncludeMappings>,
val reobfJar: TaskProvider<RemapJar>,
)

0 comments on commit 01f4198

Please sign in to comment.