Report warnings on usages of kotlin-stdlib-jre7/kotlin-stdlib-jre8

#KT-21347 Fixed
This commit is contained in:
Alexander Udalov
2018-02-15 17:59:16 +01:00
parent 71e9ee7437
commit 46a1109910
2 changed files with 35 additions and 6 deletions
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.cli.jvm
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -47,6 +46,8 @@ object JvmRuntimeVersionsConsistencyChecker {
private const val MANIFEST_KOTLIN_RUNTIME_COMPONENT_MAIN = "manifest.impl.value.kotlin.runtime.component.main"
private const val KOTLIN_STDLIB_MODULE = "$META_INF/kotlin-stdlib.kotlin_module"
private const val KOTLIN_STDLIB_JRE_7_MODULE = "$META_INF/kotlin-stdlib-jre7.kotlin_module"
private const val KOTLIN_STDLIB_JRE_8_MODULE = "$META_INF/kotlin-stdlib-jre8.kotlin_module"
private const val KOTLIN_REFLECT_MODULE = "$META_INF/kotlin-reflection.kotlin_module"
private val RUNTIME_IMPLEMENTATION_TITLES = setOf(
@@ -90,7 +91,9 @@ object JvmRuntimeVersionsConsistencyChecker {
// Runtime jars with components "Core" only (a subset of [jars])
val coreJars: List<KotlinLibraryFile>,
// Library jars which have some Kotlin Runtime library bundled into them
val otherLibrariesWithBundledRuntime: List<VirtualFile>
val otherLibrariesWithBundledRuntime: List<VirtualFile>,
val stdlibJre7: List<KotlinLibraryFile>,
val stdlibJre8: List<KotlinLibraryFile>
)
fun checkCompilerClasspathConsistency(
@@ -152,6 +155,15 @@ object JvmRuntimeVersionsConsistencyChecker {
)
}
if (configuration.languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_2) {
for (stdlibJre7 in runtimeJarsInfo.stdlibJre7) {
messageCollector.issue(stdlibJre7.file, "kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead")
}
for (stdlibJre8 in runtimeJarsInfo.stdlibJre8) {
messageCollector.issue(stdlibJre8.file, "kotlin-stdlib-jre8 is deprecated. Please use kotlin-stdlib-jdk8 instead")
}
}
val librariesWithBundled = runtimeJarsInfo.otherLibrariesWithBundledRuntime
if (librariesWithBundled.isNotEmpty()) {
messageCollector.issue(
@@ -264,6 +276,8 @@ object JvmRuntimeVersionsConsistencyChecker {
val jars = ArrayList<KotlinLibraryFile>(2)
val coreJars = ArrayList<KotlinLibraryFile>(2)
val otherLibrariesWithBundledRuntime = ArrayList<VirtualFile>(0)
val stdlibJre7 = ArrayList<KotlinLibraryFile>(0)
val stdlibJre8 = ArrayList<KotlinLibraryFile>(0)
val visitedPaths = hashSetOf<String>()
@@ -281,17 +295,28 @@ object JvmRuntimeVersionsConsistencyChecker {
if (fileKind.isCoreComponent) {
coreJars.add(file)
}
if (fileKind.isStdlibJre7) {
stdlibJre7.add(file)
}
if (fileKind.isStdlibJre8) {
stdlibJre8.add(file)
}
}
FileKind.OldRuntime -> jars.add(KotlinLibraryFile(jarFile, ApiVersion.KOTLIN_1_0.version))
FileKind.LibraryWithBundledRuntime -> otherLibrariesWithBundledRuntime.add(jarFile)
}
}
return RuntimeJarsInfo(jars, coreJars, otherLibrariesWithBundledRuntime)
return RuntimeJarsInfo(jars, coreJars, otherLibrariesWithBundledRuntime, stdlibJre7, stdlibJre8)
}
private sealed class FileKind {
class Runtime(val version: MavenComparableVersion, val isCoreComponent: Boolean) : FileKind()
class Runtime(
val version: MavenComparableVersion,
val isStdlibJre7: Boolean,
val isStdlibJre8: Boolean,
val isCoreComponent: Boolean
) : FileKind()
// Runtime library of Kotlin 1.0
object OldRuntime : FileKind()
@@ -311,11 +336,13 @@ object JvmRuntimeVersionsConsistencyChecker {
}
val runtimeComponent = manifest?.mainAttributes?.getValue(KOTLIN_RUNTIME_COMPONENT_ATTRIBUTE)
val isStdlibJre7 = jarRoot.findFileByRelativePath(KOTLIN_STDLIB_JRE_7_MODULE) != null
val isStdlibJre8 = jarRoot.findFileByRelativePath(KOTLIN_STDLIB_JRE_8_MODULE) != null
return when (runtimeComponent) {
KOTLIN_RUNTIME_COMPONENT_MAIN ->
FileKind.Runtime(manifest.getKotlinLanguageVersion(), isCoreComponent = false)
FileKind.Runtime(manifest.getKotlinLanguageVersion(), isStdlibJre7, isStdlibJre8, isCoreComponent = false)
KOTLIN_RUNTIME_COMPONENT_CORE ->
FileKind.Runtime(manifest.getKotlinLanguageVersion(), isCoreComponent = true)
FileKind.Runtime(manifest.getKotlinLanguageVersion(), isStdlibJre7, isStdlibJre8, isCoreComponent = true)
null -> when {
jarRoot.findFileByRelativePath(KOTLIN_STDLIB_MODULE) == null &&
jarRoot.findFileByRelativePath(KOTLIN_REFLECT_MODULE) == null -> FileKind.Irrelevant
@@ -3,6 +3,8 @@ Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[TestData]/main.kt] => [[Temp]/test.jar]
[kotlinc] [CompilerLib]/kotlin-stdlib-jre7.jar: warning: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
[kotlinc] [CompilerLib]/kotlin-stdlib-jre8.jar: warning: kotlin-stdlib-jre8 is deprecated. Please use kotlin-stdlib-jdk8 instead
BUILD SUCCESSFUL
Total time: [time]