Skip to content

Commit 173dd34

Browse files
committed
Use Java SDK defined on JAVA_HOME by default on JetBrains IDEs
1 parent 135bc0f commit 173dd34

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt

+19-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import com.intellij.openapi.project.ModuleListener
1212
import com.intellij.openapi.project.Project
1313
import com.intellij.openapi.projectRoots.ProjectJdkTable
1414
import com.intellij.openapi.projectRoots.Sdk
15+
import com.intellij.openapi.projectRoots.SdkType
16+
import com.intellij.openapi.projectRoots.impl.JavaHomeFinder
17+
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
1518
import com.intellij.openapi.roots.ModuleRootModificationUtil
1619
import com.intellij.openapi.roots.ProjectRootManager
20+
import com.intellij.openapi.util.registry.Registry
1721
import com.intellij.util.application
1822
import kotlinx.coroutines.GlobalScope
1923
import kotlinx.coroutines.future.await
2024
import kotlinx.coroutines.launch
2125
import java.util.concurrent.CompletableFuture
2226

23-
27+
@Suppress("UnstableApiUsage", "OPT_IN_USAGE")
2428
class GitpodProjectManager(
2529
private val project: Project
2630
) {
@@ -33,15 +37,25 @@ class GitpodProjectManager(
3337
* It is a workaround for https://youtrack.jetbrains.com/issue/GTW-88
3438
*/
3539
private fun configureSdks() {
36-
if (application.isHeadlessEnvironment) {
40+
if (application.isHeadlessEnvironment || Registry.get("gitpod.autoJdk.disabled").asBoolean()) {
3741
return
3842
}
3943
val pendingSdk = CompletableFuture<Sdk>()
4044
application.invokeLaterOnWriteThread {
4145
application.runWriteAction {
4246
try {
43-
ProjectJdkTable.getInstance().preconfigure()
44-
pendingSdk.complete(ProjectJdkTable.getInstance().allJdks.firstOrNull())
47+
val jdkTable = ProjectJdkTable.getInstance()
48+
jdkTable.preconfigure()
49+
val preferredJdkHomePath = JavaHomeFinder.getFinder().findExistingJdks().firstOrNull()
50+
if (preferredJdkHomePath != null) {
51+
val sdk = SdkConfigurationUtil.createAndAddSDK(
52+
preferredJdkHomePath,
53+
SdkType.findByName(jdkTable.defaultSdkType.name)!!
54+
)
55+
pendingSdk.complete(sdk)
56+
} else {
57+
pendingSdk.complete(jdkTable.allJdks.firstOrNull())
58+
}
4559
} catch (t: Throwable) {
4660
pendingSdk.completeExceptionally(t)
4761
}
@@ -78,4 +92,4 @@ class GitpodProjectManager(
7892
}
7993
}
8094
}
81-
}
95+
}

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<gateway.customization.name implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
3434
<gateway.customization.performance id="gitpodMetricsControl" order="before cpuControl" implementation="io.gitpod.jetbrains.remote.GitpodMetricControlProvider"/>
3535
<gateway.customization.metrics id="gitpodMetricsProvider" implementation="io.gitpod.jetbrains.remote.GitpodMetricProvider" />
36+
<registryKey key="gitpod.autoJdk.disabled" defaultValue="false" description="Disable auto-detection of JDK for the project and its modules" restartRequired="true"/>
3637
</extensions>
3738

3839
</idea-plugin>

0 commit comments

Comments
 (0)