mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Merge pull request #454 from ethauvin/master
Java 9 initial compatibility
This commit is contained in:
commit
e7ae50fe81
5 changed files with 81 additions and 71 deletions
|
@ -25,16 +25,18 @@ val bs = buildScript {
|
||||||
}
|
}
|
||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
val okhttp = "3.2.0"
|
val okhttp = "3.9.0"
|
||||||
val okio = "1.6.0"
|
val okio = "1.13.0"
|
||||||
val retrofit = "2.1.0"
|
val retrofit = "2.3.0"
|
||||||
val gson = "2.6.2"
|
val gson = "2.8.2"
|
||||||
val maven = "3.3.9"
|
val guice = "4.1.0"
|
||||||
val mavenResolver = "1.0.3"
|
val maven = "3.5.2"
|
||||||
|
val mavenResolver = "1.1.0"
|
||||||
val slf4j = "1.7.3"
|
val slf4j = "1.7.3"
|
||||||
val kotlin = "1.1.51"
|
val kotlin = "1.1.51"
|
||||||
val aether = "1.0.2.v20150114"
|
val aether = "1.0.2.v20150114"
|
||||||
val testng = "6.11"
|
val testng = "6.12"
|
||||||
|
val jcommander = "1.72"
|
||||||
|
|
||||||
// JUnit 5
|
// JUnit 5
|
||||||
val junit = "4.12"
|
val junit = "4.12"
|
||||||
|
@ -97,34 +99,35 @@ val kobaltPluginApi = project {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(
|
compile(
|
||||||
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
|
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
|
||||||
"com.google.inject:guice:4.0",
|
"com.google.inject:guice:${Versions.guice}",
|
||||||
"com.google.inject.extensions:guice-assistedinject:4.0",
|
"com.google.inject.extensions:guice-assistedinject:4.1.0",
|
||||||
"javax.inject:javax.inject:1",
|
"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}",
|
"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.squareup.okio:okio:${Versions.okio}",
|
||||||
"com.google.code.gson:gson:${Versions.gson}",
|
"com.google.code.gson:gson:${Versions.gson}",
|
||||||
"com.squareup.okhttp3:okhttp:${Versions.okhttp}",
|
"com.squareup.okhttp3:okhttp:${Versions.okhttp}",
|
||||||
"com.squareup.retrofit2:retrofit:${Versions.retrofit}",
|
"com.squareup.retrofit2:retrofit:${Versions.retrofit}",
|
||||||
"com.squareup.retrofit2:converter-gson:${Versions.retrofit}",
|
"com.squareup.retrofit2:converter-gson:${Versions.retrofit}",
|
||||||
"com.beust:jcommander:1.48",
|
"com.beust:jcommander:${Versions.jcommander}",
|
||||||
"org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r",
|
"org.eclipse.jgit:org.eclipse.jgit:4.9.0.201710071750-r",
|
||||||
"org.slf4j:slf4j-simple:${Versions.slf4j}",
|
"org.slf4j:slf4j-simple:${Versions.slf4j}",
|
||||||
*mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"),
|
*mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"),
|
||||||
"org.apache.maven:maven-aether-provider:3.3.9",
|
"org.apache.maven:maven-aether-provider:3.3.9",
|
||||||
"org.testng.testng-remote:testng-remote:1.3.2",
|
"org.testng.testng-remote:testng-remote:1.3.2",
|
||||||
"org.testng:testng:${Versions.testng}",
|
"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-surefire-provider:${Versions.junitPlatform}",
|
||||||
"org.junit.platform:junit-platform-runner:${Versions.junitPlatform}",
|
"org.junit.platform:junit-platform-runner:${Versions.junitPlatform}",
|
||||||
"org.junit.platform:junit-platform-engine:${Versions.junitPlatform}",
|
"org.junit.platform:junit-platform-engine:${Versions.junitPlatform}",
|
||||||
"org.junit.platform:junit-platform-console:${Versions.junitPlatform}",
|
"org.junit.platform:junit-platform-console:${Versions.junitPlatform}",
|
||||||
"org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}",
|
"org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}",
|
||||||
"org.junit.vintage:junit-vintage-engine:${Versions.junitVintageVersion}",
|
"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",
|
// Java 9
|
||||||
"commons-io:commons-io:2.5"
|
"javax.xml.bind:jaxb-api:2.3.0"
|
||||||
)
|
)
|
||||||
exclude(*aether("impl", "spi", "util", "api"))
|
exclude(*aether("impl", "spi", "util", "api"))
|
||||||
}
|
}
|
||||||
|
@ -161,24 +164,30 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
// Used by the main app
|
// Used by the main app
|
||||||
compile(
|
compile(
|
||||||
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
|
"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",
|
"javax.inject:javax.inject:1",
|
||||||
"com.google.inject:guice:4.0",
|
"com.google.inject:guice:${Versions.guice}",
|
||||||
"com.google.inject.extensions:guice-assistedinject:4.0",
|
"com.google.inject.extensions:guice-assistedinject:${Versions.guice}",
|
||||||
"com.beust:jcommander:1.65",
|
"com.beust:jcommander:${Versions.jcommander}",
|
||||||
"org.apache.maven:maven-model:${Versions.maven}",
|
"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.google.code.gson:gson:${Versions.gson}",
|
||||||
"com.squareup.retrofit2:retrofit:${Versions.retrofit}",
|
"com.squareup.retrofit2:retrofit:${Versions.retrofit}",
|
||||||
"com.squareup.retrofit2:converter-gson:${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",
|
"biz.aQute.bnd:bndlib:2.4.0",
|
||||||
*mavenResolver("spi"),
|
*mavenResolver("spi"),
|
||||||
|
|
||||||
"com.squareup.okhttp3:logging-interceptor:3.2.0",
|
"com.squareup.okhttp3:logging-interceptor:3.9.0",
|
||||||
|
|
||||||
"com.sparkjava:spark-core:2.5",
|
"com.sparkjava:spark-core:2.6.0",
|
||||||
"org.codehaus.groovy:groovy:2.4.8"
|
"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-server:${Versions.jetty}",
|
||||||
// "org.eclipse.jetty:jetty-servlet:${Versions.jetty}",
|
// "org.eclipse.jetty:jetty-servlet:${Versions.jetty}",
|
||||||
|
@ -194,7 +203,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
dependenciesTest {
|
dependenciesTest {
|
||||||
compile("org.jetbrains.kotlin:kotlin-test:${Versions.kotlin}",
|
compile("org.jetbrains.kotlin:kotlin-test:${Versions.kotlin}",
|
||||||
"org.testng:testng:${Versions.testng}",
|
"org.testng:testng:${Versions.testng}",
|
||||||
"org.assertj:assertj-core:3.4.1",
|
"org.assertj:assertj-core:3.8.0",
|
||||||
*mavenResolver("util")
|
*mavenResolver("util")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
8
kobaltw-test
Executable file
8
kobaltw-test
Executable 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"
|
|
@ -86,12 +86,12 @@ class GithubApi2 @Inject constructor(
|
||||||
.execute()
|
.execute()
|
||||||
val code = response.code()
|
val code = response.code()
|
||||||
if (code != Http.CREATED) {
|
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)
|
throw KobaltException("Couldn't upload release, ${error.message}: " + error.errors[0].code)
|
||||||
} else {
|
} else {
|
||||||
val body = response.body()
|
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()
|
.toBlocking()
|
||||||
.forEach { action ->
|
.forEach { action ->
|
||||||
kobaltLog(1, "\n${zipFile.name} successfully uploaded")
|
kobaltLog(1, "\n${zipFile.name} successfully uploaded")
|
||||||
|
@ -138,8 +138,8 @@ class GithubApi2 @Inject constructor(
|
||||||
val releases = ex.body()
|
val releases = ex.body()
|
||||||
if (releases != null) {
|
if (releases != null) {
|
||||||
releases.firstOrNull()?.let {
|
releases.firstOrNull()?.let {
|
||||||
try {
|
result = try {
|
||||||
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
||||||
} catch(ex: NoSuchElementException) {
|
} catch(ex: NoSuchElementException) {
|
||||||
throw KobaltException("Couldn't find the latest release")
|
throw KobaltException("Couldn't find the latest release")
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,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,
|
||||||
|
@ -147,7 +147,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()
|
||||||
parseCommandLineArguments(args2, args)
|
parseCommandLineArguments(args2, args)
|
||||||
|
@ -227,7 +227,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"
|
||||||
}
|
}
|
||||||
|
@ -253,24 +253,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?,
|
||||||
|
@ -384,8 +382,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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -418,7 +415,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)
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
@ -101,12 +101,12 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
val pkgName = config.name ?: project.name
|
val pkgName = config.name ?: project.name
|
||||||
val execute = service.getPackage(org ?: username!!, pkgName).execute()
|
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.")
|
warn("Package does not exist on bintray. Creating now.")
|
||||||
val result = service.createPackage(org ?: username!!, buildPackageInfo(project, config))
|
val result = service.createPackage(org ?: username!!, buildPackageInfo(project, config))
|
||||||
.execute()
|
.execute()
|
||||||
if (result.errorBody() != null) {
|
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 {
|
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue