Add the support suppressWarnings, verbose and version in build tools.
This commit is contained in:
+4
-5
@@ -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)) {
|
||||
|
||||
+33
-1
@@ -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()
|
||||
|
||||
+40
@@ -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"
|
||||
}
|
||||
+14
@@ -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"
|
||||
@@ -35,6 +35,12 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<version>16.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>gradle-api</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
+12
-3
@@ -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<String>): List<String> {
|
||||
private fun Project.createCommand(params: Array<String>): List<String> {
|
||||
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
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-js-suppressWarningsAndVersion</artifactId>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-js-library</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>js</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<nowarn>true</nowarn>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+20
@@ -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<String>) {
|
||||
println(getGreeting())
|
||||
}
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-helloworld</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<nowarn>true</nowarn>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+20
@@ -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<String>) {
|
||||
System.out?.println(getGreeting())
|
||||
}
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
+9
@@ -64,6 +64,13 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> 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<A extends CommonCompilerArguments> e
|
||||
throw new MojoExecutionException("No source roots to compile");
|
||||
}
|
||||
|
||||
arguments.suppressWarnings = nowarn;
|
||||
|
||||
arguments.freeArgs.addAll(sources);
|
||||
LOG.info("Compiling Kotlin sources from " + sources );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user