Skip to content

Commit af7de9a

Browse files
committed
Warn when running the compiler under Java 6 or 7
(cherry picked from commit 5537800) (cherry picked from commit 5614874)
1 parent 000da2f commit af7de9a

File tree

11 files changed

+29
-5
lines changed

11 files changed

+29
-5
lines changed

compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public abstract class CommonCompilerArguments implements Serializable {
7979
@Argument(value = "Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects")
8080
public boolean noCheckImpl;
8181

82+
@Argument(value = "Xskip-java-check", description = "Do not warn when running the compiler under Java 6 or 7")
83+
public boolean noJavaVersionWarning;
84+
8285
@Argument(value = "Xcoroutines=warn")
8386
public boolean coroutinesWarn;
8487

compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Servic
155155
}
156156

157157
reportUnknownExtraFlags(messageCollector, arguments);
158+
reportUnsupportedJavaVersion(messageCollector, arguments);
158159

159160
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
160161

@@ -350,6 +351,16 @@ private void reportUnknownExtraFlags(@NotNull MessageCollector collector, @NotNu
350351
}
351352
}
352353

354+
private void reportUnsupportedJavaVersion(MessageCollector collector, A arguments) {
355+
if (!SystemInfo.isJavaVersionAtLeast("1.8") && !arguments.noJavaVersionWarning) {
356+
collector.report(
357+
CompilerMessageSeverity.STRONG_WARNING,
358+
"Running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update.",
359+
CompilerMessageLocation.NO_LOCATION
360+
);
361+
}
362+
}
363+
353364
@NotNull
354365
protected abstract ExitCode doExecute(
355366
@NotNull A arguments,

compiler/testData/cli/js/jsExtraHelp.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ where advanced options include:
77
-Xplugin <path> Load plugins from the given classpath
88
-Xmulti-platform Enable experimental language support for multi-platform projects
99
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
10+
-Xskip-java-check Do not warn when running the compiler under Java 6 or 7
1011
-Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
1112

1213
Advanced options are non-standard and may be changed or removed without any notice.
13-
OK
14+
OK

compiler/testData/cli/js/version.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
info: Kotlin Compiler version $VERSION$
2+
warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update.
23
OK

compiler/testData/cli/jvm/extraHelp.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where advanced options include:
1818
-Xplugin <path> Load plugins from the given classpath
1919
-Xmulti-platform Enable experimental language support for multi-platform projects
2020
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
21+
-Xskip-java-check Do not warn when running the compiler under Java 6 or 7
2122
-Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
2223

2324
Advanced options are non-standard and may be changed or removed without any notice.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
warning: flag is not supported by this version of the compiler: -Xabcdefghijklm
22
warning: flag is not supported by this version of the compiler: -Xnopqrstuvwxyz
33
warning: flag is not supported by this version of the compiler: -XXxxxxxxxxxxxx
4+
warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update.
45
OK

compiler/testData/cli/jvm/version.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
info: Kotlin Compiler version $VERSION$
2+
warning: running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update.
23
OK

compiler/tests-common/org/jetbrains/kotlin/integration/KotlinIntegrationTestBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ protected String normalizeOutput(@NotNull File testDataDir, @NotNull String cont
8787
content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]");
8888
content = content.replaceAll(Pattern.quote(KotlinCompilerVersion.VERSION), "[KotlinVersion]");
8989
content = StringUtil.convertLineSeparators(content);
90+
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)
91+
.matcher(content)
92+
.replaceAll("");
9093
return content;
9194
}
9295

compiler/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ public static String getNormalizedCompilerOutput(
7474
@NotNull BinaryVersion version
7575
) {
7676
String testDataAbsoluteDir = new File(testDataDir).getAbsolutePath();
77-
String normalizedOutputWithoutExitCode = pureOutput
77+
String normalizedOutputWithoutExitCode = StringUtil.convertLineSeparators(pureOutput)
7878
.replace(testDataAbsoluteDir, "$TESTDATA_DIR$")
7979
.replace(FileUtil.toSystemIndependentName(testDataAbsoluteDir), "$TESTDATA_DIR$")
8080
.replace(PathUtil.getKotlinPathsForDistDirectory().getHomePath().getAbsolutePath(), "$PROJECT_DIR$")
8181
.replace("expected version is " + version, "expected version is $ABI_VERSION$")
8282
.replace("\\", "/")
83+
.replaceAll("^.+running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update\\.\n", "")
8384
.replace(KotlinCompilerVersion.VERSION, "$VERSION$");
8485

8586
return normalizedOutputWithoutExitCode + exitCode;

compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected int runCompiler(String logName, String... arguments) throws Exception
4343
javaArgs.add("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler");
4444

4545
Collections.addAll(javaArgs, arguments);
46+
javaArgs.add("-Xskip-java-check");
4647

4748
return run(logName, ArrayUtil.toStringArray(javaArgs));
4849
}

compiler/tests/org/jetbrains/kotlin/multiplatform/AbstractMultiPlatformIntegrationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() {
3939

4040
val result = buildString {
4141
val (commonOutput, commonExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2MetadataCompiler(), listOf(
42-
commonSrc.absolutePath, "-d", commonDest.absolutePath
42+
commonSrc.absolutePath, "-d", commonDest.absolutePath, "-Xskip-java-check"
4343
))
4444
appendln("-- Common --")
4545
appendln("Exit code: $commonExitCode")
@@ -50,7 +50,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() {
5050
val (jvmOutput, jvmExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JVMCompiler(), listOf(
5151
jvmSrc.absolutePath, commonSrc.absolutePath,
5252
"-d", jvmDest.absolutePath,
53-
"-Xmulti-platform"
53+
"-Xmulti-platform", "-Xskip-java-check"
5454
))
5555
appendln("-- JVM --")
5656
appendln("Exit code: $jvmExitCode")
@@ -62,7 +62,7 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() {
6262
val (jsOutput, jsExitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JSCompiler(), listOf(
6363
jsSrc.absolutePath, commonSrc.absolutePath,
6464
"-output", jsDest.absolutePath,
65-
"-Xmulti-platform"
65+
"-Xmulti-platform", "-Xskip-java-check"
6666
))
6767
appendln("-- JS --")
6868
appendln("Exit code: $jsExitCode")

0 commit comments

Comments
 (0)