1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Revert "trying to retrofit BintrayApi and add package creation support"

This reverts commit 2c2cd8b16b.
This commit is contained in:
evanchooly 2016-04-16 16:43:38 -04:00
parent 124375d341
commit 92118a8c23
10 changed files with 54 additions and 87 deletions

12
.idea/libraries/KotlinJavaRuntime.xml generated Normal file
View file

@ -0,0 +1,12 @@
<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>

View file

@ -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/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!/" /> <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!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

2
.idea/misc.xml generated
View file

@ -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_8" 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_7" 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>

View file

@ -3,6 +3,7 @@
<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" />
@ -10,6 +11,7 @@
</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" />

View file

@ -2,8 +2,12 @@
<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>

View file

@ -132,9 +132,8 @@ 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"
) )

View file

@ -1,12 +1,13 @@
<?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="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <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="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>

View file

@ -1,12 +1,21 @@
<?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>

View file

@ -13,20 +13,8 @@ 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
@ -72,81 +60,21 @@ class BintrayApi @Inject constructor (
@Nullable @Assisted("org") org: String?) : BintrayApi @Nullable @Assisted("org") org: String?) : BintrayApi
} }
class ReleaseResponse(var id: String? = null, @SerializedName("upload_url") var uploadUrl: String?) fun packageExists(packageName: String) : Boolean {
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", project.name) "maven", packageName)
.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 (execute.errorBody()?.string()?.contains("was not found") ?: false) { if (jcResponse.errorMessage != null) {
warn("Package does not exist on bintray. Creating now.") throw KobaltException("Error from Bintray: ${jcResponse.errorMessage}")
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 == project.name return jcResponse.jo!!.get("name").asString == packageName
} }
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig?) : TaskResult { fun uploadMaven(project: Project, files: List<File>, 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" + 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")
} }

View file

@ -0,0 +1,12 @@
<?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>