mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
trying to retrofit BintrayApi and add package creation support
This commit is contained in:
parent
e95b9008ac
commit
2c2cd8b16b
10 changed files with 87 additions and 54 deletions
12
.idea/libraries/KotlinJavaRuntime.xml
generated
12
.idea/libraries/KotlinJavaRuntime.xml
generated
|
@ -1,12 +0,0 @@
|
||||||
<component name="libraryTable">
|
|
||||||
<library name="KotlinJavaRuntime">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-reflect.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
4
.idea/libraries/kobalt__Test_.xml
generated
4
.idea/libraries/kobalt__Test_.xml
generated
|
@ -1,9 +1,9 @@
|
||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="kobalt (Test)">
|
<library name="kobalt (Test)">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="jar://$USER_HOME$/.kobalt/repository/org/testng/testng/6.9.10/testng-6.9.10.jar!/" />
|
|
||||||
<root url="jar://$USER_HOME$/.kobalt/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar!/" />
|
|
||||||
<root url="jar://$USER_HOME$/.kobalt/repository/com/beust/jcommander/1.48/jcommander-1.48.jar!/" />
|
<root url="jar://$USER_HOME$/.kobalt/repository/com/beust/jcommander/1.48/jcommander-1.48.jar!/" />
|
||||||
|
<root url="jar://$USER_HOME$/.kobalt/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar!/" />
|
||||||
|
<root url="jar://$USER_HOME$/.kobalt/repository/org/testng/testng/6.9.10/testng-6.9.10.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES />
|
<SOURCES />
|
||||||
|
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -3,7 +3,7 @@
|
||||||
<component name="EntryPointsManager">
|
<component name="EntryPointsManager">
|
||||||
<entry_points version="2.0" />
|
<entry_points version="2.0" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -3,7 +3,6 @@
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
@ -11,7 +10,6 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
<orderEntry type="library" name="kobalt (Compile)" level="project" />
|
<orderEntry type="library" name="kobalt (Compile)" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="kobalt (Test)" level="project" />
|
<orderEntry type="library" scope="TEST" name="kobalt (Test)" level="project" />
|
||||||
<orderEntry type="module" module-name="kobalt-plugin-api" />
|
<orderEntry type="module" module-name="kobalt-plugin-api" />
|
||||||
|
|
|
@ -2,12 +2,8 @@
|
||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
<orderEntry type="library" name="kobalt.jar" level="project" />
|
<orderEntry type="library" name="kobalt.jar" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -132,8 +132,9 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
"com.google.code.findbugs:jsr305:3.0.1",
|
"com.google.code.findbugs:jsr305:3.0.1",
|
||||||
"com.google.code.gson:gson:${Versions.gson}",
|
"com.google.code.gson:gson:${Versions.gson}",
|
||||||
"com.squareup.okhttp3:okhttp:${Versions.okhttp}",
|
"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",
|
"org.codehaus.plexus:plexus-utils:3.0.22",
|
||||||
|
|
||||||
"biz.aQute.bnd:bndlib:2.4.0"
|
"biz.aQute.bnd:bndlib:2.4.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="kobalt (Compile)" level="project" />
|
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="kobalt-plugin-api (Compile)" level="project" />
|
<orderEntry type="library" name="kobalt-plugin-api (Compile)" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="kobalt-plugin-api (Test)" level="project" />
|
<orderEntry type="library" scope="TEST" name="kobalt-plugin-api (Test)" level="project" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
<orderEntry type="module-library">
|
|
||||||
<library>
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MODULE_DIR$/../../../kobalt-android/kobaltBuild/libs/kobalt-android-0.43.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
<orderEntry type="library" name="kobalt-wrapper (Compile)" level="project" />
|
<orderEntry type="library" name="kobalt-wrapper (Compile)" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="kobalt-wrapper (Test)" level="project" />
|
<orderEntry type="library" scope="TEST" name="kobalt-wrapper (Test)" level="project" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -13,8 +13,20 @@ import com.beust.kobalt.misc.warn
|
||||||
import com.google.common.net.MediaType
|
import com.google.common.net.MediaType
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
import com.google.inject.assistedinject.Assisted
|
import com.google.inject.assistedinject.Assisted
|
||||||
|
import okhttp3.Credentials
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Response
|
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 java.io.File
|
||||||
import javax.annotation.Nullable
|
import javax.annotation.Nullable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -60,21 +72,81 @@ class BintrayApi @Inject constructor (
|
||||||
@Nullable @Assisted("org") org: String?) : BintrayApi
|
@Nullable @Assisted("org") org: String?) : BintrayApi
|
||||||
}
|
}
|
||||||
|
|
||||||
fun packageExists(packageName: String) : Boolean {
|
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<BintrayResponse>
|
||||||
|
|
||||||
|
@POST("/packages/{owner}/maven/{package}")
|
||||||
|
fun createPackage(@Path("owner") owner: String,
|
||||||
|
@Path("package") name: String,
|
||||||
|
@Body content: String): Call<BintrayResponse>
|
||||||
|
|
||||||
|
/*
|
||||||
|
@GET("/repos/{owner}/{repo}/releases")
|
||||||
|
fun getReleases(@Path("owner") owner: String,
|
||||||
|
@Path("repo") repo: String,
|
||||||
|
@Query("access_token") accessToken: String): Call<List<ReleasesResponse>>
|
||||||
|
|
||||||
|
@GET("/repos/{owner}/{repo}/releases")
|
||||||
|
fun getReleasesNoAuth(@Path("owner") owner: String,
|
||||||
|
@Path("repo") repo: String): Call<List<ReleasesResponse>>
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
val url = arrayListOf(UnauthenticatedBintrayApi.BINTRAY_URL_API, "packages", org ?: username!!,
|
val url = arrayListOf(UnauthenticatedBintrayApi.BINTRAY_URL_API, "packages", org ?: username!!,
|
||||||
"maven", packageName)
|
"maven", project.name)
|
||||||
.joinToString("/")
|
.joinToString("/")
|
||||||
val jcResponse = parseResponse(http.get(username, password, url))
|
val jcResponse = parseResponse(http.get(username, password, url))
|
||||||
|
val execute = service.getPackage(org ?: username!!, project.name).execute()
|
||||||
|
|
||||||
if (jcResponse.errorMessage != null) {
|
if (execute.errorBody()?.string()?.contains("was not found") ?: false) {
|
||||||
throw KobaltException("Error from Bintray: ${jcResponse.errorMessage}")
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return jcResponse.jo!!.get("name").asString == packageName
|
return jcResponse.jo!!.get("name").asString == project.name
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig?) : TaskResult {
|
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig?) : TaskResult {
|
||||||
if (! packageExists(project.name)) {
|
if (! packageExists(project)) {
|
||||||
throw KobaltException("Couldn't find a package called ${project.name} on bintray, please create one first" +
|
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")
|
" as explained at https://bintray.com/docs/usermanual/uploads/uploads_creatinganewpackage.html")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="kobalt.jar" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
Loading…
Add table
Add a link
Reference in a new issue