From 05d0ff04fb31c569ca791e2ce977da76a5b44692 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 31 Oct 2017 23:17:42 -0700 Subject: [PATCH] Fixed various syntax. --- .../kobalt/plugin/kotlin/KotlinCompiler.kt | 51 +++++++++---------- .../beust/kobalt/plugin/publish/BintrayApi.kt | 20 +++----- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index cf1e50d0..0db6a5f3 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -89,12 +89,12 @@ class KotlinCompiler @Inject constructor( // the K2JVMCompiler class directly val actualVersion = kotlinVersion(project) - if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION + return if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION || info.compilerSeparateProcess) { - return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) + invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) } else { - return invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir, + invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir, info, classpath, filesToCompile) } } @@ -111,7 +111,7 @@ class KotlinCompiler @Inject constructor( .filterNotNull() .joinToString(" ") - val xFlagsArray = xFlagsString.split(" ").toTypedArray() ?: emptyArray() + val xFlagsArray = xFlagsString.split(" ").toTypedArray() val newArgs = listOf( "-classpath", compilerClasspath, K2JVMCompiler::class.java.name, @@ -145,7 +145,7 @@ class KotlinCompiler @Inject constructor( // Collect the compiler args from kotlinCompiler{} and from settings.xml and parse them val args2 = info.compilerArgs + - (settings.kobaltCompilerFlags?.split(" ") ?: listOf()) + (settings.kobaltCompilerFlags?.split(" ") ?: listOf()) val args = K2JVMCompilerArguments() val compiler = K2JVMCompiler() compiler.parseArguments(args2.toTypedArray(), args) @@ -225,7 +225,7 @@ class KotlinCompiler @Inject constructor( } fun dump(location: CompilerMessageLocation?, s: String) = - if (location != null && location.lineContent != null) { + if (location?.lineContent != null) { with(location) { "$lineContent\n$path:$line:$column $s" } @@ -250,24 +250,22 @@ class KotlinCompiler @Inject constructor( // // TODO: experimental should be removed as soon as it becomes standard // System.setProperty("kotlin.incremental.compilation.experimental", "true") - val result = - if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { - log(2, " Kotlin incremental compilation is disabled") - val duration = benchmarkMillis { - compiler.exec(collector, Services.Builder().build(), args) - } - log(1, " Regular compilation time: ${duration.first} ms") - TaskResult(duration.second == ExitCode.OK) - } else { - log(1, " Kotlin incremental compilation is enabled") - val start = System.currentTimeMillis() - val duration = benchmarkMillis { - compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector) - } - log(1, " Incremental compilation time: ${duration.first} ms") - TaskResult() - } - return result + return if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { + log(2, " Kotlin incremental compilation is disabled") + val duration = benchmarkMillis { + compiler.exec(collector, Services.Builder().build(), args) + } + log(1, " Regular compilation time: ${duration.first} ms") + TaskResult(duration.second == ExitCode.OK) + } else { + log(1, " Kotlin incremental compilation is enabled") + //val start = System.currentTimeMillis() + val duration = benchmarkMillis { + compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector) + } + log(1, " Incremental compilation time: ${duration.first} ms") + TaskResult() + } } private fun compileIncrementally(filesToCompile: Int, sourceFiles: List, outputDir: String?, @@ -381,8 +379,7 @@ class KotlinCompiler @Inject constructor( = dependencyManager.create("org.jetbrains" + ".kotlin:kotlin-compiler-embeddable:$version") fun compilerEmbeddableDependencies(project: Project?, version: String): List { - val deps = dependencyManager.transitiveClosure(listOf(compilerDep(version)), requiredBy = project?.name ?: "") - return deps + return dependencyManager.transitiveClosure(listOf(compilerDep(version)), requiredBy = project?.name ?: "") } /** @@ -415,7 +412,7 @@ class KotlinCompiler @Inject constructor( if (project != null) { listOf(KFiles.joinDir(project.directory, project.buildDirectory, KFiles.CLASSES_DIR)) } else { - emptyList() + emptyList() } val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt index e047e013..3789b88d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt @@ -80,12 +80,12 @@ class BintrayApi @Inject constructor(val http: Http, // level = HttpLoggingInterceptor.Level.BASIC // }) builder.interceptors().add(Interceptor { chain -> - val original = chain.request(); + val original = chain.request() chain.proceed(original.newBuilder() .header("Authorization", Credentials.basic(username, password)) .method(original.method(), original.body()) - .build()); + .build()) }) val okHttpClient = builder.build() @@ -163,7 +163,7 @@ class BintrayApi @Inject constructor(val http: Http, fun dots(total: Int, list: List, file: File? = null): String { val spaces: String = Array(total - list.size, { " " }).joinToString("") - return "|" + list.map { if (it) "." else "X" }.joinToString("") + spaces + + return "|" + list.joinToString("") { if (it) "." else "X" } + spaces + (if (file != null) "| [ $file ]" else "|") } @@ -208,7 +208,7 @@ class BintrayApi @Inject constructor(val http: Http, return TaskResult() } else { - error(" Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n")) + error(" Errors while uploading:\n" + errorMessages.joinToString("\n") { " $it" }) return TaskResult(false, errorMessage = errorMessages.joinToString("\n")) } } else { @@ -221,7 +221,7 @@ class BintrayApi @Inject constructor(val http: Http, fun JsonObject.addNonNull(name: String, value: String?) { if (value != null) { - addProperty(name, value); + addProperty(name, value) } } @@ -236,20 +236,16 @@ class ConverterFactory : Converter.Factory() { override fun requestBodyConverter(type: Type, parameterAnnotations: Array, methodAnnotations: Array, retrofit: Retrofit?): Converter<*, RequestBody>? { - val result = - if (type.typeName == File::class.java.name) FileBodyConverter() - else GsonBodyConverter() - return result + return if (type.typeName == File::class.java.name) FileBodyConverter() + else GsonBodyConverter() } } class GsonResponseBodyConverter(private val gson: Gson, private val adapter: TypeAdapter) : Converter { override fun convert(value: ResponseBody): Any { val jsonReader = gson.newJsonReader(value.charStream()) - try { + value.use { return adapter.read(jsonReader) - } finally { - value.close() } } }