Initial commit
This commit is contained in:
32
runbroker-plugin/build.gradle.kts
Normal file
32
runbroker-plugin/build.gradle.kts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright © 2025 RTAkland
|
||||
* Date: 2025/4/28 22:03
|
||||
* Open Source Under Apache-2.0 License
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("com.gradle.plugin-publish") version "1.2.1"
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
website = "https://repo.rtast.cn/RTAkland/runbroker"
|
||||
vcsUrl = "https://repo.rtast.cn/RTAkland/runbroker.git"
|
||||
plugins {
|
||||
create("runbroker") {
|
||||
id = "cn.rtast.runbroker"
|
||||
displayName = "RunBroker"
|
||||
description = "Run Broker quickly"
|
||||
tags = listOf("run", "auto-run")
|
||||
implementationClass = "cn.rtast.runbroker.RunBroker"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":runbroker-common"))
|
||||
implementation(kotlin("stdlib"))
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright © 2025 RTAkland
|
||||
* Date: 2025/4/28 22:10
|
||||
* Open Source Under Apache-2.0 License
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.runbroker
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
@Suppress("unused")
|
||||
class RunBroker : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
target.extensions.create("runBroker", RunBrokerExtension::class.java)
|
||||
target.tasks.register("runBroker", RunBrokerTask::class.java) { task ->
|
||||
task.group = "run-broker"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright © 2025 RTAkland
|
||||
* Date: 2025/4/28 22:11
|
||||
* Open Source Under Apache-2.0 License
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package cn.rtast.runbroker
|
||||
|
||||
import cn.rtast.runbroker.common.JavaExecPath
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
|
||||
abstract class RunBrokerExtension {
|
||||
@get:Input
|
||||
abstract val brokerBootstrapPath: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val javaExecPath: Property<JavaExecPath>
|
||||
|
||||
init {
|
||||
brokerBootstrapPath.convention("./broker.jar")
|
||||
javaExecPath.convention(JavaExecPath.DEFAULT)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright © 2025 RTAkland
|
||||
* Date: 2025/4/28 22:15
|
||||
* Open Source Under Apache-2.0 License
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package cn.rtast.runbroker
|
||||
|
||||
import cn.rtast.runbroker.common.util.readBytesFromFile
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class RunBrokerTask : DefaultTask() {
|
||||
|
||||
init {
|
||||
val shadowJarTask = project.tasks.named("shadowJar").get()
|
||||
dependsOn(shadowJarTask)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun runBroker() {
|
||||
val shadowJarTask = project.tasks.named("shadowJar").get()
|
||||
val settings = project.extensions.getByType(RunBrokerExtension::class.java)
|
||||
project.layout.projectDirectory.dir("run/broker").asFile.mkdirs()
|
||||
val brokerFile = project.layout.projectDirectory
|
||||
.dir("run/broker/broker.jar").asFile
|
||||
if (!brokerFile.exists()) {
|
||||
brokerFile.writeBytes(settings.brokerBootstrapPath.get().readBytesFromFile())
|
||||
}
|
||||
val builtJar = shadowJarTask.outputs.files.singleFile
|
||||
val previousJar = project.layout.projectDirectory
|
||||
.dir("run/broker/plugins/broker.jar").asFile
|
||||
if (previousJar.exists()) previousJar.delete()
|
||||
builtJar.copyTo(previousJar, overwrite = true)
|
||||
val executablePath = settings.javaExecPath.get().path
|
||||
project.exec {
|
||||
it.executable = if (executablePath == "-") "java" else executablePath
|
||||
it.args = listOf("-jar", brokerFile.absolutePath)
|
||||
it.workingDir = project.layout.projectDirectory.dir("run/broker").asFile
|
||||
}
|
||||
println("Broker started...")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user