mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test [terminal console]: fallback logic for locating Java executable in tests
GitOrigin-RevId: 9845def09f66d410a389166013ae1a429579d33a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
103b72db2d
commit
5d6761c267
+23
-13
@@ -2,29 +2,40 @@
|
||||
package com.intellij.terminal
|
||||
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.platform.eel.EelExecApiHelpers
|
||||
import com.intellij.platform.eel.pathSeparator
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.platform.eel.*
|
||||
import com.intellij.platform.eel.provider.LocalEelDescriptor
|
||||
import com.intellij.platform.eel.provider.localEel
|
||||
import com.intellij.platform.eel.spawnProcess
|
||||
import com.intellij.platform.eel.provider.toEelApi
|
||||
import com.intellij.util.execution.ParametersListUtil
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.div
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.jvm.optionals.getOrElse
|
||||
|
||||
internal class TestJavaMainClassCommand(
|
||||
private val mainClass: Class<*>,
|
||||
dependencies: List<Class<*>>,
|
||||
private val args: List<String>,
|
||||
) {
|
||||
private val javaExe: Path = Path(ProcessHandle.current().info().command().get())
|
||||
private val classPath: String = getClassPath(mainClass, dependencies)
|
||||
private val javaExe: Path = Path(ProcessHandle.current().info().command().getOrElse {
|
||||
// In rare cases on macOS, `ProcessHandle.current().info().command()` may be empty for unknown reasons.
|
||||
val failover = Path(System.getProperty("java.home")) / "bin" / (if (eelDescriptor.osFamily.isWindows) "java.exe" else "java")
|
||||
logger<TestJavaMainClassCommand>().warn("Cannot find java executable, using failover: $failover")
|
||||
failover.pathString
|
||||
})
|
||||
private val classpathEntries: List<Path> = getClasspathEntries(mainClass, dependencies)
|
||||
|
||||
private val eelDescriptor: EelDescriptor
|
||||
get() = LocalEelDescriptor
|
||||
|
||||
val commandLine: String
|
||||
get() = ParametersListUtil.join(listOf(javaExe.toString(), mainClass.canonicalName) + args)
|
||||
|
||||
fun createLocalProcessBuilder(): EelExecApiHelpers.SpawnProcess {
|
||||
return localEel.exec.spawnProcess(javaExe.toString())
|
||||
.env(mapOf("CLASSPATH" to classPath))
|
||||
suspend fun createLocalProcessBuilder(): EelExecApiHelpers.SpawnProcess {
|
||||
val classpath = classpathEntries.joinToString(eelDescriptor.osFamily.pathSeparator) { it.pathString }
|
||||
return eelDescriptor.toEelApi().exec.spawnProcess(javaExe.pathString)
|
||||
.env(mapOf("CLASSPATH" to classpath))
|
||||
.args(listOf(mainClass.canonicalName) + args)
|
||||
}
|
||||
|
||||
@@ -33,11 +44,10 @@ internal class TestJavaMainClassCommand(
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private fun getClassPath(mainClass: Class<*>, dependencies: List<Class<*>>): String {
|
||||
val classPathRoots = (listOf(mainClass, KotlinVersion::class.java /* kotlin-stdlib.jar */) + dependencies).map {
|
||||
checkNotNull(PathManager.getJarPathForClass(it)) { "Cannot find jar/directory for $it" }
|
||||
private fun getClasspathEntries(mainClass: Class<*>, dependencies: List<Class<*>>): List<Path> {
|
||||
return (listOf(mainClass, KotlinVersion::class.java /* kotlin-stdlib.jar */) + dependencies).map {
|
||||
checkNotNull(PathManager.getJarForClass(it)) { "Cannot find jar/directory for $it" }
|
||||
}.distinct()
|
||||
return classPathRoots.joinToString(LocalEelDescriptor.osFamily.pathSeparator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user