1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Fixed various syntax.

This commit is contained in:
Erik C. Thauvin 2017-10-31 23:17:42 -07:00
parent c99a9eb6cd
commit 05d0ff04fb
2 changed files with 32 additions and 39 deletions

View file

@ -89,12 +89,12 @@ class KotlinCompiler @Inject constructor(
// the K2JVMCompiler class directly // the K2JVMCompiler class directly
val actualVersion = kotlinVersion(project) val actualVersion = kotlinVersion(project)
if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION return if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION
|| info.compilerSeparateProcess) { || info.compilerSeparateProcess) {
return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) invokeCompilerInSeparateProcess(classpath, info, actualVersion, project)
} else { } else {
return invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir, invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir,
info, classpath, filesToCompile) info, classpath, filesToCompile)
} }
} }
@ -111,7 +111,7 @@ class KotlinCompiler @Inject constructor(
.filterNotNull() .filterNotNull()
.joinToString(" ") .joinToString(" ")
val xFlagsArray = xFlagsString.split(" ").toTypedArray() ?: emptyArray() val xFlagsArray = xFlagsString.split(" ").toTypedArray()
val newArgs = listOf( val newArgs = listOf(
"-classpath", compilerClasspath, "-classpath", compilerClasspath,
K2JVMCompiler::class.java.name, 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 // Collect the compiler args from kotlinCompiler{} and from settings.xml and parse them
val args2 = val args2 =
info.compilerArgs + info.compilerArgs +
(settings.kobaltCompilerFlags?.split(" ") ?: listOf<String>()) (settings.kobaltCompilerFlags?.split(" ") ?: listOf())
val args = K2JVMCompilerArguments() val args = K2JVMCompilerArguments()
val compiler = K2JVMCompiler() val compiler = K2JVMCompiler()
compiler.parseArguments(args2.toTypedArray(), args) compiler.parseArguments(args2.toTypedArray(), args)
@ -225,7 +225,7 @@ class KotlinCompiler @Inject constructor(
} }
fun dump(location: CompilerMessageLocation?, s: String) = fun dump(location: CompilerMessageLocation?, s: String) =
if (location != null && location.lineContent != null) { if (location?.lineContent != null) {
with(location) { with(location) {
"$lineContent\n$path:$line:$column $s" "$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 // // TODO: experimental should be removed as soon as it becomes standard
// System.setProperty("kotlin.incremental.compilation.experimental", "true") // System.setProperty("kotlin.incremental.compilation.experimental", "true")
val result = return if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) {
if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { log(2, " Kotlin incremental compilation is disabled")
log(2, " Kotlin incremental compilation is disabled") val duration = benchmarkMillis {
val duration = benchmarkMillis { compiler.exec(collector, Services.Builder().build(), args)
compiler.exec(collector, Services.Builder().build(), args) }
} log(1, " Regular compilation time: ${duration.first} ms")
log(1, " Regular compilation time: ${duration.first} ms") TaskResult(duration.second == ExitCode.OK)
TaskResult(duration.second == ExitCode.OK) } else {
} else { log(1, " Kotlin incremental compilation is enabled")
log(1, " Kotlin incremental compilation is enabled") //val start = System.currentTimeMillis()
val start = System.currentTimeMillis() val duration = benchmarkMillis {
val duration = benchmarkMillis { compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector)
compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector) }
} log(1, " Incremental compilation time: ${duration.first} ms")
log(1, " Incremental compilation time: ${duration.first} ms") TaskResult()
TaskResult() }
}
return result
} }
private fun compileIncrementally(filesToCompile: Int, sourceFiles: List<String>, outputDir: String?, private fun compileIncrementally(filesToCompile: Int, sourceFiles: List<String>, outputDir: String?,
@ -381,8 +379,7 @@ class KotlinCompiler @Inject constructor(
= dependencyManager.create("org.jetbrains" + ".kotlin:kotlin-compiler-embeddable:$version") = dependencyManager.create("org.jetbrains" + ".kotlin:kotlin-compiler-embeddable:$version")
fun compilerEmbeddableDependencies(project: Project?, version: String): List<IClasspathDependency> { fun compilerEmbeddableDependencies(project: Project?, version: String): List<IClasspathDependency> {
val deps = dependencyManager.transitiveClosure(listOf(compilerDep(version)), requiredBy = project?.name ?: "") return dependencyManager.transitiveClosure(listOf(compilerDep(version)), requiredBy = project?.name ?: "")
return deps
} }
/** /**
@ -415,7 +412,7 @@ class KotlinCompiler @Inject constructor(
if (project != null) { if (project != null) {
listOf(KFiles.joinDir(project.directory, project.buildDirectory, KFiles.CLASSES_DIR)) listOf(KFiles.joinDir(project.directory, project.buildDirectory, KFiles.CLASSES_DIR))
} else { } else {
emptyList<String>() emptyList()
} }
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args,
friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess) friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess)

View file

@ -80,12 +80,12 @@ class BintrayApi @Inject constructor(val http: Http,
// level = HttpLoggingInterceptor.Level.BASIC // level = HttpLoggingInterceptor.Level.BASIC
// }) // })
builder.interceptors().add(Interceptor { chain -> builder.interceptors().add(Interceptor { chain ->
val original = chain.request(); val original = chain.request()
chain.proceed(original.newBuilder() chain.proceed(original.newBuilder()
.header("Authorization", Credentials.basic(username, password)) .header("Authorization", Credentials.basic(username, password))
.method(original.method(), original.body()) .method(original.method(), original.body())
.build()); .build())
}) })
val okHttpClient = builder.build() val okHttpClient = builder.build()
@ -163,7 +163,7 @@ class BintrayApi @Inject constructor(val http: Http,
fun dots(total: Int, list: List<Boolean>, file: File? = null): String { fun dots(total: Int, list: List<Boolean>, file: File? = null): String {
val spaces: String = Array(total - list.size, { " " }).joinToString("") 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 "|") (if (file != null) "| [ $file ]" else "|")
} }
@ -208,7 +208,7 @@ class BintrayApi @Inject constructor(val http: Http,
return TaskResult() return TaskResult()
} else { } 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")) return TaskResult(false, errorMessage = errorMessages.joinToString("\n"))
} }
} else { } else {
@ -221,7 +221,7 @@ class BintrayApi @Inject constructor(val http: Http,
fun JsonObject.addNonNull(name: String, value: String?) { fun JsonObject.addNonNull(name: String, value: String?) {
if (value != null) { if (value != null) {
addProperty(name, value); addProperty(name, value)
} }
} }
@ -236,20 +236,16 @@ class ConverterFactory : Converter.Factory() {
override fun requestBodyConverter(type: Type, parameterAnnotations: Array<out Annotation>, override fun requestBodyConverter(type: Type, parameterAnnotations: Array<out Annotation>,
methodAnnotations: Array<out Annotation>, methodAnnotations: Array<out Annotation>,
retrofit: Retrofit?): Converter<*, RequestBody>? { retrofit: Retrofit?): Converter<*, RequestBody>? {
val result = return if (type.typeName == File::class.java.name) FileBodyConverter()
if (type.typeName == File::class.java.name) FileBodyConverter() else GsonBodyConverter()
else GsonBodyConverter()
return result
} }
} }
class GsonResponseBodyConverter(private val gson: Gson, private val adapter: TypeAdapter<out Any>) : Converter<ResponseBody, Any> { class GsonResponseBodyConverter(private val gson: Gson, private val adapter: TypeAdapter<out Any>) : Converter<ResponseBody, Any> {
override fun convert(value: ResponseBody): Any { override fun convert(value: ResponseBody): Any {
val jsonReader = gson.newJsonReader(value.charStream()) val jsonReader = gson.newJsonReader(value.charStream())
try { value.use {
return adapter.read(jsonReader) return adapter.read(jsonReader)
} finally {
value.close()
} }
} }
} }