diff --git a/.idea/libraries/kobalt__Compile_.xml b/.idea/libraries/kobalt__Compile_.xml
index f8a31249..3bdcbd12 100644
--- a/.idea/libraries/kobalt__Compile_.xml
+++ b/.idea/libraries/kobalt__Compile_.xml
@@ -12,10 +12,10 @@
-
+
diff --git a/.idea/libraries/kobalt_plugin_api__Compile_.xml b/.idea/libraries/kobalt_plugin_api__Compile_.xml
index 50404fdc..e4d02488 100644
--- a/.idea/libraries/kobalt_plugin_api__Compile_.xml
+++ b/.idea/libraries/kobalt_plugin_api__Compile_.xml
@@ -14,7 +14,6 @@
-
diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt
index a7d19ad6..bcc48039 100644
--- a/kobalt/src/Build.kt
+++ b/kobalt/src/Build.kt
@@ -62,7 +62,6 @@ val kobaltPluginApi = project {
dependencies {
compile("org.jetbrains.kotlinx:kotlinx.dom:0.0.9",
- "com.squareup.okhttp:okhttp:2.5.0",
"com.squareup.okio:okio:1.6.0",
"com.google.inject:guice:4.0",
"com.google.inject.extensions:guice-assistedinject:4.0",
@@ -114,7 +113,6 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
// Used by the main app
compile("com.github.spullara.mustache.java:compiler:0.9.1",
- "com.squareup.okhttp:okhttp:2.5.0",
"javax.inject:javax.inject:1",
"com.google.inject:guice:4.0",
"com.google.inject.extensions:guice-assistedinject:4.0",
diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt
index 9ef93929..db97b075 100644
--- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt
+++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt
@@ -3,7 +3,7 @@ package com.beust.kobalt.maven
import com.beust.kobalt.KobaltException
import com.beust.kobalt.misc.CountingFileRequestBody
import com.beust.kobalt.misc.log
-import com.squareup.okhttp.*
+import okhttp3.*
import retrofit.mime.TypedFile
import java.io.IOException
import javax.inject.Singleton
@@ -11,7 +11,7 @@ import javax.inject.Singleton
@Singleton
class Http {
fun get(user: String?, password: String?, url: String) : Response {
- val client = OkHttpClient();
+ val client = OkHttpClient()
val request = Request.Builder().url(url)
if (user != null) {
request.header("Authorization", Credentials.basic(user, password))
diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt
index 72e45a7c..b9dc6d8a 100644
--- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt
+++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt
@@ -1,7 +1,7 @@
package com.beust.kobalt.misc
-import com.squareup.okhttp.MediaType
-import com.squareup.okhttp.RequestBody
+import okhttp3.MediaType
+import okhttp3.RequestBody
import okio.BufferedSink
import okio.Okio
import java.io.File
diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt
deleted file mode 100644
index 5a81a0b7..00000000
--- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt
+++ /dev/null
@@ -1,155 +0,0 @@
-package com.beust.kobalt.misc
-
-import com.beust.kobalt.KobaltException
-import com.beust.kobalt.internal.DocUrl
-import com.beust.kobalt.maven.Http
-import com.google.gson.Gson
-import com.google.gson.annotations.SerializedName
-import com.squareup.okhttp.Headers
-import com.squareup.okhttp.OkHttpClient
-import retrofit.RestAdapter
-import retrofit.RetrofitError
-import retrofit.client.OkClient
-import retrofit.http.*
-import retrofit.mime.TypedByteArray
-import retrofit.mime.TypedFile
-import rx.Observable
-import java.io.File
-import java.util.*
-import java.util.concurrent.Callable
-import java.util.concurrent.Future
-import javax.inject.Inject
-
-/**
- * Retrieve Kobalt's latest release version from github.
- */
-class GithubApiOld @Inject constructor(val executors: KobaltExecutors,
- val localProperties: LocalProperties, val http: Http) {
- companion object {
- const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
- const val PROPERTY_USERNAME = "github.username"
- }
-
- class RetrofitErrorResponse(val code: String?, val field: String?)
- class RetrofitErrorsResponse(val message: String?, val errors: List)
-
- private val DOC_URL = DocUrl.PUBLISH_PLUGIN_URL
-
- private fun parseRetrofitError(e: Throwable) : RetrofitErrorsResponse {
- val re = e as RetrofitError
- val json = String((re.response?.body as TypedByteArray).bytes)
- return Gson().fromJson(json, RetrofitErrorsResponse::class.java)
- }
-
- fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
- log(1, "Uploading release ${zipFile.name}")
-
- val username = localProperties.get(PROPERTY_USERNAME, DOC_URL)
- val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, DOC_URL)
- try {
- service.createRelease(username, accessToken, packageName, CreateRelease(tagName))
- .flatMap { response ->
- uploadAsset(accessToken, response.uploadUrl!!, TypedFile("application/zip", zipFile),
- tagName)
- }
- .toBlocking()
- .forEach { action ->
- log(1, "\n${zipFile.name} successfully uploaded")
- }
- } catch(e: RetrofitError) {
- val error = parseRetrofitError(e)
- throw KobaltException("Couldn't upload release, ${error.message}: "
- + error.errors[0].code + " field: " + error.errors[0].field)
- }
- }
-
- private fun uploadAsset(token: String, uploadUrl: String, typedFile: TypedFile, tagName: String)
- : Observable {
- val strippedUrl = uploadUrl.substring(0, uploadUrl.indexOf("{"))
- val fileName = typedFile.file().name
- val url = "$strippedUrl?name=$fileName&label=$fileName"
- val headers = Headers.of("Authorization", "token $token")
- val totalSize = typedFile.file().length()
- http.uploadFile(url = url, file = typedFile, headers = headers, post = true, // Github requires POST
- progressCallback = http.percentProgressCallback(totalSize))
-
- return Observable.just(UploadAssetResponse(tagName, tagName))
- }
-
- //
- // Read only Api
- //
-
- private val service = RestAdapter.Builder()
-// .setLogLevel(RestAdapter.LogLevel.FULL)
- .setClient(OkClient(OkHttpClient()))
- .setEndpoint("https://api.github.com")
- .build()
- .create(Api::class.java)
-
- //
- // JSON mapped classes that get sent up and down
- //
- class CreateRelease(@SerializedName("tag_name") var tagName: String? = null,
- var name: String? = tagName)
- class CreateReleaseResponse(var id: String? = null, @SerializedName("upload_url") var uploadUrl: String?)
- class UploadAssetResponse(var id: String? = null, val name: String? = null)
- class ReleasesResponse(@SerializedName("tag_name") var tagName: String? = null,
- var name: String? = tagName)
-
- interface Api {
- @POST("/repos/{owner}/{repo}/releases")
- fun createRelease(@Path("owner") owner: String,
- @Query("access_token") accessToken: String,
- @Path("repo") repo: String,
- @Body createRelease: CreateRelease): Observable
-
- @GET("/repos/{owner}/{repo}/releases")
- fun getReleases(@Path("owner") owner: String,
- @Query("access_token") accessToken: String,
- @Path("repo") repo: String): List
-
- @GET("/repos/{owner}/{repo}/releases")
- fun getReleasesNoAuth(@Path("owner") owner: String,
- @Path("repo") repo: String): List
- }
-
- val latestKobaltVersion: Future
- get() {
- val callable = Callable {
- var result = "0"
-
- val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
- val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
- try {
- val releases =
- if (username != null && accessToken != null) {
- service.getReleases(username, accessToken, "kobalt")
- } else {
- service.getReleasesNoAuth("cbeust", "kobalt")
- }
- releases.firstOrNull()?.let {
- try {
- result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
- } catch(ex: NoSuchElementException) {
- throw KobaltException("Couldn't find the latest release")
- }
- }
- } catch(e: RetrofitError) {
- val error = parseRetrofitError(e)
- val details = if (error.errors != null) {
- error.errors[0]
- } else {
- null
- }
- // TODO: If the credentials didn't work ("bad credentials"), should start again
- // using cbeust/kobalt, like above. Right now, just bailing.
- log(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
- + details?.code + " field: " + details?.field)
- }
- result
- }
-
- return executors.miscExecutor.submit(callable)
- }
-}
diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt
index 74cfb335..836d680b 100644
--- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt
+++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt
@@ -5,7 +5,6 @@ import com.beust.kobalt.internal.DocUrl
import com.beust.kobalt.maven.Http
import com.google.gson.annotations.SerializedName
import com.google.inject.Inject
-import com.squareup.okhttp.Headers
import retrofit.RetrofitError
import retrofit.mime.TypedFile
import retrofit2.Call
@@ -93,7 +92,7 @@ class GithubApi2 @Inject constructor(
val strippedUrl = uploadUrl.substring(0, uploadUrl.indexOf("{"))
val fileName = typedFile.file().name
val url = "$strippedUrl?name=$fileName&label=$fileName"
- val headers = Headers.of("Authorization", "token $token")
+ val headers = okhttp3.Headers.of("Authorization", "token $token")
val totalSize = typedFile.file().length()
http.uploadFile(url = url, file = typedFile, headers = headers, post = true, // Github requires POST
progressCallback = http.percentProgressCallback(totalSize))
@@ -106,8 +105,8 @@ class GithubApi2 @Inject constructor(
val callable = Callable {
var result = "0"
- val username = localProperties.getNoThrows(GithubApiOld.PROPERTY_USERNAME, DOC_URL)
- val accessToken = localProperties.getNoThrows(GithubApiOld.PROPERTY_ACCESS_TOKEN, DOC_URL)
+ val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
+ val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
try {
val req =
if (username != null && accessToken != null) {
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 fa9f7e85..bae55b8d 100644
--- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt
+++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt
@@ -14,7 +14,7 @@ import com.google.common.net.MediaType
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.google.inject.assistedinject.Assisted
-import com.squareup.okhttp.Response
+import okhttp3.Response
import retrofit.mime.TypedFile
import java.io.File
import javax.annotation.Nullable