From 571815bbd506a026a58c524b3437e09e8f68c8fc Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 10 Sep 2023 20:24:52 +0200 Subject: [PATCH] Implement AppStartPlugin --- build-logic/app-start-plugin/build.gradle | 17 +++++++ .../gradle/app_start_plugin/AppStartPlugin.kt | 49 +++++++++++++++++++ build-logic/settings.gradle | 1 + 3 files changed, 67 insertions(+) create mode 100644 build-logic/app-start-plugin/build.gradle create mode 100644 build-logic/app-start-plugin/src/main/kotlin/bisq/gradle/app_start_plugin/AppStartPlugin.kt diff --git a/build-logic/app-start-plugin/build.gradle b/build-logic/app-start-plugin/build.gradle new file mode 100644 index 00000000000..15b43f6ec0b --- /dev/null +++ b/build-logic/app-start-plugin/build.gradle @@ -0,0 +1,17 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' version '1.7.10' + id 'org.gradle.kotlin.kotlin-dsl' version '2.4.1' +} + +repositories { + mavenCentral() +} + +gradlePlugin { + plugins { + simplePlugin { + id = 'bisq.gradle.app_start_plugin.AppStartPlugin' + implementationClass = 'bisq.gradle.app_start_plugin.AppStartPlugin' + } + } +} diff --git a/build-logic/app-start-plugin/src/main/kotlin/bisq/gradle/app_start_plugin/AppStartPlugin.kt b/build-logic/app-start-plugin/src/main/kotlin/bisq/gradle/app_start_plugin/AppStartPlugin.kt new file mode 100644 index 00000000000..16e616a427d --- /dev/null +++ b/build-logic/app-start-plugin/src/main/kotlin/bisq/gradle/app_start_plugin/AppStartPlugin.kt @@ -0,0 +1,49 @@ +package bisq.gradle.app_start_plugin + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaApplication +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.JavaExec +import org.gradle.api.tasks.Sync +import org.gradle.api.tasks.TaskProvider +import org.gradle.jvm.toolchain.* +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.register +import java.io.File +import javax.inject.Inject + +class AppStartPlugin @Inject constructor(private val javaToolchainService: JavaToolchainService) : Plugin { + + override fun apply(project: Project) { + val installDistTask: TaskProvider = project.tasks.named("installDist", Sync::class.java) + + val javaApplicationExtension = project.extensions.findByType() + checkNotNull(javaApplicationExtension) { "Can't find JavaApplication extension." } + + project.tasks.register("startBisqApp") { + dependsOn(installDistTask) + javaLauncher.set(getJavaLauncher(project)) + + classpath = installDistTask.map { + val appLibsDir = File(it.destinationDir, "lib") + val allFiles = appLibsDir.listFiles() + project.files(allFiles) + }.get() + + jvmArgs.addAll(javaApplicationExtension.applicationDefaultJvmArgs) + + workingDir = project.projectDir.parentFile + mainClass.set(javaApplicationExtension.mainClass) + } + } + + private fun getJavaLauncher(project: Project): Provider { + val javaExtension = project.extensions.findByType() + checkNotNull(javaExtension) { "Can't find JavaPluginExtension extension." } + + val toolchain = javaExtension.toolchain + return javaToolchainService.launcherFor(toolchain) + } +} diff --git a/build-logic/settings.gradle b/build-logic/settings.gradle index 2b47bf62ab9..dcdcd20fe24 100644 --- a/build-logic/settings.gradle +++ b/build-logic/settings.gradle @@ -6,6 +6,7 @@ dependencyResolutionManagement { } } +include 'app-start-plugin' include 'commons' include 'gradle-tasks' include 'packaging'