From 1636d4f4ebdca4604e36be7c6120a9a1cd35e771 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 6 Jan 2016 01:43:39 +0400 Subject: [PATCH] Simplify the publish org/username logic. --- .../beust/kobalt/plugin/publish/JCenterApi.kt | 17 ++++++++--------- .../kobalt/plugin/publish/PublishPlugin.kt | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/JCenterApi.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/JCenterApi.kt index e562fa69..d1c4d639 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/JCenterApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/JCenterApi.kt @@ -52,18 +52,17 @@ open public class UnauthenticatedJCenterApi @Inject constructor(open val http: H // } } -public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val username: String?, - @Nullable @Assisted("password") val password: String?, @Nullable @Assisted("org") val org: String?, +public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val username: String, + @Nullable @Assisted("password") val password: String, override val http: Http, val gpg: Gpg, val executors: KobaltExecutors) : UnauthenticatedJCenterApi(http) { interface IFactory { - fun create(@Nullable @Assisted("username") username: String?, - @Nullable @Assisted("password") password: String?, - @Nullable @Assisted("org") org: String?) : JCenterApi + fun create(@Nullable @Assisted("username") username: String, + @Nullable @Assisted("password") password: String) : JCenterApi } fun packageExists(packageName: String) : Boolean { - val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", org ?: username!!, "maven", packageName) + val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", username, "maven", packageName) .joinToString("/") val jcResponse = parseResponse(http.get(username, password, url)) @@ -91,7 +90,7 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val val fileToPath: (File) -> String = { f: File -> arrayListOf( UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT, - org ?: username!!, + username, "maven", project.name, project.version!!, @@ -108,7 +107,7 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val fun uploadFile(file: File, url: String, config: JCenterConfig, generateMd5: Boolean = false, generateAsc: Boolean = false) = upload(arrayListOf(file), config, { - f: File -> "${UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT}/${org ?: username}/generic/$url"}, + f: File -> "${UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT}/$username/generic/$url"}, generateMd5, generateAsc) private fun upload(files: List, config: JCenterConfig?, fileToPath: (File) -> String, @@ -148,7 +147,7 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val // val fileCount = filesToUpload.size if (fileCount > 0) { - log(1, " Found $fileCount artifacts to upload: " + filesToUpload.get(0) + log(1, " Found $fileCount artifacts to upload: " + filesToUpload[0] + if (fileCount > 1) "..." else "") var i = 1 val errorMessages = arrayListOf() 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 91dbbfc3..d5f2f019 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -91,9 +91,9 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P val docUrl = DocUrl.PUBLISH_PLUGIN_URL val user = localProperties.get(PROPERTY_BINTRAY_USER, docUrl) val password = localProperties.get(PROPERTY_BINTRAY_PASSWORD, docUrl) - val org = localProperties.get(PROPERTY_BINTRAY_ORG, docUrl) + val org = localProperties.getNoThrows(PROPERTY_BINTRAY_ORG, docUrl) - val jcenter = jcenterFactory.create(user, password, org) + val jcenter = jcenterFactory.create(org ?: user, password) var success = false val configuration = jcenterConfigurations[project.name] val messages = arrayListOf()