diff --git a/.gitignore b/.gitignore index 25ccd9afd15..d18141fa4df 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ build *.java.hsw *.~ava /bundles -/bisq-* +/bisq-*.bat /lib /xchange desktop.ini diff --git a/apitest/build.gradle b/apitest/build.gradle index 0b8a5da6b5d..94388acff2b 100644 --- a/apitest/build.gradle +++ b/apitest/build.gradle @@ -1,5 +1,6 @@ plugins { id 'bisq.application' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' } application { diff --git a/bisq-apitest b/bisq-apitest new file mode 100755 index 00000000000..953709b6482 --- /dev/null +++ b/bisq-apitest @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :apitest:startBisqApp +else + ./gradlew :apitest:startBisqApp --args \"\""$args"\"\" +fi diff --git a/bisq-cli b/bisq-cli new file mode 100755 index 00000000000..fba1c32d413 --- /dev/null +++ b/bisq-cli @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :cli:startBisqApp +else + ./gradlew :cli:startBisqApp --args \"\""$args"\"\" +fi diff --git a/bisq-daemon b/bisq-daemon new file mode 100755 index 00000000000..d025a5d706d --- /dev/null +++ b/bisq-daemon @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :daemon:startBisqApp +else + ./gradlew :daemon:startBisqApp --args \"\""$args"\"\" +fi diff --git a/bisq-desktop b/bisq-desktop new file mode 100755 index 00000000000..e2d1856088d --- /dev/null +++ b/bisq-desktop @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :desktop:startBisqApp +else + ./gradlew :desktop:startBisqApp --args \"\""$args"\"\" +fi diff --git a/bisq-seednode b/bisq-seednode new file mode 100755 index 00000000000..ffedf8a8f14 --- /dev/null +++ b/bisq-seednode @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :seednode:startBisqApp +else + ./gradlew :seednode:startBisqApp --args \"\""$args"\"\" +fi diff --git a/bisq-statsnode b/bisq-statsnode new file mode 100755 index 00000000000..4c88794f59a --- /dev/null +++ b/bisq-statsnode @@ -0,0 +1,16 @@ +#!/bin/bash +project_dir=$(dirname "${BASH_SOURCE[0]}") +echo $project_dir +cd "$project_dir" || exit + +args= +for i in "$@" +do + args+="$i " +done + +if [ ${#@} -eq 0 ]; then + ./gradlew :statsnode:startBisqApp +else + ./gradlew :statsnode:startBisqApp --args \"\""$args"\"\" +fi 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/commons/src/main/groovy/bisq.application.gradle b/build-logic/commons/src/main/groovy/bisq.application.gradle index 9658c3f2ae7..aa0fd6913c6 100644 --- a/build-logic/commons/src/main/groovy/bisq.application.gradle +++ b/build-logic/commons/src/main/groovy/bisq.application.gradle @@ -7,41 +7,3 @@ build.dependsOn installDist installDist.destinationDir = file('build/app') distZip.enabled = false distTar.enabled = false - -// the 'installDist' and 'startScripts' blocks below configure bisq executables to put -// generated shell scripts in the root project directory, such that users can easily -// discover and invoke e.g. ./bisq-desktop, ./bisq-seednode, etc. -// See https://stackoverflow.com/q/46327736 for details. - -installDist { - doLast { - // copy generated shell scripts, e.g. `bisq-desktop` directly to the project - // root directory for discoverability and ease of use - - copy { - from "$destinationDir/bin" - into rootProject.projectDir - } - // copy libs required for generated shell script classpaths to 'lib' dir under - // the project root directory - copy { - from "$destinationDir/lib" - into "${rootProject.projectDir}/lib" - } - - // edit generated shell scripts such that they expect to be executed in the - // project root dir as opposed to a 'bin' subdirectory - def windowsScriptFile = file("${rootProject.projectDir}/bisq-${applicationName}.bat") - windowsScriptFile.text = windowsScriptFile.text.replace( - 'set APP_HOME=%DIRNAME%..', 'set APP_HOME=%DIRNAME%') - - def unixScriptFile = file("${rootProject.projectDir}/bisq-$applicationName") - unixScriptFile.text = unixScriptFile.text.replace( - 'APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit', 'APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit') - } -} - -startScripts { - // rename scripts from, e.g. `desktop` to `bisq-desktop` - applicationName = "bisq-$applicationName" -} 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' diff --git a/build.gradle b/build.gradle index e658103fdf6..d142e1256ef 100644 --- a/build.gradle +++ b/build.gradle @@ -6,16 +6,6 @@ buildscript { } } -configure(rootProject) { - - // remove the 'bisq-*' scripts and 'lib' dir generated by the 'installDist' task - task clean { - doLast { - delete fileTree(dir: rootProject.projectDir, include: 'bisq-*'), 'lib' - } - } -} - if (hasProperty('buildScan')) { buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service' diff --git a/cli/build.gradle b/cli/build.gradle index 8d358eb4908..8eb8e6aca3e 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -1,5 +1,6 @@ plugins { id 'bisq.application' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' } distTar.enabled = true diff --git a/daemon/build.gradle b/daemon/build.gradle index 7606d288ff3..ea7d1f350d4 100644 --- a/daemon/build.gradle +++ b/daemon/build.gradle @@ -1,5 +1,6 @@ plugins { id 'bisq.application' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' } distTar.enabled = true diff --git a/desktop/build.gradle b/desktop/build.gradle index 6445139527f..d86198d6783 100644 --- a/desktop/build.gradle +++ b/desktop/build.gradle @@ -1,6 +1,7 @@ plugins { id 'bisq.application' id 'bisq.javafx' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' id 'bisq.gradle.packaging.PackagingPlugin' } diff --git a/seednode/build.gradle b/seednode/build.gradle index 8d8622b7884..02bcbd1eaa5 100644 --- a/seednode/build.gradle +++ b/seednode/build.gradle @@ -1,5 +1,6 @@ plugins { id 'bisq.application' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' } mainClassName = 'bisq.seednode.SeedNodeMain' diff --git a/statsnode/build.gradle b/statsnode/build.gradle index b593c42b615..c5936a773ba 100644 --- a/statsnode/build.gradle +++ b/statsnode/build.gradle @@ -1,5 +1,6 @@ plugins { id 'bisq.application' + id 'bisq.gradle.app_start_plugin.AppStartPlugin' } mainClassName = 'bisq.statistics.StatisticsMain'