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

Merge branch 'master' of github.com:cbeust/kobalt

This commit is contained in:
Marcus Fihlon 2017-11-06 19:51:32 +01:00
commit 70f01fa691
No known key found for this signature in database
GPG key ID: C6B7F469EE363E1F
5 changed files with 81 additions and 71 deletions

View file

@ -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")
)
}

8
kobaltw-test Executable file
View file

@ -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"

View file

@ -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")
}

View file

@ -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<String>())
(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<String>, 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<IClasspathDependency> {
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<String>()
emptyList()
}
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args,
friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess)

View file

@ -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<Boolean>, 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<out Annotation>,
methodAnnotations: Array<out Annotation>,
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<out Any>) : Converter<ResponseBody, Any> {
override fun convert(value: ResponseBody): Any {
val jsonReader = gson.newJsonReader(value.charStream())
try {
value.use {
return adapter.read(jsonReader)
} finally {
value.close()
}
}
}