ExistingJdkConfigurationActivity - use serviceAsync

GitOrigin-RevId: c369790429f73bb92e520f530fe59592a9bee1c5
This commit is contained in:
Vladimir Krivosheev
2024-03-13 20:02:57 +01:00
committed by intellij-monorepo-bot
parent 6796d42dc0
commit 45bef58974

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.projectRoots.impl
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.components.serviceAsync
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.JdkFinder
@@ -19,16 +20,18 @@ import com.intellij.openapi.util.registry.Registry
* - Automatically registers JDKs on the computer in the [ProjectJdkTable]
* - Uses the first JDK found as project SDK if none was configured
*/
class ExistingJdkConfigurationActivity : ProjectActivity {
private class ExistingJdkConfigurationActivity : ProjectActivity {
override suspend fun execute(project: Project) {
if (!Registry.`is`("jdk.configure.existing", false)) return
if (!Registry.`is`("jdk.configure.existing", false)) {
return
}
val javaSdk = JavaSdk.getInstance()
val registeredJdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk)
val registeredJdks = serviceAsync<ProjectJdkTable>().getSdksOfType(javaSdk)
val jdkPathsToAdd = ArrayList<String>()
// Collect JDKs to register
JdkFinder.getInstance().suggestHomePaths().forEach { homePath: String ->
serviceAsync<JdkFinder>().suggestHomePaths().forEach { homePath: String ->
if (javaSdk.isValidSdkHome(homePath) && registeredJdks.none {
FileUtil.toCanonicalPath(it.homePath) == FileUtil.toCanonicalPath(homePath)
}) {
@@ -36,7 +39,7 @@ class ExistingJdkConfigurationActivity : ProjectActivity {
}
}
val rootManager = ProjectRootManager.getInstance(project)
val rootManager = project.serviceAsync<ProjectRootManager>()
val addedJdks = registeredJdks.toMutableList()
val priorityPaths = JavaHomeFinder.getFinder().findInJavaHome()