Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla authored and kennytv committed Aug 9, 2023
1 parent de15167 commit 0d3d960
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ class PaperweightCore : Plugin<Project> {
tasks.generateReobfMappings {
inputJar.set(shadowJar.flatMap { it.archiveFile })
}
tasks.generateRelocatedReobfMappings {
inputJar.set(shadowJar.flatMap { it.archiveFile })
}

val (_, reobfJar) = serverProj.setupServerProject(
val (includeMappings, reobfJar) = serverProj.setupServerProject(
target,
tasks.lineMapJar.flatMap { it.outputJar },
tasks.decompileJar.flatMap { it.outputJar },
ext.mcDevSourceDir.path,
cache.resolve(SERVER_LIBRARIES_TXT),
ext.paper.reobfPackagesToFix,
tasks.patchReobfMappings.flatMap { it.outputMappings }
tasks.patchReobfMappings.flatMap { it.outputMappings },
tasks.generateRelocatedReobfMappings
) ?: return@afterEvaluate

devBundleTasks.configure(
Expand All @@ -167,7 +171,7 @@ class PaperweightCore : Plugin<Project> {
tasks.extractFromBundler.map { it.versionJson.path }.convertToFileProvider(layout, providers)
) {
vanillaJarIncludes.set(ext.vanillaJarIncludes)
reobfMappingsFile.set(tasks.patchReobfMappings.flatMap { it.outputMappings })
reobfMappingsFile.set(tasks.generateRelocatedReobfMappings.flatMap { it.outputMappings })

paramMappingsCoordinates.set(
target.provider {
Expand All @@ -182,7 +186,7 @@ class PaperweightCore : Plugin<Project> {
tasks.extractFromBundler.flatMap { it.versionJson },
tasks.extractFromBundler.flatMap { it.serverLibrariesList },
tasks.downloadServerJar.flatMap { it.outputJar },
shadowJar,
includeMappings.flatMap { it.outputJar },
reobfJar,
ext.minecraftVersion
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,9 @@ open class AllTasks(

outputMappings.set(cache.resolve(PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS))
}

val generateRelocatedReobfMappings by tasks.registering<GenerateRelocatedReobfMappings> {
inputMappings.set(patchReobfMappings.flatMap { it.outputMappings })
outputMappings.set(cache.resolve(RELOCATED_PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS))
}
}
6 changes: 6 additions & 0 deletions paperweight-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ plugins {
`config-kotlin`
}

repositories {
gradlePluginPortal()
}

dependencies {
implementation(libs.httpclient)
implementation(libs.kotson)
Expand All @@ -20,4 +24,6 @@ dependencies {
implementation("net.minecraftforge:DiffPatch:2.0.7:all") {
isTransitive = false
}

compileOnly(libs.gradle.shadow)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.extension

import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.property

abstract class PaperweightServerExtension(objects: ObjectFactory) {
val craftBukkitPackageVersion: Property<String> = objects.property()
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.gradle.api.Project
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
import org.gradle.kotlin.dsl.*

@Suppress("MemberVisibilityCanBePrivate")
Expand Down Expand Up @@ -60,15 +59,15 @@ class BundlerJarTasks(
bundlerVersionJson: Provider<RegularFile>,
serverLibrariesList: Provider<RegularFile>,
vanillaJar: Provider<RegularFile>,
shadowJar: TaskProvider<out AbstractArchiveTask>,
mojangJar: Provider<RegularFile>,
reobfJar: TaskProvider<RemapJar>,
mcVersion: Provider<String>
) {
createBundlerJar.configureWith(
bundlerVersionJson,
serverLibrariesList,
vanillaJar,
shadowJar.flatMap { it.archiveFile },
mojangJar,
)
createReobfBundlerJar.configureWith(
bundlerVersionJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package io.papermc.paperweight.taskcontainers

import io.papermc.paperweight.extension.RelocationExtension
import io.papermc.paperweight.taskcontainers.BundlerJarTasks.Companion.registerVersionArtifact
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
Expand Down Expand Up @@ -106,7 +105,7 @@ class DevBundleTasks(
serverProject.set(serverProj)
runtimeConfiguration.set(project.configurations.named(SERVER_RUNTIME_CLASSPATH))

relocations.set(serverProj.the<RelocationExtension>().relocations.map { gson.toJson(it) })
relocations.set(gson.toJson(listOf<Relocation>()))
decompiledJar.pathProvider(decompileJar)
atFile.pathProvider(accessTransformFile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

package io.papermc.paperweight.tasks

import io.papermc.paperweight.extension.Relocation
import io.papermc.paperweight.extension.RelocationWrapper
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class GenerateReobfMappings : JavaLauncherTask() {
abstract val reobfMappings: RegularFileProperty

@get:Internal
abstract val jvmargs: ListProperty<String>
abstract val jvmArgs: ListProperty<String>

@get:Inject
abstract val workerExecutor: WorkerExecutor
Expand All @@ -86,13 +86,13 @@ abstract class GenerateReobfMappings : JavaLauncherTask() {
override fun init() {
super.init()

jvmargs.convention(listOf("-Xmx2G"))
jvmArgs.convention(listOf("-Xmx2G"))
}

@TaskAction
fun run() {
val queue = workerExecutor.processIsolation {
forkOptions.jvmArgs(jvmargs.get())
forkOptions.jvmArgs(jvmArgs.get())
forkOptions.executable(launcher.get().executablePath.path.absolutePathString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ abstract class RemapJar : JavaLauncherTask() {
@get:Internal
abstract val jvmArgs: ListProperty<String>

@get:Input
abstract val markReobf: Property<Boolean>

override fun init() {
super.init()

outputJar.convention(defaultOutput())
jvmArgs.convention(listOf("-Xmx1G"))
markReobf.convention(false)
remapperArgs.convention(TinyRemapper.createArgsList())
}

Expand All @@ -91,6 +95,13 @@ abstract class RemapJar : JavaLauncherTask() {
workingDir = layout.cache,
jvmArgs = jvmArgs.get()
)
outputJar.path.openZip().use { fs ->
val reobf = fs.getPath("META-INF/.reobf")
val moj = fs.getPath("META-INF/.mojang-mapped")
moj.deleteIfExists()
reobf.parent.createDirectories()
reobf.createFile()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const val PATCHED_SPIGOT_MOJANG_YARN_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yar
const val PATCHED_SPIGOT_MOJANG_YARN_SOURCE_MAPPINGS = "$MAPPINGS_DIR/spigot-mojang+yarn-patched-source.tiny"
const val REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf.tiny"
const val PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf-patched.tiny"
const val RELOCATED_PATCHED_REOBF_MOJANG_SPIGOT_MAPPINGS = "$MAPPINGS_DIR/mojang+yarn-spigot-reobf-patched-relocated.tiny"

const val OBF_NAMESPACE = "official"
const val SPIGOT_NAMESPACE = "spigot"
Expand All @@ -113,8 +114,6 @@ const val MC_DEV_SOURCES_DIR = "$PAPER_PATH/mc-dev-sources"

const val IVY_REPOSITORY = "$PAPER_PATH/ivyRepository"

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"
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

package io.papermc.paperweight.util

import io.papermc.paperweight.extension.RelocationExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.paperweight.extension.PaperweightServerExtension
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.constants.*
import java.nio.file.Path
Expand All @@ -37,7 +38,6 @@ import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.ide.idea.model.IdeaModel

Expand All @@ -49,14 +49,18 @@ fun Project.setupServerProject(
libsFile: Any,
packagesToFix: Provider<List<String>?>,
reobfMappings: Provider<RegularFile>,
relocatedReobfMappings: TaskProvider<GenerateRelocatedReobfMappings>,
): ServerTasks? {
if (!projectDir.exists()) {
return null
}

plugins.apply("java")

extensions.create<RelocationExtension>(RELOCATION_EXTENSION, objects)
val serverExt = extensions.create<PaperweightServerExtension>(PAPERWEIGHT_EXTENSION, objects)
relocatedReobfMappings {
craftBukkitPackageVersion.set(serverExt.craftBukkitPackageVersion)
}

exportRuntimeClasspathTo(parent)

Expand Down Expand Up @@ -101,7 +105,7 @@ fun Project.setupServerProject(
addMcDevSourcesRoot(mcDevSourceDir)

plugins.apply("com.github.johnrengelman.shadow")
return createBuildTasks(parent, packagesToFix, reobfMappings)
return createBuildTasks(parent, serverExt, vanillaServer, packagesToFix, reobfMappings, relocatedReobfMappings)
}

private fun Project.exportRuntimeClasspathTo(parent: Project) {
Expand Down Expand Up @@ -134,23 +138,45 @@ private fun Project.exportRuntimeClasspathTo(parent: Project) {

private fun Project.createBuildTasks(
parent: Project,
serverExt: PaperweightServerExtension,
vanillaServer: Configuration,
packagesToFix: Provider<List<String>?>,
reobfMappings: Provider<RegularFile>
reobfMappings: Provider<RegularFile>,
relocatedReobfMappings: TaskProvider<GenerateRelocatedReobfMappings>
): ServerTasks {
val shadowJar: TaskProvider<Jar> = tasks.named("shadowJar", Jar::class)
val shadowJar: TaskProvider<ShadowJar> = tasks.named("shadowJar", ShadowJar::class) {
archiveClassifier.set("mojang-mapped")
configurations = listOf(vanillaServer)
}

val fixJarForReobf by tasks.registering<FixJarForReobf> {
dependsOn(shadowJar)

inputJar.set(shadowJar.flatMap { it.archiveFile })
packagesToProcess.set(packagesToFix)
}

val includeMappings by tasks.registering<IncludeMappings> {
inputJar.set(fixJarForReobf.flatMap { it.outputJar })
mappings.set(relocatedReobfMappings.flatMap { it.outputMappings })
mappingsDest.set("META-INF/mappings/reobf.tiny")
}

val relocatedShadowJar by tasks.registering<ShadowJar> {
archiveClassifier.set("mojang-mapped-relocated")
from(zipTree(includeMappings.flatMap { it.outputJar }))
}
afterEvaluate {
relocatedShadowJar {
relocate("org.bukkit.craftbukkit", "org.bukkit.craftbukkit.${serverExt.craftBukkitPackageVersion.get()}") {
exclude("org.bukkit.craftbukkit.Main*")
}
}
}

val reobfJar by tasks.registering<RemapJar> {
group = "paperweight"
description = "Re-obfuscate the built jar to obf mappings"

inputJar.set(fixJarForReobf.flatMap { it.outputJar })
inputJar.set(relocatedShadowJar.flatMap { it.archiveFile })

mappingsFile.set(reobfMappings)

Expand All @@ -163,11 +189,11 @@ private fun Project.createBuildTasks(
outputJar.set(buildDir.resolve("libs/${project.name}-${project.version}-reobf.jar"))
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,7 @@
* USA
*/

package io.papermc.paperweight.extension

import org.gradle.api.model.ObjectFactory
import org.gradle.kotlin.dsl.*

abstract class RelocationExtension(objects: ObjectFactory) {
val relocations = objects.listProperty<Relocation>()

fun relocate(
owningLibraryCoordinates: String,
relocation: Pair<String, String>,
config: Relocation.() -> Unit = {}
) {
relocations.add(Relocation(owningLibraryCoordinates, relocation.first, relocation.second, arrayListOf()).apply(config))
}

fun relocate(
relocation: Pair<String, String>,
config: Relocation.() -> Unit = {}
) {
relocations.add(Relocation(null, relocation.first, relocation.second, arrayListOf()).apply(config))
}
}
package io.papermc.paperweight.util

data class Relocation(
val owningLibraryCoordinates: String?,
Expand Down
Loading

0 comments on commit 0d3d960

Please sign in to comment.