From 46a1109910225e185e4c465ad59d6f7d1fd01669 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 15 Feb 2018 17:59:16 +0100 Subject: [PATCH] Report warnings on usages of kotlin-stdlib-jre7/kotlin-stdlib-jre8 #KT-21347 Fixed --- .../JvmRuntimeVersionsConsistencyChecker.kt | 39 ++++++++++++++++--- .../build.log.expected | 2 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt index 53a8d4518de..7d4284f98ff 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt @@ -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, // Library jars which have some Kotlin Runtime library bundled into them - val otherLibrariesWithBundledRuntime: List + val otherLibrariesWithBundledRuntime: List, + val stdlibJre7: List, + val stdlibJre8: List ) 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(2) val coreJars = ArrayList(2) val otherLibrariesWithBundledRuntime = ArrayList(0) + val stdlibJre7 = ArrayList(0) + val stdlibJre8 = ArrayList(0) val visitedPaths = hashSetOf() @@ -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 diff --git a/compiler/testData/integration/ant/jvm/stdlibJre78AndStdlibJdk78/build.log.expected b/compiler/testData/integration/ant/jvm/stdlibJre78AndStdlibJdk78/build.log.expected index e7e2f376871..a9eb220ec49 100644 --- a/compiler/testData/integration/ant/jvm/stdlibJre78AndStdlibJdk78/build.log.expected +++ b/compiler/testData/integration/ant/jvm/stdlibJre78AndStdlibJdk78/build.log.expected @@ -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]