Wizard: correctly check for Kotlin compiler version is snapshot

This commit is contained in:
Ilya Kirillov
2020-03-07 19:13:58 +03:00
parent 51f71a4e33
commit 00d8045adc
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.tools.projectWizard.wizard.service package org.jetbrains.kotlin.tools.projectWizard.wizard.service
import com.intellij.util.text.VersionComparatorUtil
import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
@@ -22,11 +23,21 @@ import java.util.stream.Collectors
class IdeaKotlinVersionProviderService : KotlinVersionProviderService, IdeaWizardService { class IdeaKotlinVersionProviderService : KotlinVersionProviderService, IdeaWizardService {
override fun getKotlinVersion(): Version = override fun getKotlinVersion(): Version =
KotlinCompilerVersion.getVersion()?.let { Version.fromString(it) } getKotlinVersionFromCompiler()
?: VersionsDownloader.downloadLatestEapOrStableKotlinVersion() ?: VersionsDownloader.downloadLatestEapOrStableKotlinVersion()
?: KotlinVersionProviderServiceImpl.DEFAULT ?: KotlinVersionProviderServiceImpl.DEFAULT
private fun getKotlinVersionFromCompiler() =
KotlinCompilerVersion.getVersion()
?.takeUnless { it.contains(SNAPSHOT_TAG, ignoreCase = true) }
?.let { Version.fromString(it) }
companion object {
private const val SNAPSHOT_TAG = "snapshot"
}
} }
private object VersionsDownloader { private object VersionsDownloader {
fun downloadLatestEapOrStableKotlinVersion(): Version? = runWithProgressBar("Downloading Kotlin version") { fun downloadLatestEapOrStableKotlinVersion(): Version? = runWithProgressBar("Downloading Kotlin version") {
val latestEap = EapVersionDownloader.getLatestEapVersion() val latestEap = EapVersionDownloader.getLatestEapVersion()
@@ -34,7 +45,7 @@ private object VersionsDownloader {
when { when {
latestEap == null -> latestStable latestEap == null -> latestStable
latestStable == null -> latestEap latestStable == null -> latestEap
latestEap > latestStable -> latestEap VersionComparatorUtil.compare(latestEap.text, latestStable.text) > 0 -> latestEap
else -> latestStable else -> latestStable
} }
} }