diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt index c3ccf4a7739..d84fa58ed81 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt @@ -29,6 +29,8 @@ import org.apache.tools.ant.types.Commandline import com.sampullara.cli.Args import java.io.IOException import org.jetbrains.jet.config +import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector +import org.jetbrains.jet.cli.common.messages.MessageRenderer /** * {@code file.getCanonicalPath()} convenience wrapper. @@ -55,6 +57,9 @@ public abstract class KotlinCompilerBaseTask : Task public var src: Path? = null public var output: File? = null + public var nowarn: Boolean = false + public var verbose: Boolean = false + public var printVersion: Boolean = false public val additionalArguments: MutableList = arrayListOf() @@ -87,6 +92,10 @@ public abstract class KotlinCompilerBaseTask : Task output ?: throw BuildException("\"output\" should be specified") + arguments.suppressWarnings = nowarn + arguments.verbose = verbose + arguments.version = printVersion + val args = additionalArguments.flatMap { it.getParts()!!.toList() } try { Args.parse(arguments, args.copyToArray()) @@ -105,7 +114,8 @@ public abstract class KotlinCompilerBaseTask : Task log("Compiling ${arguments.freeArgs} => [${outputPath}]"); - val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, config.Services.EMPTY, arguments) + val collector = PrintingMessageCollector(System.err, MessageRenderer.PLAIN, arguments.verbose) + val exitCode = compiler.exec(collector, config.Services.EMPTY, arguments) if (exitCode != ExitCode.OK) { throw BuildException("Compilation finished with exit code $exitCode") diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java index 893322b1732..e4c55dd9c50 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java @@ -116,14 +116,8 @@ public abstract class CLICompiler { errStream.print(messageRenderer.renderPreamble()); - printVersionIfNeeded(errStream, arguments, messageRenderer); - MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose); - if (arguments.suppressWarnings) { - collector = new FilteringMessageCollector(collector, Predicates.equalTo(CompilerMessageSeverity.WARNING)); - } - try { return exec(collector, services, arguments); } @@ -134,6 +128,12 @@ public abstract class CLICompiler { @NotNull public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) { + printVersionIfNeeded(messageCollector, arguments); + + if (arguments.suppressWarnings) { + messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING)); + } + GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector); try { Disposable rootDisposable = Disposer.newDisposable(); @@ -164,17 +164,12 @@ public abstract class CLICompiler { @NotNull Disposable rootDisposable ); - protected void printVersionIfNeeded( - @NotNull PrintStream errStream, - @NotNull A arguments, - @NotNull MessageRenderer messageRenderer - ) { - if (arguments.version) { - String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO, - "Kotlin Compiler version " + KotlinVersion.VERSION, - CompilerMessageLocation.NO_LOCATION); - errStream.println(versionMessage); - } + protected void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) { + if (!arguments.version) return; + + messageCollector.report(CompilerMessageSeverity.INFO, + "Kotlin Compiler version " + KotlinVersion.VERSION, + CompilerMessageLocation.NO_LOCATION); } /** diff --git a/compiler/integration-tests/compiler-integration-tests.iml b/compiler/integration-tests/compiler-integration-tests.iml index 9e68b015744..e9e580dbddd 100644 --- a/compiler/integration-tests/compiler-integration-tests.iml +++ b/compiler/integration-tests/compiler-integration-tests.iml @@ -11,6 +11,6 @@ + - - + \ No newline at end of file diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java index fe39293c8ad..8d481f18dee 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java @@ -102,6 +102,21 @@ public class AntTaskJsTest extends AntTaskBaseTest { doJsAntTest(); } + @Test + public void suppressWarnings() throws Exception { + doJsAntTest(); + } + + @Test + public void verbose() throws Exception { + doJsAntTest(); + } + + @Test + public void version() throws Exception { + doJsAntTest(); + } + @Test public void noSrcParam() throws Exception { diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJvmTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJvmTest.java index 71fa826035f..3f81a32889b 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJvmTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJvmTest.java @@ -76,6 +76,21 @@ public class AntTaskJvmTest extends AntTaskBaseTest { doJvmAntTest(); } + @Test + public void suppressWarnings() throws Exception { + doJvmAntTest(); + } + + @Test + public void verbose() throws Exception { + doJvmAntTest(); + } + + @Test + public void version() throws Exception { + doJvmAntTest(); + } + @Test public void javacCompiler() throws Exception { doJvmAntTest("-cp", getClassPathForAnt(), diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java index efa553dec4f..676e31a6e50 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java @@ -31,6 +31,7 @@ import kotlin.KotlinPackage; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.cli.common.KotlinVersion; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.jet.test.Tmpdir; import org.jetbrains.jet.utils.PathUtil; @@ -95,6 +96,8 @@ public abstract class KotlinIntegrationTestBase { content = normalizePath(content, getTestDataDir(), "[TestData]"); content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]"); content = normalizePath(content, getCompilerLib(), "[CompilerLib]"); + content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]"); + content = content.replaceAll(KotlinVersion.VERSION, "[KotlinVersion]"); content = StringUtil.convertLineSeparators(content); return content; } diff --git a/compiler/integration-tests/testData/ant/js/suppressWarnings/build.log.expected b/compiler/integration-tests/testData/ant/js/suppressWarnings/build.log.expected new file mode 100644 index 00000000000..438f56679ca --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/suppressWarnings/build.log.expected @@ -0,0 +1,10 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: +[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/js/suppressWarnings/build.xml b/compiler/integration-tests/testData/ant/js/suppressWarnings/build.xml new file mode 100644 index 00000000000..9f866514b62 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/suppressWarnings/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/js/suppressWarnings/root1/foo.kt b/compiler/integration-tests/testData/ant/js/suppressWarnings/root1/foo.kt new file mode 100644 index 00000000000..b97b1e74260 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/suppressWarnings/root1/foo.kt @@ -0,0 +1,14 @@ +package foo + +import kotlin.Any +import kotlin.Any + +fun foo(p: Int??) { + +} + +trait T { + abstract fun foo() +} + +fun box(): String = "OK" diff --git a/compiler/integration-tests/testData/ant/js/verbose/build.log.expected b/compiler/integration-tests/testData/ant/js/verbose/build.log.expected new file mode 100644 index 00000000000..db86edb3ce6 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/verbose/build.log.expected @@ -0,0 +1,15 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: +[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] +[kotlin2js] LOGGING: Compiling source files: [TestData]/root1/foo.kt +[kotlin2js] OUTPUT: Output: +[kotlin2js] [Temp]/out.js +[kotlin2js] Sources: +[kotlin2js] [TestData]/root1/foo.kt + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/js/verbose/build.xml b/compiler/integration-tests/testData/ant/js/verbose/build.xml new file mode 100644 index 00000000000..c6de721f6bc --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/verbose/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/js/verbose/root1/foo.kt b/compiler/integration-tests/testData/ant/js/verbose/root1/foo.kt new file mode 100644 index 00000000000..f6123b9882f --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/verbose/root1/foo.kt @@ -0,0 +1,3 @@ +package foo + +fun box(): String = "OK" diff --git a/compiler/integration-tests/testData/ant/js/version/build.log.expected b/compiler/integration-tests/testData/ant/js/version/build.log.expected new file mode 100644 index 00000000000..660964d92bd --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/version/build.log.expected @@ -0,0 +1,11 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: +[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] +[kotlin2js] INFO: Kotlin Compiler version [KotlinVersion] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/js/version/build.xml b/compiler/integration-tests/testData/ant/js/version/build.xml new file mode 100644 index 00000000000..09fa5329255 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/version/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/js/version/root1/foo.kt b/compiler/integration-tests/testData/ant/js/version/root1/foo.kt new file mode 100644 index 00000000000..f6123b9882f --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/version/root1/foo.kt @@ -0,0 +1,3 @@ +package foo + +fun box(): String = "OK" diff --git a/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.log.expected b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.log.expected new file mode 100644 index 00000000000..bdd3291fcb4 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.log.expected @@ -0,0 +1,10 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.xml b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.xml new file mode 100644 index 00000000000..92e56eeb094 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.kt b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.kt new file mode 100644 index 00000000000..17ad0702849 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.kt @@ -0,0 +1,13 @@ +package hello + +fun foo(p: Int??) { + +} + +trait T { + abstract fun foo() +} + +fun main(args : Array) { + println("Hi!") +} diff --git a/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.run.expected b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.run.expected new file mode 100644 index 00000000000..20c284504fb --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/suppressWarnings/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hi! + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/jvm/verbose/build.log.expected b/compiler/integration-tests/testData/ant/jvm/verbose/build.log.expected new file mode 100644 index 00000000000..5b0f97433c7 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/verbose/build.log.expected @@ -0,0 +1,12 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar] + [kotlinc] LOGGING: Using Kotlin home directory [KotlinProjectHome]/dist/kotlinc + [kotlinc] LOGGING: Configuring the compilation environment + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/jvm/verbose/build.xml b/compiler/integration-tests/testData/ant/jvm/verbose/build.xml new file mode 100644 index 00000000000..2be0c50fa69 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/verbose/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/jvm/verbose/hello.kt b/compiler/integration-tests/testData/ant/jvm/verbose/hello.kt new file mode 100644 index 00000000000..30d773783e7 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/verbose/hello.kt @@ -0,0 +1,5 @@ +package hello + +fun main(args : Array) { + println("Hi!") +} diff --git a/compiler/integration-tests/testData/ant/jvm/verbose/hello.run.expected b/compiler/integration-tests/testData/ant/jvm/verbose/hello.run.expected new file mode 100644 index 00000000000..20c284504fb --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/verbose/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hi! + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/jvm/version/build.log.expected b/compiler/integration-tests/testData/ant/jvm/version/build.log.expected new file mode 100644 index 00000000000..db341b75807 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/version/build.log.expected @@ -0,0 +1,11 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar] + [kotlinc] INFO: Kotlin Compiler version [KotlinVersion] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/jvm/version/build.xml b/compiler/integration-tests/testData/ant/jvm/version/build.xml new file mode 100644 index 00000000000..2d797fac56e --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/version/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/jvm/version/hello.kt b/compiler/integration-tests/testData/ant/jvm/version/hello.kt new file mode 100644 index 00000000000..f04b2b73595 --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/version/hello.kt @@ -0,0 +1,5 @@ +package hello + +fun main(args : Array) { + println("Yo!") +} diff --git a/compiler/integration-tests/testData/ant/jvm/version/hello.run.expected b/compiler/integration-tests/testData/ant/jvm/version/hello.run.expected new file mode 100644 index 00000000000..683c9b6f7ba --- /dev/null +++ b/compiler/integration-tests/testData/ant/jvm/version/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Yo! + +Return code: 0 diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index ab032648c8d..4ec7003afc3 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -1,13 +1,11 @@ package org.jetbrains.kotlin.gradle.tasks import org.gradle.api.tasks.compile.AbstractCompile -import org.jetbrains.kotlin.gradle.plugin.KSpec import java.io.File import org.gradle.api.GradleException import org.jetbrains.jet.cli.common.ExitCode import org.gradle.api.tasks.SourceTask import org.jetbrains.kotlin.doc.KDocArguments -import java.util.HashMap import java.util.HashSet import org.jetbrains.kotlin.doc.KDocCompiler import org.gradle.api.tasks.TaskAction @@ -22,11 +20,8 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging import org.apache.commons.lang.StringUtils -import org.gradle.api.initialization.dsl.ScriptHandler import org.apache.commons.io.FileUtils import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.doc.KDocConfig -import java.util.concurrent.Callable import org.gradle.api.Project import org.jetbrains.jet.config.Services @@ -101,6 +96,10 @@ public open class KotlinCompile(): AbstractCompile() { return } + args.suppressWarnings = kotlinOptions.suppressWarnings + args.version = kotlinOptions.version + args.verbose = logger.isDebugEnabled() + args.freeArgs = sources.map { it.getAbsolutePath() } if (StringUtils.isEmpty(kotlinOptions.classpath)) { diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index 4ec8660d6f6..bacc6e2dd34 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -1,8 +1,8 @@ package org.jetbrains.kotlin.gradle import org.junit.Test -import org.junit.Ignore import org.jetbrains.kotlin.gradle.BaseGradleIT.Project +import org.gradle.api.logging.LogLevel class BasicKotlinGradleIT : BaseGradleIT() { @@ -21,6 +21,38 @@ class BasicKotlinGradleIT : BaseGradleIT() { } } + Test fun testSuppressWarningsAndVersionInVerboseMode() { + val project = Project("suppressWarningsAndVersion", "1.6") + + project.build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { + assertSuccessful() + assertContains(":compileKotlin", "i: Kotlin Compiler version", "v: Using Kotlin home directory") + assertNotContains("w:") + } + + project.build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { + assertSuccessful() + assertContains(":compileKotlin UP-TO-DATE") + assertNotContains("w:") + } + } + + Test fun testSuppressWarningsAndVersionInNonVerboseMode() { + val project = Project("suppressWarningsAndVersion", "1.6", minLogLevel = LogLevel.INFO) + + project.build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { + assertSuccessful() + assertContains(":compileKotlin", "i: Kotlin Compiler version") + assertNotContains("w:", "v:") + } + + project.build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { + assertSuccessful() + assertContains(":compileKotlin UP-TO-DATE") + assertNotContains("w:", "v:") + } + } + Test fun testKotlinCustomDirectory() { Project("customSrcDir", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { assertSuccessful() diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/build.gradle b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/build.gradle new file mode 100644 index 00000000000..f0c428b4e6e --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/build.gradle @@ -0,0 +1,40 @@ +buildscript { + repositories { + mavenCentral() + maven { + url 'file://' + pathToKotlinPlugin + } + } + dependencies { + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin-core:0.1-SNAPSHOT' + } +} + +import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin + +apply plugin: KotlinPlugin + +sourceSets { + main { + kotlin { + srcDir 'src' + } + } +} + +repositories { + maven { + url 'file://' + pathToKotlinPlugin + } + mavenCentral() +} + +compileKotlin { + kotlinOptions.suppressWarnings = true + kotlinOptions.version = true +} + + +task wrapper(type: Wrapper) { + gradleVersion="1.4" +} diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/src/helloWorld.kt b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/src/helloWorld.kt new file mode 100644 index 00000000000..b97b1e74260 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/suppressWarningsAndVersion/src/helloWorld.kt @@ -0,0 +1,14 @@ +package foo + +import kotlin.Any +import kotlin.Any + +fun foo(p: Int??) { + +} + +trait T { + abstract fun foo() +} + +fun box(): String = "OK" diff --git a/libraries/tools/kotlin-gradle-plugin-test/pom.xml b/libraries/tools/kotlin-gradle-plugin-test/pom.xml index c8d89c918e3..0b147c38244 100644 --- a/libraries/tools/kotlin-gradle-plugin-test/pom.xml +++ b/libraries/tools/kotlin-gradle-plugin-test/pom.xml @@ -35,6 +35,12 @@ guava 16.0.1 + + org.jetbrains.kotlin + gradle-api + 1.6 + provided + diff --git a/libraries/tools/kotlin-gradle-plugin-test/src/main/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-test/src/main/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index 8930d033b42..426e1ca0b0d 100644 --- a/libraries/tools/kotlin-gradle-plugin-test/src/main/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-test/src/main/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -7,8 +7,10 @@ import java.util.Scanner import org.junit.Before import org.junit.After import kotlin.test.assertTrue +import kotlin.test.assertFalse import kotlin.test.assertEquals import kotlin.test.fail +import org.gradle.api.logging.LogLevel open class BaseGradleIT(resourcesRoot: String = "src/test/resources") { @@ -23,7 +25,7 @@ open class BaseGradleIT(resourcesRoot: String = "src/test/resources") { deleteRecursively(workingDir) } - class Project(val projectName: String, val wrapperVersion: String = "1.4") + class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG) class CompiledProject(val project: Project, val output: String, val resultCode: Int) @@ -50,14 +52,21 @@ open class BaseGradleIT(resourcesRoot: String = "src/test/resources") { return this } + fun CompiledProject.assertNotContains(vararg expected: String): CompiledProject { + for (str in expected) { + assertFalse(output.contains(str), "Should not contain '$str', actual output: $output") + } + return this + } + fun CompiledProject.assertReportExists(pathToReport: String = ""): CompiledProject { assertTrue(File(File(workingDir, project.projectName), pathToReport).exists(), "The report [$pathToReport] does not exist.") return this } - private fun createCommand(params: Array): List { + private fun Project.createCommand(params: Array): List { val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath() - val tailParameters = params + listOf(pathToKotlinPlugin, "--no-daemon", "--debug") + val tailParameters = params + listOf(pathToKotlinPlugin, "--no-daemon", "--${minLogLevel.name().toLowerCase()}") return if (isWindows()) listOf("cmd", "/C", "gradlew.bat") + tailParameters diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/pom.xml new file mode 100644 index 00000000000..f7702193138 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-project + 0.1-SNAPSHOT + ../../pom.xml + + + test-js-suppressWarningsAndVersion + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${project.version} + + + org.jetbrains.kotlin + kotlin-js-library + ${project.version} + + + + + compile + + js + + + + + true + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt new file mode 100644 index 00000000000..a2dabbd8903 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,20 @@ +package org.jetbrains + +import kotlin.Any +import kotlin.Any + +fun foo(p: Int??) { + +} + +trait T { + abstract fun foo() +} + +fun main(args : Array) { + println(getGreeting()) +} + +fun getGreeting() : String { + return "Hello, World!" +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/verify.bsh new file mode 100644 index 00000000000..582689710af --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-suppressWarnings/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/js/test-js-suppressWarningsAndVersion.js"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JS : " + file); +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/pom.xml new file mode 100644 index 00000000000..6fb8f582609 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-project + 0.1-SNAPSHOT + ../../pom.xml + + + test-helloworld + + + + junit + junit + 4.9 + + + org.jetbrains.kotlin + kotlin-runtime + ${project.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${project.version} + + + compile + process-sources + + compile + + + + + true + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt new file mode 100644 index 00000000000..1db88783020 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,20 @@ +package org.jetbrains + +import kotlin.Any +import kotlin.Any + +fun foo(p: Int??) { + +} + +trait T { + abstract fun foo() +} + +fun main(args : Array) { + System.out?.println(getGreeting()) +} + +fun getGreeting() : String { + return "Hello, World!" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/verify.bsh new file mode 100644 index 00000000000..00656d3d18d --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-suppressWarnings/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/test-helloworld-0.1-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +} diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index 67027918022..39d493d1271 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -64,6 +64,13 @@ public abstract class KotlinCompileMojoBase e return defaultSourceDirs; } + /** + * Suppress all warnings. + * + * @parameter default-value="false" + */ + public boolean nowarn; + // TODO not sure why this doesn't work :( // * @parameter default-value="$(project.basedir}/src/main/resources" @@ -238,6 +245,8 @@ public abstract class KotlinCompileMojoBase e throw new MojoExecutionException("No source roots to compile"); } + arguments.suppressWarnings = nowarn; + arguments.freeArgs.addAll(sources); LOG.info("Compiling Kotlin sources from " + sources );