Skip to content

Commit

Permalink
Merge pull request #6862 from alvasw/Enforce_same_JDK_in_all_start_sc…
Browse files Browse the repository at this point in the history
…ripts

Enforce same JDK in all start scripts
  • Loading branch information
alejandrogarcia83 authored Sep 11, 2023
2 parents 8a5631c + cc36852 commit bbbb567
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build
*.java.hsw
*.~ava
/bundles
/bisq-*
/bisq-*.bat
/lib
/xchange
desktop.ini
Expand Down
1 change: 1 addition & 0 deletions apitest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bisq.application'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
}

application {
Expand Down
16 changes: 16 additions & 0 deletions bisq-apitest
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bisq-cli
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bisq-daemon
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bisq-desktop
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bisq-seednode
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bisq-statsnode
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions build-logic/app-start-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Project> {

override fun apply(project: Project) {
val installDistTask: TaskProvider<Sync> = project.tasks.named("installDist", Sync::class.java)

val javaApplicationExtension = project.extensions.findByType<JavaApplication>()
checkNotNull(javaApplicationExtension) { "Can't find JavaApplication extension." }

project.tasks.register<JavaExec>("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<JavaLauncher> {
val javaExtension = project.extensions.findByType<JavaPluginExtension>()
checkNotNull(javaExtension) { "Can't find JavaPluginExtension extension." }

val toolchain = javaExtension.toolchain
return javaToolchainService.launcherFor(toolchain)
}
}
38 changes: 0 additions & 38 deletions build-logic/commons/src/main/groovy/bisq.application.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencyResolutionManagement {
}
}

include 'app-start-plugin'
include 'commons'
include 'gradle-tasks'
include 'packaging'
Expand Down
10 changes: 0 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bisq.application'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
}

distTar.enabled = true
Expand Down
1 change: 1 addition & 0 deletions daemon/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bisq.application'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
}

distTar.enabled = true
Expand Down
1 change: 1 addition & 0 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'bisq.application'
id 'bisq.javafx'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
id 'bisq.gradle.packaging.PackagingPlugin'
}

Expand Down
1 change: 1 addition & 0 deletions seednode/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bisq.application'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
}

mainClassName = 'bisq.seednode.SeedNodeMain'
Expand Down
1 change: 1 addition & 0 deletions statsnode/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bisq.application'
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
}

mainClassName = 'bisq.statistics.StatisticsMain'
Expand Down

0 comments on commit bbbb567

Please sign in to comment.