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 1b5de7bd..7793a77d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt @@ -61,6 +61,14 @@ class BintrayApi @Inject constructor(val http: Http, @Path("name") name: String, @Path("publish") publish: Int, @Body file: File): Call + + class UpdateVersion(val desc: String?, val vcsTag: String?) + + @PATCH("/packages/{owner}/maven/{repo}/versions/{version}") + fun updateVersion(@Path("owner") owner: String, + @Path("repo") repo: String, + @Path("version") version: String, + @Body content: UpdateVersion): Call } private val service: Api @@ -155,13 +163,13 @@ class BintrayApi @Inject constructor(val http: Http, } val results = arrayListOf() - filesToUpload.forEachIndexed { i, file -> - val owner = org ?: username!! - val repo = project.name - val group = project.group!!.replace('.', '/') - val artifact = project.artifactId!! - val version = project.version!! + val owner = org ?: username!! + val repo = project.name + val group = project.group!!.replace('.', '/') + val artifact = project.artifactId!! + val version = project.version!! + filesToUpload.forEachIndexed { i, file -> val result = service.uploadArtifact(owner, repo, group, artifact, version, file.name, if (config.publish) 1 else 0, file) .execute() @@ -181,6 +189,18 @@ class BintrayApi @Inject constructor(val http: Http, logger.log(project.name, 1, " Uploaded $success / $fileCount " + dots(fileCount, results), false) logger.log(project.name, 1, "", true) if (errorMessages.isEmpty()) { + if (config.description != null || config.vcsTag != null) { + // + // Update the version if the user specified some additional version information + // + val versionUpdateResult = service.updateVersion(owner, repo, version, + Api.UpdateVersion(config.description, config.vcsTag)) + .execute() + if (!versionUpdateResult.isSuccessful) { + warn("Couldn't update the version description: " + versionUpdateResult.errorBody()) + } + } + return TaskResult() } else { error(" Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n")) @@ -203,13 +223,18 @@ class BintrayApi @Inject constructor(val http: Http, } class ConverterFactory : Converter.Factory() { - override fun responseBodyConverter(type: Type, annotations: Array, retrofit: Retrofit): Converter? { + override fun responseBodyConverter(type: Type, annotations: Array, + retrofit: Retrofit): Converter? { return GsonResponseBodyConverter(Gson(), Gson().getAdapter(TypeToken.get(type))) } - override fun requestBodyConverter(type: Type, parameterAnnotations: Array, methodAnnotations: Array, - retrofit: Retrofit?): Converter<*, RequestBody>? { - return RequestBodyConverter() + 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 } } @@ -224,8 +249,15 @@ class GsonResponseBodyConverter(private val gson: Gson, private val adapter: Typ } } -class RequestBodyConverter : Converter { +class FileBodyConverter : Converter { override fun convert(value: File): RequestBody { return CountingFileRequestBody(value, "application/*", { }) } -} \ No newline at end of file +} + +class GsonBodyConverter : Converter { + override fun convert(value: Any): RequestBody { + val jo = Gson().toJson(value) + return RequestBody.create(MediaType.parse("application/json"), jo.toString()) + } +} diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 9ffea810..56883401 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -241,6 +241,12 @@ data class BintrayConfig(val project: Project) { fun file(filePath: String, url: String) { files.add(Pair(filePath, url)) } + + @Directive + var description: String? = null + + @Directive + var vcsTag: String? = null } @Directive