-
-
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 be6e33c
Showing
5 changed files
with
128 additions
and
0 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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
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") | ||
downloadedJar.convention(project.layout.buildDirectory.file("spigot-build-tools/BuildTools.jar")) | ||
} | ||
|
||
@TaskAction | ||
fun download() { | ||
ant.withGroovyBuilder { | ||
"get"("src" to downloadUrl, "dest" to downloadedJar.get().asFile.toPath()) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
|
||
interface MythicDropsSpigotBuildToolsExtension { | ||
/** | ||
* Should existing versions not be built? | ||
*/ | ||
val isSkipExistingVersions: Property<Boolean> | ||
|
||
/** | ||
* Which versions of Spigot to build and publish into [mavenLocal()]. | ||
*/ | ||
val versions: ListProperty<String> | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
package dev.mythicdrops.gradle.spigot | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.create | ||
|
||
class MythicDropsSpigotBuildToolsGradlePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
target.extensions.create<MythicDropsSpigotBuildToolsExtension>("spigotBuildTools").apply { | ||
isSkipExistingVersions.convention(true) | ||
versions.convention(emptyList()) | ||
} | ||
|
||
val downloadTask = target.tasks.create<DownloadSpigotBuildToolsTask>("downloadSpigotBuildTools") | ||
target.tasks.create<RunSpigotBuildToolsTask>("runSpigotBuildTools").apply { dependsOn(downloadTask) } | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
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.tasks.InputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.gradle.process.ExecOperations | ||
import java.nio.file.Paths | ||
import javax.inject.Inject | ||
|
||
abstract class RunSpigotBuildToolsTask | ||
@Inject | ||
constructor( | ||
private val execOperations: ExecOperations, | ||
private val fileSystemOperations: FileSystemOperations, | ||
) : DefaultTask() { | ||
@get:InputFile | ||
abstract val buildToolsJar: RegularFileProperty | ||
|
||
init { | ||
buildToolsJar.convention(project.layout.buildDirectory.file("spigot-build-tools/BuildTools.jar")) | ||
} | ||
|
||
@TaskAction | ||
fun runSpigotBuildTools() { | ||
val buildToolsExtension = project.extensions.getByType<MythicDropsSpigotBuildToolsExtension>() | ||
buildToolsExtension.versions.getOrElse(emptyList()).forEach { | ||
val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile() | ||
if (!mavenLocalDirectory.exists()) { | ||
logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}") | ||
mavenLocalDirectory.mkdirs() | ||
} | ||
val versionJar = | ||
mavenLocalDirectory.resolve("org/spigotmc/spigot/$it-R0.1-SNAPSHOT/spigot-$it-R0.1-SNAPSHOT.jar") | ||
if (versionJar.exists()) { | ||
logger.lifecycle("Skipping $it as Spigot JAR is found at ${versionJar.absolutePath}") | ||
return@forEach | ||
} | ||
val jar = buildToolsJar.get().asFile | ||
val versionDir = jar.parentFile.resolve(it) | ||
fileSystemOperations.copy { | ||
from(jar) | ||
into(versionDir) | ||
} | ||
execOperations.javaexec { | ||
args(listOf("-jar", jar, "--rev", it)) | ||
workingDir = versionDir.absoluteFile | ||
jvmArgs = listOf("-Xmx1024M") | ||
} | ||
} | ||
} | ||
} |