From 502e45168d4f31c426582af86fa8319db5fc9d8d Mon Sep 17 00:00:00 2001 From: BloodWorkXGaming Date: Wed, 13 Apr 2022 16:23:45 +0200 Subject: [PATCH] hopefully fixed which not working on linux --- build.gradle | 2 +- .../serverstarter/LoaderManager.kt | 42 ++++++++++--------- .../serverstarter/ServerStarter.kt | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 3783c6b..ce54b6e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'atm.bloodworkxgaming' -version = '2.3.0' +version = '2.3.1' sourceCompatibility = 1.8 diff --git a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/LoaderManager.kt b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/LoaderManager.kt index 23ea5d5..0e0b037 100644 --- a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/LoaderManager.kt +++ b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/LoaderManager.kt @@ -310,7 +310,7 @@ class LoaderManager(private val configFile: ConfigFile, private val internetMana * 2. correct jvm version on the $PATH * 3. 'java' */ - private fun getEffectiveJavaPath() = when { + private fun getEffectiveJavaPath(): String = when { configFile.launch.forcedJavaPath.isNotBlank() -> configFile.launch.processedForcedJavaPath configFile.launch.supportedJavaVersions.isNotEmpty() -> { // Find the best suitable java version @@ -319,28 +319,32 @@ class LoaderManager(private val configFile: ConfigFile, private val internetMana val command = if (OSUtil.isWindows) { arrayOf("where", "java") } else { - arrayOf("which -a java") + arrayOf("which", "-a", "java") } + try { + val path = Runtime.getRuntime().exec(command ) + .inputStream + .bufferedReader() + .readLines() + .firstOrNull { path -> + val text = Runtime.getRuntime().exec(arrayOf(path, "-version")) + .errorStream + .bufferedReader() + .readText() + configFile.launch.supportedJavaVersions + .any { text.contains(Regex("\"(1\\.)?${it}")) } + } - val path = Runtime.getRuntime().exec(command ) - .inputStream - .bufferedReader() - .readLines() - .firstOrNull { path -> - val text = Runtime.getRuntime().exec(arrayOf(path, "-version")) - .errorStream - .bufferedReader() - .readText() - configFile.launch.supportedJavaVersions - .any { text.contains(Regex("\"(1\\.)?${it}")) } + if (path == null) { + LOGGER.warn("Couldn't find any JVM installation matching the supported versions, falling back to 'java', but this might fail.") + "java" + } else { + LOGGER.info("Found suitable JVM at path $path.") + path.replace("\\", "/") } - - if (path == null) { - LOGGER.warn("Couldn't find any JVM installation matching the supported versions, falling back to 'java', but this might fail.") + } catch (e: Exception) { + LOGGER.error("Couldn't find jvm, falling back to 'java'", e) "java" - } else { - LOGGER.info("Found suitable JVM at path $path.") - path.replace("\\", "/") } } else -> "java" diff --git a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/ServerStarter.kt b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/ServerStarter.kt index 9c575cf..c8d2fdf 100644 --- a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/ServerStarter.kt +++ b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/ServerStarter.kt @@ -25,7 +25,7 @@ class ServerStarter(args: Array) { private val rep: Representer = Representer() private val options: DumperOptions = DumperOptions() private const val CURRENT_SPEC = 2 - private const val VERSION = "2.3.0" + private const val VERSION = "2.3.1" val LOGGER = PrimitiveLogger(File("serverstarter.log")) var lockFile: LockFile