Add Paper version back to manifest, add runShadow, runReobf, and runDev tasks for testing

This commit is contained in:
Jason Penilla 2021-06-11 18:10:12 -07:00
parent ee5185e59f
commit 5db334f804

View file

@ -24,6 +24,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer
+import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
+import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
+import io.papermc.paperweight.util.Git
+import io.papermc.paperweight.util.path
+import org.gradle.api.file.FileTreeElement
+import shadow.org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE
+import java.util.Date
@ -64,9 +66,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+tasks.jar {
+ manifest {
+ val git = Git(rootProject.layout.projectDirectory.path)
+ val gitHashCmd = git("rev-parse", "HEAD")
+ val gitHash = gitHashCmd.getText().substring(0, 7)
+ attributes(mapOf(
+ "Main-Class" to "org.bukkit.craftbukkit.Main",
+ "Implementation-Title" to "CraftBukkit",
+ "Implementation-Version" to "git-Paper-\"$gitHash\"",
+ "Implementation-Vendor" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(Date()), // Paper
+ "Specification-Title" to "Bukkit",
+ "Specification-Version" to project.version,
@ -100,6 +106,37 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class")
+}
+
+fun TaskContainer.registerRunTask(name: String, block: JavaExec.() -> Unit): TaskProvider<JavaExec> =
+ register<JavaExec>(name) {
+ group = "Paper"
+ workingDir = rootProject.projectDir.resolve("run")
+ doFirst {
+ if (!workingDir.exists()) workingDir.mkdir()
+ }
+ standardInput = System.`in`
+ args("--nogui")
+ systemProperty("net.kyori.adventure.text.warnWhenLegacyFormattingDetected", true)
+ block(this)
+ }
+
+tasks.registerRunTask("runShadow") {
+ description = "Spin up a test server from the shadowJar archiveFile"
+ classpath(tasks.shadowJar.flatMap { it.archiveFile })
+}
+
+tasks.registerRunTask("runReobf") {
+ description = "Spin up a test server from the reobfJar output jar"
+ classpath(tasks.reobfJar.flatMap { it.outputJar })
+}
+
+tasks.registerRunTask("runDev") {
+ description = "Spin up a non-shaded non-remapped test server"
+ classpath = project.convention.getPlugin(JavaPluginConvention::class.java)
+ .sourceSets.getByName("main").runtimeClasspath
+ main = "org.bukkit.craftbukkit.Main"
+ systemProperty("disable.watchdog", true)
+}
+
+class ModifiedLog4j2PluginsCacheFileTransformer : Transformer by Log4j2PluginsCacheFileTransformer() {
+ override fun canTransformResource(element: FileTreeElement): Boolean {
+ return PLUGIN_CACHE_FILE == element.name || element.name == "Log4j2Plugins.dat"