diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index ab46b7e6..b8da5e5b 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -25,16 +25,18 @@ val bs = buildScript { } object Versions { - val okhttp = "3.2.0" - val okio = "1.6.0" - val retrofit = "2.1.0" - val gson = "2.6.2" - val maven = "3.3.9" - val mavenResolver = "1.0.3" + val okhttp = "3.9.0" + val okio = "1.13.0" + val retrofit = "2.3.0" + val gson = "2.8.2" + val guice = "4.1.0" + val maven = "3.5.2" + val mavenResolver = "1.1.0" val slf4j = "1.7.3" val kotlin = "1.1.51" val aether = "1.0.2.v20150114" - val testng = "6.11" + val testng = "6.12" + val jcommander = "1.72" // JUnit 5 val junit = "4.12" @@ -97,34 +99,35 @@ val kobaltPluginApi = project { dependencies { compile( "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}", - "com.google.inject:guice:4.0", - "com.google.inject.extensions:guice-assistedinject:4.0", + "com.google.inject:guice:${Versions.guice}", + "com.google.inject.extensions:guice-assistedinject:4.1.0", "javax.inject:javax.inject:1", - "com.google.guava:guava:21.0", + "com.google.guava:guava:23.3-jre", "org.apache.maven:maven-model:${Versions.maven}", - "io.reactivex:rxjava:1.1.5", + "io.reactivex:rxjava:1.3.3", "com.squareup.okio:okio:${Versions.okio}", "com.google.code.gson:gson:${Versions.gson}", "com.squareup.okhttp3:okhttp:${Versions.okhttp}", "com.squareup.retrofit2:retrofit:${Versions.retrofit}", "com.squareup.retrofit2:converter-gson:${Versions.retrofit}", - "com.beust:jcommander:1.48", - "org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r", + "com.beust:jcommander:${Versions.jcommander}", + "org.eclipse.jgit:org.eclipse.jgit:4.9.0.201710071750-r", "org.slf4j:slf4j-simple:${Versions.slf4j}", *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), "org.apache.maven:maven-aether-provider:3.3.9", "org.testng.testng-remote:testng-remote:1.3.2", "org.testng:testng:${Versions.testng}", - "commons-io:commons-io:2.5", "org.junit.platform:junit-platform-surefire-provider:${Versions.junitPlatform}", "org.junit.platform:junit-platform-runner:${Versions.junitPlatform}", "org.junit.platform:junit-platform-engine:${Versions.junitPlatform}", "org.junit.platform:junit-platform-console:${Versions.junitPlatform}", "org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}", "org.junit.vintage:junit-vintage-engine:${Versions.junitVintageVersion}", + "org.apache.commons:commons-compress:1.15", + "commons-io:commons-io:2.6", - "org.apache.commons:commons-compress:1.13", - "commons-io:commons-io:2.5" + // Java 9 + "javax.xml.bind:jaxb-api:2.3.0" ) exclude(*aether("impl", "spi", "util", "api")) } @@ -161,24 +164,30 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { // Used by the main app compile( "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}", - "com.github.spullara.mustache.java:compiler:0.9.1", + "com.github.spullara.mustache.java:compiler:0.9.5", "javax.inject:javax.inject:1", - "com.google.inject:guice:4.0", - "com.google.inject.extensions:guice-assistedinject:4.0", - "com.beust:jcommander:1.65", + "com.google.inject:guice:${Versions.guice}", + "com.google.inject.extensions:guice-assistedinject:${Versions.guice}", + "com.beust:jcommander:${Versions.jcommander}", "org.apache.maven:maven-model:${Versions.maven}", - "com.google.code.findbugs:jsr305:3.0.1", + "com.google.code.findbugs:jsr305:3.0.2", "com.google.code.gson:gson:${Versions.gson}", "com.squareup.retrofit2:retrofit:${Versions.retrofit}", "com.squareup.retrofit2:converter-gson:${Versions.retrofit}", - "com.squareup.okhttp3:okhttp-ws:${Versions.okhttp}", + "com.squareup.okhttp3:okhttp-ws:3.4.2", "biz.aQute.bnd:bndlib:2.4.0", *mavenResolver("spi"), - "com.squareup.okhttp3:logging-interceptor:3.2.0", + "com.squareup.okhttp3:logging-interceptor:3.9.0", - "com.sparkjava:spark-core:2.5", - "org.codehaus.groovy:groovy:2.4.8" + "com.sparkjava:spark-core:2.6.0", + "org.codehaus.groovy:groovy:2.4.12", + + // Java 9 + "javax.xml.bind:jaxb-api:2.3.0", + "com.sun.xml.bind:jaxb-impl:2.3.0", + "com.sun.xml.bind:jaxb-core:2.3.0", + "com.sun.activation:javax.activation:1.2.0" // "org.eclipse.jetty:jetty-server:${Versions.jetty}", // "org.eclipse.jetty:jetty-servlet:${Versions.jetty}", @@ -194,7 +203,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { dependenciesTest { compile("org.jetbrains.kotlin:kotlin-test:${Versions.kotlin}", "org.testng:testng:${Versions.testng}", - "org.assertj:assertj-core:3.4.1", + "org.assertj:assertj-core:3.8.0", *mavenResolver("util") ) } diff --git a/kobaltw-test b/kobaltw-test new file mode 100755 index 00000000..2693c3aa --- /dev/null +++ b/kobaltw-test @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +JAR=$(ls -1 -t kobaltBuild/libs/*.jar | grep -Ev "(sources|javadoc)" | head -1) +TEMPDIR=$(mktemp -d) +cp -pf "$JAR" "$TEMPDIR" +TEMPJAR=$TEMPDIR/$(basename "$JAR") +export KOBALT_JAR=$TEMPJAR +java -jar "$TEMPJAR" "$@" +rm -rf "$TEMPDIR" \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt index 0c235181..b33286e0 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt @@ -86,12 +86,12 @@ class GithubApi2 @Inject constructor( .execute() val code = response.code() if (code != Http.CREATED) { - val error = Gson().fromJson(response.errorBody().string(), RetrofitError::class.java) + val error = Gson().fromJson(response.errorBody()?.string(), RetrofitError::class.java) throw KobaltException("Couldn't upload release, ${error.message}: " + error.errors[0].code) } else { val body = response.body() - uploadAsset(accessToken, body.uploadUrl!!, Http.TypedFile("application/zip", zipFile), tagName) + uploadAsset(accessToken, body?.uploadUrl!!, Http.TypedFile("application/zip", zipFile), tagName) .toBlocking() .forEach { action -> kobaltLog(1, "\n${zipFile.name} successfully uploaded") @@ -138,8 +138,8 @@ class GithubApi2 @Inject constructor( val releases = ex.body() if (releases != null) { releases.firstOrNull()?.let { - try { - result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() } + result = try { + listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() } } catch(ex: NoSuchElementException) { throw KobaltException("Couldn't find the latest release") } 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 a0fabe2a..1d37234a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -91,12 +91,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) } } @@ -113,7 +113,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, @@ -147,7 +147,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() parseCommandLineArguments(args2, args) @@ -227,7 +227,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" } @@ -253,24 +253,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?, @@ -384,8 +382,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 ?: "") } /** @@ -418,7 +415,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 d1e5c565..1a80ff0e 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() @@ -101,12 +101,12 @@ class BintrayApi @Inject constructor(val http: Http, val pkgName = config.name ?: project.name val execute = service.getPackage(org ?: username!!, pkgName).execute() - if (execute.errorBody()?.string()?.contains("'$pkgName' was not found") ?: false) { + if (execute.errorBody()?.string()?.contains("'$pkgName' was not found") == true) { warn("Package does not exist on bintray. Creating now.") val result = service.createPackage(org ?: username!!, buildPackageInfo(project, config)) .execute() if (result.errorBody() != null) { - throw KobaltException("Error while creating package:\n" + result.errorBody().string()) + throw KobaltException("Error while creating package:\n" + result.errorBody()!!.string()) } } } @@ -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() } } }