Skip to content

Commit

Permalink
Provide the same java for child process in JavaExecutor as parent one
Browse files Browse the repository at this point in the history
(cherry picked from commit 0b0f2fc)
  • Loading branch information
dkrasnoff committed Oct 10, 2024
1 parent ff76969 commit 41b9c6f
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,20 +104,31 @@ class JavaExecutor {
}

class CommandLineArgument(
val classPaths: String,
val mainClass: String?,
val policy: Path,
val memoryLimit: Int,
val arguments: List<String>
val classPaths: String,
val mainClass: String?,
val policy: Path,
val memoryLimit: Int,
val arguments: List<String>,
) {
fun toList(): List<String> {
return (listOf(
"java",
"-Xmx" + memoryLimit + "M",
"-Djava.security.manager",
"-Djava.security.policy=$policy",
"-ea",
"-classpath"
) + classPaths + mainClass + arguments).filterNotNull()
}
fun toList(): List<String> {
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
}

0 comments on commit 41b9c6f

Please sign in to comment.