mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Remove okhttp 2 dependency.
This commit is contained in:
parent
2bb75f1006
commit
27a613c8bb
8 changed files with 9 additions and 168 deletions
2
.idea/libraries/kobalt__Compile_.xml
generated
2
.idea/libraries/kobalt__Compile_.xml
generated
|
@ -12,10 +12,10 @@
|
|||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/github/spullara/mustache/java/compiler/0.9.1/compiler-0.9.1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.0.0/kotlin-compiler-embeddable-1.0.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/squareup/okhttp/okhttp/2.5.0/okhttp-2.5.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/guava/guava/20.0-SNAPSHOT/guava-20.0-SNAPSHOT.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/inject/guice/4.0/guice-4.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/squareup/okhttp3/okhttp/3.2.0/okhttp-3.2.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
|
1
.idea/libraries/kobalt_plugin_api__Compile_.xml
generated
1
.idea/libraries/kobalt_plugin_api__Compile_.xml
generated
|
@ -14,7 +14,6 @@
|
|||
<root url="jar://$USER_HOME$/.kobalt/repository/io/reactivex/rxjava/1.0.16/rxjava-1.0.16.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/squareup/retrofit2/converter-gson/2.0.0-beta4/converter-gson-2.0.0-beta4.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/squareup/okhttp/okhttp/2.5.0/okhttp-2.5.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/guava/guava/20.0-SNAPSHOT/guava-20.0-SNAPSHOT.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/google/inject/guice/4.0/guice-4.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/squareup/okhttp3/okhttp/3.2.0/okhttp-3.2.0.jar!/" />
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<RetrofitErrorResponse>)
|
||||
|
||||
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<UploadAssetResponse> {
|
||||
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<CreateReleaseResponse>
|
||||
|
||||
@GET("/repos/{owner}/{repo}/releases")
|
||||
fun getReleases(@Path("owner") owner: String,
|
||||
@Query("access_token") accessToken: String,
|
||||
@Path("repo") repo: String): List<ReleasesResponse>
|
||||
|
||||
@GET("/repos/{owner}/{repo}/releases")
|
||||
fun getReleasesNoAuth(@Path("owner") owner: String,
|
||||
@Path("repo") repo: String): List<ReleasesResponse>
|
||||
}
|
||||
|
||||
val latestKobaltVersion: Future<String>
|
||||
get() {
|
||||
val callable = Callable<String> {
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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<String> {
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue