From 41b9c6fddbba2818eb03b96ec4d2762d89ff8195 Mon Sep 17 00:00:00 2001 From: Dmitrii Krasnov Date: Fri, 13 Sep 2024 21:01:11 +0200 Subject: [PATCH] Provide the same java for child process in JavaExecutor as parent one (cherry picked from commit 0b0f2fc4a32121c62d47a94b9720afa6f15ee5e7) --- .../compiler/server/executor/JavaExecutor.kt | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt b/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt index 5d0e98231..2dcfebe02 100644 --- a/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt +++ b/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt @@ -7,6 +7,7 @@ import java.io.BufferedReader import java.io.IOException import java.io.InputStreamReader import java.nio.file.Path +import java.nio.file.Paths import java.util.concurrent.Callable import java.util.concurrent.Executors import java.util.concurrent.TimeUnit @@ -103,20 +104,31 @@ class JavaExecutor { } class CommandLineArgument( - val classPaths: String, - val mainClass: String?, - val policy: Path, - val memoryLimit: Int, - val arguments: List + val classPaths: String, + val mainClass: String?, + val policy: Path, + val memoryLimit: Int, + val arguments: List, ) { - fun toList(): List { - return (listOf( - "java", - "-Xmx" + memoryLimit + "M", - "-Djava.security.manager", - "-Djava.security.policy=$policy", - "-ea", - "-classpath" - ) + classPaths + mainClass + arguments).filterNotNull() - } + fun toList(): List { + return (listOf( + getJavaPath(), + "-Xmx" + memoryLimit + "M", + "-Djava.security.manager", + "-Djava.security.policy=$policy", + "-ea", + "-classpath" + ) + classPaths + mainClass + arguments).filterNotNull() + } +} + +fun getJavaPath(): String { + // Determine the Java executable path based on the OS + val javaHome = System.getProperty("java.home") ?: return "java" + val javaBinPath = if (System.getProperty("os.name")?.lowercase()?.contains("win") == true) { + Paths.get(javaHome, "bin", "java.exe").toString() + } else { + Paths.get(javaHome, "bin", "java").toString() + } + return javaBinPath } \ No newline at end of file