Skip to content

[jb] Use the default Java SDK version when there's no explicit configuration for it yet #12163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import com.intellij.openapi.project.ModuleListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.projectRoots.SdkType
import com.intellij.openapi.projectRoots.impl.JavaHomeFinder
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.registry.Registry
import com.intellij.util.application
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import java.util.concurrent.CompletableFuture


@Suppress("UnstableApiUsage", "OPT_IN_USAGE")
class GitpodProjectManager(
private val project: Project
) {
Expand All @@ -33,15 +37,30 @@ class GitpodProjectManager(
* It is a workaround for https://youtrack.jetbrains.com/issue/GTW-88
*/
private fun configureSdks() {
if (application.isHeadlessEnvironment) {
if (application.isHeadlessEnvironment || Registry.get("gitpod.autoJdk.disabled").asBoolean()) {
return
}
val pendingSdk = CompletableFuture<Sdk>()
application.invokeLaterOnWriteThread {
application.runWriteAction {
try {
ProjectJdkTable.getInstance().preconfigure()
pendingSdk.complete(ProjectJdkTable.getInstance().allJdks.firstOrNull())
val jdkTable = ProjectJdkTable.getInstance()
jdkTable.preconfigure()
val preconfiguredJdk = ProjectRootManager.getInstance(project).projectSdk
val preferredJdkHomePath = JavaHomeFinder.getFinder().findExistingJdks().firstOrNull()
pendingSdk.complete(
when {
preconfiguredJdk != null -> preconfiguredJdk
preferredJdkHomePath != null ->
jdkTable.allJdks.find { sdk -> sdk.homePath == preferredJdkHomePath }
?: SdkConfigurationUtil.createAndAddSDK(
preferredJdkHomePath,
SdkType.findByName(jdkTable.defaultSdkType.name)!!
)

else -> jdkTable.allJdks.firstOrNull()
}
)
} catch (t: Throwable) {
pendingSdk.completeExceptionally(t)
}
Expand Down Expand Up @@ -78,4 +97,4 @@ class GitpodProjectManager(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<gateway.customization.name implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
<gateway.customization.performance id="gitpodMetricsControl" order="before cpuControl" implementation="io.gitpod.jetbrains.remote.GitpodMetricControlProvider"/>
<gateway.customization.metrics id="gitpodMetricsProvider" implementation="io.gitpod.jetbrains.remote.GitpodMetricProvider" />
<registryKey key="gitpod.autoJdk.disabled" defaultValue="false" description="Disable auto-detection of JDK for the project and its modules" restartRequired="true"/>
</extensions>

</idea-plugin>