diff --git a/compiler/testData/cli/jvm/warningJdkWithNoJdk.args b/compiler/testData/cli/jvm/warningJdkWithNoJdk.args new file mode 100644 index 00000000000..19536fe9476 --- /dev/null +++ b/compiler/testData/cli/jvm/warningJdkWithNoJdk.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/simple.kt +-d +$TEMP_DIR$ +-jdk +$TESTDATA_DIR$ +-no-jdk diff --git a/compiler/testData/cli/jvm/warningJdkWithNoJdk.out b/compiler/testData/cli/jvm/warningJdkWithNoJdk.out new file mode 100644 index 00000000000..1958ae1c5cb --- /dev/null +++ b/compiler/testData/cli/jvm/warningJdkWithNoJdk.out @@ -0,0 +1,2 @@ +warning: the '-jdk' option with a path to JDK is ignored because '-no-jdk' is specified +OK diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 6981f08ce7f..ba199bc2156 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -265,6 +265,12 @@ public class CliTestGenerated extends AbstractCliTest { doJvmTest(fileName); } + @TestMetadata("warningJdkWithNoJdk.args") + public void testWarningJdkWithNoJdk() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningJdkWithNoJdk.args"); + doJvmTest(fileName); + } + @TestMetadata("warningsInDummy.args") public void testWarningsInDummy() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningsInDummy.args"); diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt index c9949138352..f3bf3e651b7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt @@ -107,6 +107,15 @@ class SimpleKotlinGradleIT : BaseGradleIT() { } } + @Test + fun testCustomJdk() { + Project("customJdk", "1.6").build("build") { + assertFailed() + assertContains("Unresolved reference: stream") + assertNotContains("AutoCloseable") + } + } + @Test fun testGradleSubplugin() { val project = Project("kotlinGradleSubplugin", "1.6") diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/build.gradle b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/build.gradle new file mode 100644 index 00000000000..689f054d6fc --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/build.gradle @@ -0,0 +1,40 @@ +buildscript { + repositories { + mavenCentral() + maven { + url 'file://' + pathToKotlinPlugin + } + } + dependencies { + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-SNAPSHOT' + } +} + +apply plugin: "kotlin" + +sourceSets { + main { + kotlin { + srcDir 'src' + } + } +} + +repositories { + maven { + url 'file://' + pathToKotlinPlugin + } + mavenCentral() +} + +dependencies { + compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1-SNAPSHOT' +} + +compileKotlin { + kotlinOptions.jdk = System.getenv("JDK_17") +} + +task wrapper(type: Wrapper) { + gradleVersion = "1.4" +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/src/main.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/src/main.kt new file mode 100644 index 00000000000..7f09733c2a7 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/customJdk/src/main.kt @@ -0,0 +1,9 @@ +// available in JDK 1.7 +fun java.lang.AutoCloseable.silentClose() { + +} + +// available in JDK 1.8, should be an error with JDK 1.7 +fun java.util.stream.Stream.count(): Int { + return 0 +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/invoker.properties b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/invoker.properties new file mode 100644 index 00000000000..c21e972fc6b --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/invoker.properties @@ -0,0 +1 @@ +invoker.buildResult = failure diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/pom.xml new file mode 100644 index 00000000000..01dd2d363dc --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-customJdk + 1.0-SNAPSHOT + + + + junit + junit + 4.9 + + + org.jetbrains.kotlin + kotlin-runtime + ${kotlin.version} + + + + + ${env.JDK_18} + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + process-sources + + compile + + + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/src/main/kotlin/main.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/src/main/kotlin/main.kt new file mode 100644 index 00000000000..7f09733c2a7 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/src/main/kotlin/main.kt @@ -0,0 +1,9 @@ +// available in JDK 1.7 +fun java.lang.AutoCloseable.silentClose() { + +} + +// available in JDK 1.8, should be an error with JDK 1.7 +fun java.util.stream.Stream.count(): Int { + return 0 +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/verify.bsh new file mode 100644 index 00000000000..147f952b5b4 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-customJdk/verify.bsh @@ -0,0 +1,5 @@ +source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath()); + +assertBuildLogHasLine("[INFO] BUILD FAILURE"); +assertBuildLogHasNoLineThatContains("AutoCloseable"); +assertBuildLogHasLineThatContains("Unresolved reference: stream"); diff --git a/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh b/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh index 1f1afc149db..a38ee0a75d8 100644 --- a/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh +++ b/libraries/tools/kotlin-maven-plugin-test/verify-common.bsh @@ -1,38 +1,50 @@ -File buildLog = new File(basedir, "build.log"); +String[] getBuildLogLines() { + File buildLog = new File(basedir, "build.log"); + BufferedReader reader = new BufferedReader(new FileReader(buildLog)); + List result = new ArrayList(); + String line; + while ((line = reader.readLine()) != null){ + line=line.replaceAll("\\u001b[^m]*m",""); + result.add(line); + } + reader.close(); + return result.toArray(new String[0]); +} + +String[] buildLog = getBuildLogLines(); + void assertBuildLogHasLine(String expectedLine) { - BufferedReader reader = new BufferedReader(new FileReader(buildLog)); - try { - String line; - int i = 0; - while ((line = reader.readLine()) != null) { - line = line.replaceAll("\\u001b[^m]*m", ""); - i++; - if (line.equals(expectedLine)) { - print("Expected line was found at line " + i + " of build log: " + "\"" + expectedLine + "\""); - return; - } + for (int i = 0; i < buildLog.length; i++) { + String line = buildLog[i]; + if (line.equals(expectedLine)) { + print("Expected line was found at line " + i + " of build log: " + "\"" + expectedLine + "\""); + return; } - throw new Exception("Expected build log to contain line: \"" + expectedLine + "\""); - } finally { - reader.close(); } + throw new Exception("Expected build log to contain line: \"" + expectedLine + "\""); } void assertBuildLogHasLineThatContains(String content) { - BufferedReader reader = new BufferedReader(new FileReader(buildLog)); - try { - String line; - int i = 0; - while ((line = reader.readLine()) != null) { - i++; - if (line.contains(content)) { - print("Expected content " + "\"" + content + "\"" + " was found at line " + i + " of build log: " + "\"" + line + "\""); - return; - } - } + int line = findBuildLogLineThatContains(content); + if (line >= 0) + print("Expected content " + "\"" + content + "\"" + " was found at line " + (line+1) + " of build log: " + "\"" + buildLog[line] + "\""); + else throw new Exception("Expected build log to contain: \"" + content + "\""); - } finally { - reader.close(); +} + +void assertBuildLogHasNoLineThatContains(String content) { + int line = findBuildLogLineThatContains(content); + if (line >= 0) + throw new Exception("Expected build log not to contain content " + "\"" + content + "\"" + ", but was found at line " + (line+1) + ": " + "\"" + buildLog[line] + "\""); +} + +int findBuildLogLineThatContains(String content) { + for (int i = 0; i < buildLog.length; i++) { + String line = buildLog[i]; + if (line.contains(content)) { + return i; + } } + return -1; } \ No newline at end of file