When version is not defined we need to fallback to released

There are few more such places. Better fix would be to avoid
situation, when we need to fallback. So in every project these
settings are defined. It means "Latest stable" setting is not good.

#KT-26364 Fixed
This commit is contained in:
Alexander Podkhalyuzin
2018-08-25 10:48:00 +03:00
committed by Ilya Gorbunov
parent 009980944b
commit 69a0fedd9f
3 changed files with 11 additions and 13 deletions
@@ -23,6 +23,7 @@ import com.intellij.util.text.VersionComparatorUtil
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.config.VersionView
interface KotlinVersionInfoProvider {
companion object {
@@ -53,8 +54,8 @@ fun getLibraryLanguageLevel(
rootModel: ModuleRootModel?,
targetPlatform: TargetPlatformKind<*>?
): LanguageVersion {
val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM)
.minWith(VersionComparatorUtil.COMPARATOR)
val minVersion = (getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) +
VersionView.RELEASED_VERSION.versionString).minWith(VersionComparatorUtil.COMPARATOR)
return getDefaultLanguageLevel(module, minVersion)
}
@@ -63,16 +64,16 @@ fun getDefaultLanguageLevel(
explicitVersion: String? = null
): LanguageVersion {
val libVersion = explicitVersion
?: KotlinVersionInfoProvider.EP_NAME.extensions
.mapNotNull { it.getCompilerVersion(module) }
?: (KotlinVersionInfoProvider.EP_NAME.extensions
.mapNotNull { it.getCompilerVersion(module) } + VersionView.RELEASED_VERSION.versionString)
.minWith(VersionComparatorUtil.COMPARATOR)
?: return LanguageVersion.LATEST_STABLE
?: return VersionView.RELEASED_VERSION
return when {
libVersion.startsWith("1.3") -> LanguageVersion.KOTLIN_1_3
libVersion.startsWith("1.2") -> LanguageVersion.KOTLIN_1_2
libVersion.startsWith("1.1") -> LanguageVersion.KOTLIN_1_1
libVersion.startsWith("1.0") -> LanguageVersion.KOTLIN_1_0
else -> LanguageVersion.LATEST_STABLE
else -> VersionView.RELEASED_VERSION
}
}
@@ -118,7 +118,7 @@ fun Project.getLanguageVersionSettings(
val languageVersion =
LanguageVersion.fromVersionString(arguments.languageVersion)
?: contextModule?.getAndCacheLanguageLevelByDependencies()
?: LanguageVersion.LATEST_STABLE
?: VersionView.RELEASED_VERSION
val apiVersion = ApiVersion.createByLanguageVersion(LanguageVersion.fromVersionString(arguments.apiVersion) ?: languageVersion)
val compilerSettings = KotlinCompilerSettings.getInstance(this).settings
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.build.GeneratedFile
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.incremental.CacheVersion
import org.jetbrains.kotlin.incremental.ChangesCollector
import org.jetbrains.kotlin.incremental.ExpectActualTrackerImpl
@@ -313,7 +310,7 @@ abstract class KotlinModuleBuildTarget<BuildMetaInfoType : BuildMetaInfo>(
val lastBuildLangVersion = LanguageVersion.fromVersionString(lastBuildMetaInfo.languageVersionString)
val lastBuildApiVersion = ApiVersion.parse(lastBuildMetaInfo.apiVersionString)
val currentLangVersion =
args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE
args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: VersionView.RELEASED_VERSION
val currentApiVersion =
args.apiVersion?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(currentLangVersion)
@@ -339,4 +336,4 @@ abstract class KotlinModuleBuildTarget<BuildMetaInfoType : BuildMetaInfo>(
}
}
}
}
}