From af7de9a0c541ddc0a064e863ec08564ee57de695 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 15 Feb 2017 17:04:24 +0100 Subject: [PATCH] Warn when running the compiler under Java 6 or 7 (cherry picked from commit 5537800) (cherry picked from commit 5614874) --- .../cli/common/arguments/CommonCompilerArguments.java | 3 +++ .../org/jetbrains/kotlin/cli/common/CLICompiler.java | 11 +++++++++++ compiler/testData/cli/js/jsExtraHelp.out | 3 ++- compiler/testData/cli/js/version.out | 1 + compiler/testData/cli/jvm/extraHelp.out | 1 + compiler/testData/cli/jvm/unknownExtraFlags.out | 1 + compiler/testData/cli/jvm/version.out | 1 + .../kotlin/integration/KotlinIntegrationTestBase.java | 3 +++ .../org/jetbrains/kotlin/cli/AbstractCliTest.java | 3 ++- .../kotlin/integration/CompilerSmokeTestBase.java | 1 + .../AbstractMultiPlatformIntegrationTest.kt | 6 +++--- 11 files changed, 29 insertions(+), 5 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.java index c1d1f5d1bb9..21a07c9204e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.java @@ -79,6 +79,9 @@ public abstract class CommonCompilerArguments implements Serializable { @Argument(value = "Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects") public boolean noCheckImpl; + @Argument(value = "Xskip-java-check", description = "Do not warn when running the compiler under Java 6 or 7") + public boolean noJavaVersionWarning; + @Argument(value = "Xcoroutines=warn") public boolean coroutinesWarn; diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java index 62a18bdeeaf..fc3dc61403f 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java @@ -155,6 +155,7 @@ public abstract class CLICompiler { } reportUnknownExtraFlags(messageCollector, arguments); + reportUnsupportedJavaVersion(messageCollector, arguments); GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector); @@ -350,6 +351,16 @@ public abstract class CLICompiler { } } + private void reportUnsupportedJavaVersion(MessageCollector collector, A arguments) { + if (!SystemInfo.isJavaVersionAtLeast("1.8") && !arguments.noJavaVersionWarning) { + collector.report( + CompilerMessageSeverity.STRONG_WARNING, + "Running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update.", + CompilerMessageLocation.NO_LOCATION + ); + } + } + @NotNull protected abstract ExitCode doExecute( @NotNull A arguments, diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index ce8d7a49540..b6a25f8c5e0 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -7,7 +7,8 @@ where advanced options include: -Xplugin Load plugins from the given classpath -Xmulti-platform Enable experimental language support for multi-platform projects -Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects + -Xskip-java-check Do not warn when running the compiler under Java 6 or 7 -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier Advanced options are non-standard and may be changed or removed without any notice. -OK \ No newline at end of file +OK diff --git a/compiler/testData/cli/js/version.out b/compiler/testData/cli/js/version.out index 77295403a32..1feaa1fb984 100644 --- a/compiler/testData/cli/js/version.out +++ b/compiler/testData/cli/js/version.out @@ -1,2 +1,3 @@ info: Kotlin Compiler version $VERSION$ +warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update. OK diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 28f67a08b88..b8d7c4e55ba 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -18,6 +18,7 @@ where advanced options include: -Xplugin Load plugins from the given classpath -Xmulti-platform Enable experimental language support for multi-platform projects -Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects + -Xskip-java-check Do not warn when running the compiler under Java 6 or 7 -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier Advanced options are non-standard and may be changed or removed without any notice. diff --git a/compiler/testData/cli/jvm/unknownExtraFlags.out b/compiler/testData/cli/jvm/unknownExtraFlags.out index bac1829ceb7..f03509ff611 100644 --- a/compiler/testData/cli/jvm/unknownExtraFlags.out +++ b/compiler/testData/cli/jvm/unknownExtraFlags.out @@ -1,4 +1,5 @@ warning: flag is not supported by this version of the compiler: -Xabcdefghijklm warning: flag is not supported by this version of the compiler: -Xnopqrstuvwxyz warning: flag is not supported by this version of the compiler: -XXxxxxxxxxxxxx +warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update. OK diff --git a/compiler/testData/cli/jvm/version.out b/compiler/testData/cli/jvm/version.out index 77295403a32..1feaa1fb984 100644 --- a/compiler/testData/cli/jvm/version.out +++ b/compiler/testData/cli/jvm/version.out @@ -1,2 +1,3 @@ info: Kotlin Compiler version $VERSION$ +warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update. OK diff --git a/compiler/tests-common/org/jetbrains/kotlin/integration/KotlinIntegrationTestBase.java b/compiler/tests-common/org/jetbrains/kotlin/integration/KotlinIntegrationTestBase.java index c14ba96636c..7a5d685f0b7 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/integration/KotlinIntegrationTestBase.java +++ b/compiler/tests-common/org/jetbrains/kotlin/integration/KotlinIntegrationTestBase.java @@ -87,6 +87,9 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir { content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]"); content = content.replaceAll(Pattern.quote(KotlinCompilerVersion.VERSION), "[KotlinVersion]"); content = StringUtil.convertLineSeparators(content); + content = Pattern.compile("^.+running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update\\.\n", Pattern.MULTILINE) + .matcher(content) + .replaceAll(""); return content; } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java b/compiler/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java index a71ca19b071..0b2f022b883 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java @@ -74,12 +74,13 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir { @NotNull BinaryVersion version ) { String testDataAbsoluteDir = new File(testDataDir).getAbsolutePath(); - String normalizedOutputWithoutExitCode = pureOutput + String normalizedOutputWithoutExitCode = StringUtil.convertLineSeparators(pureOutput) .replace(testDataAbsoluteDir, "$TESTDATA_DIR$") .replace(FileUtil.toSystemIndependentName(testDataAbsoluteDir), "$TESTDATA_DIR$") .replace(PathUtil.getKotlinPathsForDistDirectory().getHomePath().getAbsolutePath(), "$PROJECT_DIR$") .replace("expected version is " + version, "expected version is $ABI_VERSION$") .replace("\\", "/") + .replaceAll("^.+running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update\\.\n", "") .replace(KotlinCompilerVersion.VERSION, "$VERSION$"); return normalizedOutputWithoutExitCode + exitCode; diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java index 7a4f0bbc998..5efe36a7dff 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java @@ -43,6 +43,7 @@ public abstract class CompilerSmokeTestBase extends KotlinIntegrationTestBase { javaArgs.add("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"); Collections.addAll(javaArgs, arguments); + javaArgs.add("-Xskip-java-check"); return run(logName, ArrayUtil.toStringArray(javaArgs)); } diff --git a/compiler/tests/org/jetbrains/kotlin/multiplatform/AbstractMultiPlatformIntegrationTest.kt b/compiler/tests/org/jetbrains/kotlin/multiplatform/AbstractMultiPlatformIntegrationTest.kt index 44d2acf46fa..99e2b7a6d17 100644 --- a/compiler/tests/org/jetbrains/kotlin/multiplatform/AbstractMultiPlatformIntegrationTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/multiplatform/AbstractMultiPlatformIntegrationTest.kt @@ -39,7 +39,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() { val result = buildString { val (commonOutput, commonExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2MetadataCompiler(), listOf( - commonSrc.absolutePath, "-d", commonDest.absolutePath + commonSrc.absolutePath, "-d", commonDest.absolutePath, "-Xskip-java-check" )) appendln("-- Common --") appendln("Exit code: $commonExitCode") @@ -50,7 +50,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() { val (jvmOutput, jvmExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JVMCompiler(), listOf( jvmSrc.absolutePath, commonSrc.absolutePath, "-d", jvmDest.absolutePath, - "-Xmulti-platform" + "-Xmulti-platform", "-Xskip-java-check" )) appendln("-- JVM --") appendln("Exit code: $jvmExitCode") @@ -62,7 +62,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() { val (jsOutput, jsExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JSCompiler(), listOf( jsSrc.absolutePath, commonSrc.absolutePath, "-output", jsDest.absolutePath, - "-Xmulti-platform" + "-Xmulti-platform", "-Xskip-java-check" )) appendln("-- JS --") appendln("Exit code: $jsExitCode")