Simplify adding Kotlin sdk by inlining internals of ProjectSdksModel
Because of using cloning sdks inside ProjectSdksModel tests fail with sdk leaked errors.
This commit is contained in:
@@ -9,7 +9,6 @@ import com.intellij.openapi.application.ApplicationManager
|
|||||||
import com.intellij.openapi.projectRoots.*
|
import com.intellij.openapi.projectRoots.*
|
||||||
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl
|
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl
|
||||||
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
|
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
|
||||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel
|
|
||||||
import com.intellij.util.Consumer
|
import com.intellij.util.Consumer
|
||||||
import org.jdom.Element
|
import org.jdom.Element
|
||||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||||
@@ -28,13 +27,19 @@ class KotlinSdkType : SdkType("KotlinSDK") {
|
|||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun setUpIfNeeded(checkIfNeeded: () -> Boolean = { true }) {
|
fun setUpIfNeeded(checkIfNeeded: () -> Boolean = { true }) {
|
||||||
with(ProjectSdksModel()) {
|
val projectSdks: Array<Sdk> = ProjectJdkTable.getInstance().allJdks
|
||||||
reset(null)
|
if (projectSdks.any { it.sdkType is KotlinSdkType }) return
|
||||||
if (sdks.any { it.sdkType is KotlinSdkType }) return
|
if (!checkIfNeeded()) return // do not create Kotlin SDK
|
||||||
if (!checkIfNeeded()) return //do not create Kotlin SDK
|
|
||||||
addSdk(INSTANCE, defaultHomePath, null)
|
val newSdkName = SdkConfigurationUtil.createUniqueSdkName(INSTANCE, defaultHomePath, projectSdks.toList())
|
||||||
ApplicationManager.getApplication().invokeAndWait {
|
val newJdk = ProjectJdkImpl(newSdkName, INSTANCE)
|
||||||
runWriteAction { apply(null, true) }
|
newJdk.homePath = defaultHomePath
|
||||||
|
INSTANCE.setupSdkPaths(newJdk)
|
||||||
|
|
||||||
|
ApplicationManager.getApplication().invokeAndWait {
|
||||||
|
runWriteAction {
|
||||||
|
if (ProjectJdkTable.getInstance().allJdks.any { it.sdkType is KotlinSdkType }) return@runWriteAction
|
||||||
|
ProjectJdkTable.getInstance().addJdk(newJdk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user