mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
IDEA-346655 Java target introspection should not be limited to JAVA_HOME
GitOrigin-RevId: 24646b072d1f01e285a6cbf9b2b695e568346a1a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7c8ca97c79
commit
30d7790de0
@@ -17,7 +17,10 @@ import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.util.lang.JavaVersion
|
||||
import com.intellij.util.text.nullize
|
||||
import org.jetbrains.annotations.Nls
|
||||
import java.io.StringReader
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.CompletionStage
|
||||
import java.util.function.Supplier
|
||||
import javax.swing.Icon
|
||||
|
||||
@@ -59,6 +62,8 @@ class JavaLanguageRuntimeType : LanguageRuntimeType<JavaLanguageRuntimeConfigura
|
||||
override fun introspect(subject: Introspectable): CompletableFuture<JavaLanguageRuntimeConfiguration> {
|
||||
val javaHomePromise = if (config.homePath.isBlank()) {
|
||||
subject.promiseEnvironmentVariable("JAVA_HOME")
|
||||
.thenCompose { it.completeOrElse { subject.promiseExecuteScript(listOf("java", "-XshowSettings:properties", "-version"))
|
||||
.handle { output, _ -> tryParseJavaHome(output.stdout) }}}
|
||||
.thenApply { acceptJavaHome(it) }
|
||||
}
|
||||
else {
|
||||
@@ -95,6 +100,14 @@ class JavaLanguageRuntimeType : LanguageRuntimeType<JavaLanguageRuntimeConfigura
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> T?.completeOrElse(orElse: () -> CompletionStage<T>): CompletionStage<T> = this?.let { CompletableFuture.completedFuture(this) } ?: orElse()
|
||||
|
||||
private fun tryParseJavaHome(output: String): String? {
|
||||
val properties = Properties()
|
||||
properties.load(StringReader(output))
|
||||
return properties.getProperty("java.home")
|
||||
}
|
||||
|
||||
private fun tryParseJavaVersionFromOutput(output: String?): JavaVersion? =
|
||||
output?.lines()?.firstNotNullOfOrNull {
|
||||
kotlin.runCatching { JavaVersion.parse(it) }.getOrNull()
|
||||
|
||||
Reference in New Issue
Block a user