Change how kotlinc and tools display their version

- Display the Kotlin version in kotlin-gradle-plugin. This is needed
  because if "-version" is specified in compiler arguments, the "info"
  level of the message printed by the compiler in CLICompiler prevents
  it from being displayed by default (unless "--debug" is passed to
  Gradle).
- Display the version of JRE the compiler is running on. This will be
  helpful to diagnose Java 9 related issues in the future.
- In CLI, also display the executable name (kotlinc-jvm or kotlinc-js)
This commit is contained in:
Alexander Udalov
2017-04-06 18:29:48 +03:00
parent bb01ca038a
commit fcf44af294
26 changed files with 63 additions and 67 deletions
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
import org.jetbrains.kotlin.daemon.common.*
@@ -100,6 +101,12 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
compilerArgs: CommonCompilerArguments,
environment: GradleCompilerEnvironment
): ExitCode {
if (compilerArgs.version) {
project.logger.lifecycle("Kotlin version " + KotlinCompilerVersion.VERSION +
" (JRE " + System.getProperty("java.runtime.version") + ")")
compilerArgs.version = false
}
val argsArray = ArgumentUtils.convertArgumentsToStringList(compilerArgs).toTypedArray()
with (project.logger) {
kotlinDebug { "Kotlin compiler class: $compilerClassName" }
@@ -1,11 +1,11 @@
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/test-extension/src/main/kotlin]
[INFO] Module name is test-extension
[WARNING] Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath or use '-Xskip-runtime-version-check' to suppress this warning
[WARNING] /local-repo/org/jetbrains/kotlin/kotlin-compiler/@snapshot@/kotlin-compiler-@snapshot@.jar: (-1, -1) Library has Kotlin runtime bundled into it
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[WARNING] No sources found skipping Kotlin compile
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/use-test-extension/src/main/kotlin]
[INFO] Module name is use-test-extension
[INFO] Applicability test for project use-test-extension
@@ -13,5 +13,5 @@
[INFO] Configuring test plugin with arguments
[INFO] Plugin applied
[INFO] Option value: my-special-value
[INFO] Kotlin Compiler version @snapshot@
[WARNING] No sources found skipping Kotlin compile
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[WARNING] No sources found skipping Kotlin compile
@@ -1,5 +1,5 @@
/**
* NOTE: if this script returns false, the build log with more information can be found at tools/kotlin-maven-plugin/target/it/plugins/build.log
* NOTE: if this script returns false, the build log with more information can be found at tools/kotlin-maven-plugin-test/target/it/plugins/build.log
*/
import java.util.regex.Pattern
@@ -38,7 +38,8 @@ State state = buildLogFile.readLines().collect { it.replaceAll("\\u001b[^m]*m",
replaceAll(/[0-9]+\s*ms/, "LLL ms").
trim().
replaceAll(/^\[[A-Z]+\]$/, "").
replace(kotlinVersion, "@snapshot@")
replace(kotlinVersion, "@snapshot@").
replaceAll(/\(JRE .+\)/, "(JRE <jre-version>)")
if (filtered != "") {
acc.lines << filtered
@@ -1,3 +1,3 @@
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/src/main/kotlin]
[INFO] Module name is test-project
@@ -35,7 +35,8 @@ State state = new File(basedir, "build.log").readLines().collect { it.replaceAll
replaceAll(/[0-9]+\s*ms/, "LLL ms").
trim().
replaceAll(/^\[[A-Z]+\]$/, "").
replaceAll(/version [0-9a-z-+\.]+/, "version @snapshot@")
replaceAll(/version [0-9a-z-+\.]+/, "version @snapshot@").
replaceAll(/\(JRE .+\)/, "(JRE <jre-version>)")
if (filtered != "") {
acc.lines << filtered
@@ -198,8 +198,8 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Kotlin Compiler version " + KotlinCompilerVersion.VERSION);
getLog().info("Kotlin version " + KotlinCompilerVersion.VERSION +
" (JRE " + System.getProperty("java.runtime.version") + ")");
if (!hasKotlinFilesInSources()) {
getLog().warn("No sources found skipping Kotlin compile");