mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
commit
2227783905
2 changed files with 26 additions and 12 deletions
|
@ -15,6 +15,7 @@ import com.google.gson.Gson
|
||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.TypeAdapter
|
import com.google.gson.TypeAdapter
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.google.inject.assistedinject.Assisted
|
import com.google.inject.assistedinject.Assisted
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
|
@ -62,7 +63,7 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
@Path("publish") publish: Int,
|
@Path("publish") publish: Int,
|
||||||
@Body file: File): Call<BintrayResponse>
|
@Body file: File): Call<BintrayResponse>
|
||||||
|
|
||||||
class UpdateVersion(val desc: String?, val vcsTag: String?)
|
class UpdateVersion(val desc: String?, @SerializedName("vcs_tag") val vcsTag: String?)
|
||||||
|
|
||||||
@PATCH("/packages/{owner}/maven/{repo}/versions/{version}")
|
@PATCH("/packages/{owner}/maven/{repo}/versions/{version}")
|
||||||
fun updateVersion(@Path("owner") owner: String,
|
fun updateVersion(@Path("owner") owner: String,
|
||||||
|
@ -96,12 +97,13 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
.create(Api::class.java)
|
.create(Api::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validatePackage(project: Project) {
|
fun validatePackage(project: Project, config: BintrayConfig) {
|
||||||
val execute = service.getPackage(org ?: username!!, project.name).execute()
|
val pkgName = config.name ?: project.name
|
||||||
|
val execute = service.getPackage(org ?: username!!, pkgName).execute()
|
||||||
|
|
||||||
if (execute.errorBody()?.string()?.contains("'${project.name}' was not found") ?: false) {
|
if (execute.errorBody()?.string()?.contains("'$pkgName' was not found") ?: false) {
|
||||||
warn("Package does not exist on bintray. Creating now.")
|
warn("Package does not exist on bintray. Creating now.")
|
||||||
val result = service.createPackage(org ?: username!!, buildPackageInfo(project))
|
val result = service.createPackage(org ?: username!!, buildPackageInfo(project, config))
|
||||||
.execute()
|
.execute()
|
||||||
if (result.errorBody() != null) {
|
if (result.errorBody() != null) {
|
||||||
throw KobaltException("Error while creating package:\n" + result.errorBody().string())
|
throw KobaltException("Error while creating package:\n" + result.errorBody().string())
|
||||||
|
@ -109,12 +111,15 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildPackageInfo(project: Project): JsonObject {
|
private fun buildPackageInfo(project: Project, config: BintrayConfig): JsonObject {
|
||||||
val jsonObject = JsonObject()
|
val jsonObject = JsonObject().apply {
|
||||||
jsonObject.addNonNull("name", project.name)
|
addNonNull("name", config.name ?: project.name)
|
||||||
jsonObject.addNonNull("desc", project.description)
|
addNonNull("desc",
|
||||||
jsonObject.addNonNull("vcs_url", project.pom?.scm?.url)
|
if (project.description.isNotBlank()) project.description else project.pom?.description)
|
||||||
jsonObject.addNonNull("website_url", project.url)
|
addNonNull("vcs_url", project.pom?.scm?.url)
|
||||||
|
addNonNull("website_url", project.url ?: project.pom?.url)
|
||||||
|
addNonNull("issue_tracker_url", config.issueTrackerUrl)
|
||||||
|
}
|
||||||
val licenses = JsonArray()
|
val licenses = JsonArray()
|
||||||
project.pom?.licenses?.forEach {
|
project.pom?.licenses?.forEach {
|
||||||
licenses.add(it.name)
|
licenses.add(it.name)
|
||||||
|
@ -124,7 +129,7 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig): TaskResult {
|
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig): TaskResult {
|
||||||
validatePackage(project)
|
validatePackage(project, config)
|
||||||
return upload(project, files, config, generateMd5 = true)
|
return upload(project, files, config, generateMd5 = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,9 +268,18 @@ data class BintrayConfig(val project: Project) {
|
||||||
files.add(Pair(filePath, url))
|
files.add(Pair(filePath, url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The package name on Bintray which is not always the project name.
|
||||||
|
*/
|
||||||
|
@Directive
|
||||||
|
var name: String? = null
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
var description: String? = null
|
var description: String? = null
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
var issueTrackerUrl: String? = null
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
var vcsTag: String? = null
|
var vcsTag: String? = null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue