From dbf4a4473d03aeb0fb7bec497ac9991fab2585e5 Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Wed, 23 Feb 2022 12:35:11 +0000 Subject: [PATCH] jb: configure SDK workaround --- .../jetbrains/remote/GitpodProjectManager.kt | 38 +++++++++++++++++++ .../src/main/resources/META-INF/plugin.xml | 1 + 2 files changed, 39 insertions(+) create mode 100644 components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt new file mode 100644 index 00000000000000..aac3c1fdb257f2 --- /dev/null +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt @@ -0,0 +1,38 @@ +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License-AGPL.txt in the project root for license information. + +package io.gitpod.jetbrains.remote + +import com.intellij.openapi.diagnostic.thisLogger +import com.intellij.openapi.project.Project +import com.intellij.openapi.projectRoots.ProjectJdkTable +import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.util.application + +class GitpodProjectManager( + private val project: Project +) { + + init { + application.invokeLaterOnWriteThread { + application.runWriteAction { + configureSdk() + } + } + } + + /** + * It is a workaround for https://youtrack.jetbrains.com/issue/GTW-88 + */ + private fun configureSdk() { + ProjectJdkTable.getInstance().preconfigure() + val sdk = ProjectJdkTable.getInstance().allJdks.firstOrNull() ?: return + val projectRootManager = ProjectRootManager.getInstance(project) + if (projectRootManager.projectSdk != null) { + return + } + projectRootManager.projectSdk = sdk + thisLogger().warn("gitpod: SDK was auto preconfigured: $sdk") + } +} \ No newline at end of file diff --git a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml index 38964a566d21ff..a2007f96130074 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml +++ b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml @@ -25,6 +25,7 @@ +