Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Sep 13, 2021
1 parent 46cc253 commit e2c5eeb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
plugins {
id 'java'
id 'cn.apisium.papershelled' version '1.0.2'
id 'cn.apisium.papershelled' version '1.0.3'
}
paperShelled {
Expand All @@ -40,7 +40,7 @@ buildscript {
}
plugins {
id 'cn.apisium.papershelled' version '1.0.2'
id 'cn.apisium.papershelled' version '1.0.3'
id 'com.github.johnrengelman.shadow' version '7.0.0'
}
Expand All @@ -54,7 +54,9 @@ paperShelled {
reobfFile = 'some/path/reobf.tiny'
spigotMap = 'spigot'
mojangMap = 'mojang+yarn'
relocateCraftBukkit = false
archiveClassifier = "-reobf"
relocateCraftBukkit = true
reobfAfterJarTask = true
}
shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion plugin-build/buildSrc/src/main/java/Coordinates.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object PluginCoordinates {
const val ID = "cn.apisium.papershelled"
const val GROUP = "cn.apisium.papershelled"
const val VERSION = "1.0.2"
const val VERSION = "1.0.3"
const val IMPLEMENTATION_CLASS = "cn.apisium.papershelled.gradle.Plugin"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ abstract class Extension @Inject constructor(private val project: Project) {
val reobfFile: RegularFileProperty = objects.fileProperty().convention(project.layout.getCache("reobf.tiny"))
val spigotMap: Property<String> = objects.property(String::class.java).convention("spigot")
val mojangMap: Property<String> = objects.property(String::class.java).convention("mojang+yarn")
val relocateCraftBukkit: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
val paperShelledJar: RegularFileProperty = objects.fileProperty().convention(project.layout.getCache("out.jar"))
val relocateCraftBukkit: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
val reobfAfterJarTask: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
val archiveClassifier: Property<String> = objects.property(String::class.java).convention("-reobf")
val craftBukkitVersion: Property<String> = objects.property(String::class.java)
.convention(project.provider {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class Plugin : Plugin<Project> {

val download = project.tasks.register("download", DownloadTask::class.java) {
it.jarUrl.set(extension.jarUrl)
it.jarFile.set(extension.jarFile)
it.downloader.set(ds)
}

Expand All @@ -26,11 +27,7 @@ abstract class Plugin : Plugin<Project> {
it.spigotMap.set(extension.spigotMap)
it.mojangMap.set(extension.mojangMap)
it.paperShelledJar.set(extension.paperShelledJar)
it.shouldRunAfter(download)
}

val setup = project.tasks.register("setupPaperShelled", SetupTask::class.java) {
it.dependsOn(download, gmj)
if (!Files.exists(it.jarFile.get().asFile.toPath())) it.dependsOn(download)
}

val reobf = project.tasks.register("reobf", ReobfTask::class.java) {
Expand All @@ -40,11 +37,12 @@ abstract class Plugin : Plugin<Project> {
it.mojangMap.set(extension.mojangMap)
it.craftBukkitVersion.set(extension.craftBukkitVersion)
it.paperShelledJar.set(extension.paperShelledJar)
it.archiveClassifier.set(extension.archiveClassifier)
if (!Files.exists(it.reobfFile.get().asFile.toPath()) ||
!Files.exists(it.paperShelledJar.get().asFile.toPath())) it.dependsOn(setup)
!Files.exists(it.paperShelledJar.get().asFile.toPath())) it.dependsOn(gmj)
}

project.tasks.withType(Jar::class.java) {
if (extension.reobfAfterJarTask.get()) project.tasks.withType(Jar::class.java) {
lastJarTask = it
it.finalizedBy(reobf)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ import kotlin.io.path.name

private const val GROUP = "papershelled"

abstract class SetupTask : DefaultTask() {
init {
description = "Setup"
group = GROUP
}

@TaskAction
fun run() = Unit
}

abstract class DownloadTask : DefaultTask() {
init {
description = "Download server jar"
Expand All @@ -42,6 +32,10 @@ abstract class DownloadTask : DefaultTask() {
@get:Option(option = "jarUrl", description = "The url to download server jar")
abstract val jarUrl: Property<String>

@get:Input
@get:Option(option = "jarFile", description = "The file path of server jar")
abstract val jarFile: RegularFileProperty

@get:Inject
abstract val workerExecutor: WorkerExecutor

Expand All @@ -54,7 +48,7 @@ abstract class DownloadTask : DefaultTask() {
workerExecutor.noIsolation().submit(DownloadWorker::class.java) {
it.downloader.set(downloader)
it.source.set(jarUrl)
it.target.set(project.layout.cache.resolve("server.jar").toFile())
it.target.set(jarFile)
}
}
}
Expand Down Expand Up @@ -148,6 +142,11 @@ abstract class ReobfTask : DefaultTask() {
@get:Optional
abstract val reobfFile: RegularFileProperty

@get:Input
@get:Option(option = "archiveClassifier", description = "The classifier of output jar")
@get:Optional
abstract val archiveClassifier: Property<String>

@get:Input
@get:Option(option = "spigotMap", description = "The map name of Spigot")
@get:Optional
Expand Down Expand Up @@ -184,8 +183,8 @@ abstract class ReobfTask : DefaultTask() {
val needRelocate = relocateCraftBukkit.get()
val path = lastJarTask!!.archiveFile.get().asFile.toPath()
val noSuffix = path.fileName.toString().removeSuffix(".jar")
val out = path.parent.resolve("$noSuffix-reobf.jar")
val temp = if (needRelocate) path.parent.resolve("$noSuffix.tmp.jar") else out
val temp = path.parent.resolve(noSuffix + archiveClassifier.get() + ".temp1.jar")
val out = path.parent.resolve(noSuffix + archiveClassifier.get() + ".jar")
try {
OutputConsumerPath.Builder(temp).build().use {
it.addNonClassFiles(path, NonClassCopyMode.FIX_META_INF, remapper)
Expand All @@ -196,10 +195,14 @@ abstract class ReobfTask : DefaultTask() {
} finally {
remapper.finish()
}
if (needRelocate) {
JarRelocator(temp.toFile(), out.toFile(), listOf(Relocation("org.bukkit.craftbukkit",
val tempOut = if (needRelocate) {
val tmp = path.parent.resolve(noSuffix + archiveClassifier.get() + ".temp2.jar")
JarRelocator(temp.toFile(), tmp.toFile(), listOf(Relocation("org.bukkit.craftbukkit",
"org.bukkit.craftbukkit." + craftBukkitVersion.get()))).run()
Files.delete(temp)
}
tmp
} else temp
if (Files.exists(out)) Files.delete(out)
Files.move(tempOut, out)
}
}

0 comments on commit e2c5eeb

Please sign in to comment.