Skip to content

Commit

Permalink
hopefully fixed which not working on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodWorkXGaming committed Apr 13, 2022
1 parent a287383 commit 502e451
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'atm.bloodworkxgaming'
version = '2.3.0'
version = '2.3.1'

sourceCompatibility = 1.8

Expand Down
42 changes: 23 additions & 19 deletions src/main/kotlin/atm/bloodworkxgaming/serverstarter/LoaderManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ServerStarter(args: Array<String>) {
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
Expand Down

0 comments on commit 502e451

Please sign in to comment.