-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a6fcf9
commit 48c769e
Showing
9 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/dev/mythicdrops/gradle/spigot/DownloadSpigotBuildToolsTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.kotlin.dsl.withGroovyBuilder | ||
|
||
/** | ||
* Task to download Spigot Build Tools to the build directory. | ||
*/ | ||
abstract class DownloadSpigotBuildToolsTask : DefaultTask() { | ||
@get:Input | ||
abstract val downloadUrl: Property<String> | ||
|
||
@get:OutputFile | ||
abstract val downloadedJar: RegularFileProperty | ||
|
||
init { | ||
description = "Download Spigot BuildTools.jar into a build directory for use." | ||
group = "spigot" | ||
downloadUrl.convention( | ||
"https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar", | ||
) | ||
} | ||
|
||
@TaskAction | ||
fun download() { | ||
ant.withGroovyBuilder { | ||
"get"("src" to downloadUrl.get(), "dest" to downloadedJar.get().asFile.toPath()) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/dev/mythicdrops/gradle/spigot/MythicDropsSpigotBuildToolsExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
|
||
interface MythicDropsSpigotBuildToolsExtension { | ||
/** | ||
* Location of the BuildTools.jar | ||
*/ | ||
val buildToolsLocation: RegularFileProperty | ||
|
||
/** | ||
* Should a version with `--remapped` also be run? | ||
*/ | ||
val includeRemapped: Property<Boolean> | ||
|
||
/** | ||
* Which version of Spigot to build and publish into [mavenLocal()]. | ||
*/ | ||
val version: Property<String> | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/dev/mythicdrops/gradle/spigot/MythicDropsSpigotBuildToolsGradlePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import io.github.patrick.gradle.remapper.RemapTask | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.jvm.tasks.Jar | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.named | ||
import org.gradle.kotlin.dsl.register | ||
import org.gradle.kotlin.dsl.registerIfAbsent | ||
|
||
class MythicDropsSpigotBuildToolsGradlePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
val extension = | ||
target.extensions.create<MythicDropsSpigotBuildToolsExtension>("spigotBuildTools").apply { | ||
buildToolsLocation.convention( | ||
target.rootProject.layout.buildDirectory.file("spigot-build-tools/BuildTools.jar"), | ||
) | ||
includeRemapped.convention(true) | ||
version.convention("") | ||
} | ||
|
||
// Register sync task | ||
target.gradle.sharedServices.registerIfAbsent(SyncTaskBuildService.NAME, SyncTaskBuildService::class) { | ||
// throttle the usages of the build tools | ||
maxParallelUsages.set(1) | ||
} | ||
|
||
val downloadTask = | ||
target.tasks.create<DownloadSpigotBuildToolsTask>("downloadSpigotBuildTools") { | ||
downloadedJar.set(extension.buildToolsLocation) | ||
} | ||
target.tasks.register<RunSpigotBuildToolsTask>("runSpigotBuildTools") { | ||
buildToolsLocation.set(extension.buildToolsLocation) | ||
includeRemapped.set(extension.includeRemapped) | ||
version.set(extension.version) | ||
dependsOn(downloadTask) | ||
} | ||
|
||
target.plugins.apply("io.github.patrick.remapper") | ||
target.tasks.named<RemapTask>("remap") { | ||
version.set(extension.version) | ||
dependsOn("jar") | ||
} | ||
target.tasks.named<Jar>("jar") { | ||
finalizedBy("remap") | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.FileSystemOperations | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.services.ServiceReference | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.process.ExecOperations | ||
import java.io.File | ||
import java.nio.file.Paths | ||
import javax.inject.Inject | ||
|
||
abstract class RunSpigotBuildToolsTask | ||
@Inject | ||
constructor( | ||
private val execOperations: ExecOperations, | ||
private val fileSystemOperations: FileSystemOperations, | ||
) : DefaultTask() { | ||
@get:ServiceReference(SyncTaskBuildService.NAME) | ||
Check warning on line 22 in src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt GitHub Actions / qodanaUnstable API Usage
|
||
abstract val syncTask: Property<SyncTaskBuildService> | ||
|
||
@get:InputFile | ||
abstract val buildToolsLocation: RegularFileProperty | ||
|
||
@get:Input | ||
abstract val includeRemapped: Property<Boolean> | ||
|
||
@get:Input | ||
abstract val version: Property<String> | ||
|
||
init { | ||
description = "Runs Spigot BuildTools.jar for a specific Minecraft version" | ||
group = "spigot" | ||
} | ||
|
||
@TaskAction | ||
fun runSpigotBuildTools() { | ||
val version = version.getOrElse("") | ||
if (version.isBlank()) { | ||
logger.lifecycle("Not running Spigot build tools as the version is blank") | ||
return | ||
} | ||
|
||
val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile() | ||
if (!mavenLocalDirectory.exists()) { | ||
logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}") | ||
mavenLocalDirectory.mkdirs() | ||
} | ||
|
||
normalVersion(mavenLocalDirectory, version) | ||
if (includeRemapped.getOrElse(false)) { | ||
remappedVersion(mavenLocalDirectory, version) | ||
} | ||
} | ||
|
||
private fun normalVersion( | ||
mavenLocalDirectory: File, | ||
version: String, | ||
) { | ||
val versionJar = | ||
mavenLocalDirectory.resolve( | ||
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT.jar", | ||
) | ||
if (versionJar.exists()) { | ||
logger.lifecycle("Skipping $version as Spigot JAR is found at ${versionJar.absolutePath}") | ||
return | ||
} | ||
val jar = buildToolsLocation.get().asFile | ||
val versionDir = jar.parentFile.resolve(version) | ||
fileSystemOperations.copy { | ||
from(jar) | ||
into(versionDir) | ||
} | ||
execOperations.javaexec { | ||
args(listOf("--rev", version)) | ||
workingDir = versionDir.absoluteFile | ||
jvmArgs = listOf("-Xmx1024M") | ||
classpath(buildToolsLocation) | ||
} | ||
} | ||
|
||
private fun remappedVersion( | ||
mavenLocalDirectory: File, | ||
version: String, | ||
) { | ||
val versionJar = | ||
mavenLocalDirectory.resolve( | ||
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT-remapped-mojang.jar", | ||
) | ||
if (versionJar.exists()) { | ||
logger.lifecycle("Skipping $version as Spigot remapped JAR is found at ${versionJar.absolutePath}") | ||
return | ||
} | ||
val jar = buildToolsLocation.get().asFile | ||
val versionDir = jar.parentFile.resolve(version) | ||
fileSystemOperations.copy { | ||
from(jar) | ||
into(versionDir) | ||
} | ||
execOperations.javaexec { | ||
args(listOf("--rev", version, "--remapped")) | ||
workingDir = versionDir.absoluteFile | ||
jvmArgs = listOf("-Xmx1024M") | ||
classpath(buildToolsLocation) | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/dev/mythicdrops/gradle/spigot/SyncTaskBuildService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.services.BuildService | ||
import org.gradle.api.services.BuildServiceParameters | ||
|
||
/** | ||
* Used for preventing multiple expensive tasks from being used simultaneously. | ||
*/ | ||
abstract class SyncTaskBuildService : BuildService<SyncTaskBuildService.Params> { | ||
companion object { | ||
const val NAME = "mythicDropsSyncTask" | ||
} | ||
|
||
interface Params : BuildServiceParameters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=7.0.* | ||
version=7.1.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters