diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 00000000..207fc74d --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/kobalt__Test_.xml b/.idea/libraries/kobalt__Test_.xml index a93b84bc..faf74539 100644 --- a/.idea/libraries/kobalt__Test_.xml +++ b/.idea/libraries/kobalt__Test_.xml @@ -1,9 +1,9 @@ - - + + diff --git a/.idea/misc.xml b/.idea/misc.xml index df7e8eb0..4079311b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/kobalt.iml b/kobalt.iml index 8fbec6cf..9510060e 100644 --- a/kobalt.iml +++ b/kobalt.iml @@ -3,6 +3,7 @@ + @@ -10,6 +11,7 @@ + diff --git a/kobalt/Build.kt.iml b/kobalt/Build.kt.iml index 62cf5e77..d3683da5 100644 --- a/kobalt/Build.kt.iml +++ b/kobalt/Build.kt.iml @@ -2,8 +2,12 @@ - + + + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index b790fe9f..2388fe60 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -132,9 +132,8 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { "com.google.code.findbugs:jsr305:3.0.1", "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}", "org.codehaus.plexus:plexus-utils:3.0.22", + "biz.aQute.bnd:bndlib:2.4.0" ) diff --git a/modules/kobalt-plugin-api/kobalt-plugin-api.iml b/modules/kobalt-plugin-api/kobalt-plugin-api.iml index 21255f15..64fabb37 100644 --- a/modules/kobalt-plugin-api/kobalt-plugin-api.iml +++ b/modules/kobalt-plugin-api/kobalt-plugin-api.iml @@ -1,12 +1,13 @@ - - + + + diff --git a/modules/wrapper/kobalt-wrapper.iml b/modules/wrapper/kobalt-wrapper.iml index 8cefc473..d31f73ee 100644 --- a/modules/wrapper/kobalt-wrapper.iml +++ b/modules/wrapper/kobalt-wrapper.iml @@ -1,12 +1,21 @@ - + + + + + + + + + + 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 7c1c42d1..cae618ed 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt @@ -13,20 +13,8 @@ import com.beust.kobalt.misc.warn import com.google.common.net.MediaType import com.google.gson.JsonObject import com.google.gson.JsonParser -import com.google.gson.annotations.SerializedName import com.google.inject.assistedinject.Assisted -import okhttp3.Credentials -import okhttp3.Interceptor -import okhttp3.OkHttpClient import okhttp3.Response -import retrofit2.Call -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.PATCH -import retrofit2.http.POST -import retrofit2.http.Path import java.io.File import javax.annotation.Nullable import javax.inject.Inject @@ -72,81 +60,21 @@ class BintrayApi @Inject constructor ( @Nullable @Assisted("org") org: String?) : BintrayApi } - class ReleaseResponse(var id: String? = null, @SerializedName("upload_url") var uploadUrl: String?) - - interface Api { - @GET("/packages/{owner}/maven/{package}") - fun getPackage(@Path("owner") owner: String, - @Path("package") name: String): Call - - @POST("/packages/{owner}/maven/{package}") - fun createPackage(@Path("owner") owner: String, - @Path("package") name: String, - @Body content: String): Call - -/* - @GET("/repos/{owner}/{repo}/releases") - fun getReleases(@Path("owner") owner: String, - @Path("repo") repo: String, - @Query("access_token") accessToken: String): Call> - - @GET("/repos/{owner}/{repo}/releases") - fun getReleasesNoAuth(@Path("owner") owner: String, - @Path("repo") repo: String): Call> -*/ - } - - private val service: Api - - init { - val builder = OkHttpClient.Builder() - builder.interceptors().add(Interceptor { chain -> - var original = chain.request(); - - var requestBuilder = original.newBuilder() - .header("Authorization", Credentials.basic(username, password)) - .header("Accept", "application/json") - .method(original.method(), original.body()); - - chain.proceed(requestBuilder.build()); - }) - val okHttpClient = builder.build() - - service = Retrofit.Builder() - .client(okHttpClient) - .baseUrl(UnauthenticatedBintrayApi.BINTRAY_URL_API) - .addConverterFactory(GsonConverterFactory.create()) - .build() - .create(Api::class.java) - } - - fun packageExists(project: Project) : Boolean { + fun packageExists(packageName: String) : Boolean { val url = arrayListOf(UnauthenticatedBintrayApi.BINTRAY_URL_API, "packages", org ?: username!!, - "maven", project.name) + "maven", packageName) .joinToString("/") val jcResponse = parseResponse(http.get(username, password, url)) - val execute = service.getPackage(org ?: username!!, project.name).execute() - if (execute.errorBody()?.string()?.contains("was not found") ?: false) { - warn("Package does not exist on bintray. Creating now.") - val content = mapOf( - "desc" to project.description, - "vcs_url" to (project.scm?.url ?: ""), - "licences" to """[ "Apache-2.0" ]""", - "website_url" to (project.url ?: "") - ).toString() - val result = service.createPackage(org ?: username!!, project.name, content).execute() - if (result.errorBody() != null) { - error(" Errors while creating package:\n" + result.errorBody().string()) - return false - } + if (jcResponse.errorMessage != null) { + throw KobaltException("Error from Bintray: ${jcResponse.errorMessage}") } - return jcResponse.jo!!.get("name").asString == project.name + return jcResponse.jo!!.get("name").asString == packageName } fun uploadMaven(project: Project, files: List, config: BintrayConfig?) : TaskResult { - if (! packageExists(project)) { + if (! packageExists(project.name)) { throw KobaltException("Couldn't find a package called ${project.name} on bintray, please create one first" + " as explained at https://bintray.com/docs/usermanual/uploads/uploads_creatinganewpackage.html") } diff --git a/src/main/resources/templates/idea/Build.kt.iml b/src/main/resources/templates/idea/Build.kt.iml new file mode 100644 index 00000000..dfa4c6b9 --- /dev/null +++ b/src/main/resources/templates/idea/Build.kt.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + +