From 0fc43b1f570fa3a6a29141ebd3d222def8497d50 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 28 May 2020 21:25:36 +0300 Subject: [PATCH] Wizard: add possibility to change Kotlin version for generated projects via property #KT-39247 fixed --- .../service/IdeaKotlinVersionProviderService.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/service/IdeaKotlinVersionProviderService.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/service/IdeaKotlinVersionProviderService.kt index 7db436e8531..fce8f96f3b9 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/service/IdeaKotlinVersionProviderService.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/service/IdeaKotlinVersionProviderService.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.service +import com.intellij.openapi.application.ApplicationManager import com.intellij.util.text.VersionComparatorUtil import org.jetbrains.annotations.NonNls import org.jetbrains.kotlin.config.KotlinCompilerVersion @@ -25,14 +26,26 @@ import java.util.stream.Collectors class IdeaKotlinVersionProviderService : KotlinVersionProviderService, IdeaWizardService { override fun getKotlinVersion(): Version = - getKotlinVersionFromCompiler() + getPatchedKotlinVersion() + ?: getKotlinVersionFromCompiler() ?: VersionsDownloader.downloadLatestEapOrStableKotlinVersion() ?: Versions.KOTLIN + private fun getPatchedKotlinVersion() = + if (ApplicationManager.getApplication().isInternal) { + System.getProperty(KOTLIN_COMPILER_VERSION_TAG)?.let { Version.fromString(it) } + } else { + null + } + private fun getKotlinVersionFromCompiler() = KotlinCompilerVersion.getVersion() ?.takeUnless { it.contains(SNAPSHOT_TAG, ignoreCase = true) } ?.let { Version.fromString(it) } + + companion object { + private const val KOTLIN_COMPILER_VERSION_TAG = "kotlin.compiler.version" + } } @NonNls