mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Rename JCenter -> Bintray.
This commit is contained in:
parent
2253b06965
commit
9b5d923bcc
4 changed files with 67 additions and 81 deletions
|
@ -12,7 +12,7 @@ import com.beust.kobalt.plugin.kotlin.kotlinCompiler
|
||||||
import com.beust.kobalt.plugin.kotlin.kotlinProject
|
import com.beust.kobalt.plugin.kotlin.kotlinProject
|
||||||
import com.beust.kobalt.plugin.packaging.assemble
|
import com.beust.kobalt.plugin.packaging.assemble
|
||||||
import com.beust.kobalt.plugin.publish.github
|
import com.beust.kobalt.plugin.publish.github
|
||||||
import com.beust.kobalt.plugin.publish.jcenter
|
import com.beust.kobalt.plugin.publish.bintray
|
||||||
import com.beust.kobalt.repos
|
import com.beust.kobalt.repos
|
||||||
import com.beust.kobalt.test
|
import com.beust.kobalt.test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -98,7 +98,7 @@ val kobaltPluginApi = kotlinProject {
|
||||||
args("-nowarn")
|
args("-nowarn")
|
||||||
}
|
}
|
||||||
|
|
||||||
jcenter {
|
bintray {
|
||||||
publish = true
|
publish = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ val kobaltApp = kotlinProject(kobaltPluginApi, wrapper) {
|
||||||
args("-nowarn")
|
args("-nowarn")
|
||||||
}
|
}
|
||||||
|
|
||||||
jcenter {
|
bintray {
|
||||||
publish = true
|
publish = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.beust.kobalt.maven.Pom
|
||||||
import com.beust.kobalt.maven.PomGenerator
|
import com.beust.kobalt.maven.PomGenerator
|
||||||
import com.beust.kobalt.misc.DependencyExecutor
|
import com.beust.kobalt.misc.DependencyExecutor
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.plugin.publish.JCenterApi
|
import com.beust.kobalt.plugin.publish.BintrayApi
|
||||||
import com.google.inject.AbstractModule
|
import com.google.inject.AbstractModule
|
||||||
import com.google.inject.Provider
|
import com.google.inject.Provider
|
||||||
import com.google.inject.Singleton
|
import com.google.inject.Singleton
|
||||||
|
@ -24,11 +24,12 @@ public open class MainModule(val args: Args) : AbstractModule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configure() {
|
override fun configure() {
|
||||||
|
|
||||||
configureTest()
|
configureTest()
|
||||||
val builder = FactoryModuleBuilder()
|
val builder = FactoryModuleBuilder()
|
||||||
arrayListOf(
|
arrayListOf(
|
||||||
PomGenerator.IFactory::class.java,
|
PomGenerator.IFactory::class.java,
|
||||||
JCenterApi.IFactory::class.java,
|
BintrayApi.IFactory::class.java,
|
||||||
Pom.IFactory::class.java,
|
Pom.IFactory::class.java,
|
||||||
BuildFileCompiler.IFactory::class.java,
|
BuildFileCompiler.IFactory::class.java,
|
||||||
ArtifactFetcher.IFactory::class.java)
|
ArtifactFetcher.IFactory::class.java)
|
||||||
|
|
|
@ -20,72 +20,57 @@ import java.io.File
|
||||||
import javax.annotation.Nullable
|
import javax.annotation.Nullable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
data class JCenterPackage(val jo: JsonObject) {
|
data class BintrayPackage(val jo: JsonObject) {
|
||||||
// @Suppress("UNCHECKED_CAST")
|
// @Suppress("UNCHECKED_CAST")
|
||||||
// val latestPublishedVersion = (jo.get("versions") as JsonArray).get(0) as JsonObject).
|
// val latestPublishedVersion = (jo.get("versions") as JsonArray).get(0) as JsonObject).
|
||||||
}
|
}
|
||||||
|
|
||||||
open public class UnauthenticatedJCenterApi @Inject constructor(open val http: Http){
|
open public class UnauthenticatedBintrayApi @Inject constructor(open val http: Http) {
|
||||||
companion object {
|
companion object {
|
||||||
const val BINTRAY_URL_API = "https://api.bintray.com"
|
const val BINTRAY_URL_API = "https://api.bintray.com"
|
||||||
const val BINTRAY_URL_API_CONTENT = BINTRAY_URL_API + "/content"
|
const val BINTRAY_URL_API_CONTENT = BINTRAY_URL_API + "/content"
|
||||||
}
|
}
|
||||||
|
|
||||||
class JCenterResponse(val jo: JsonObject?, val errorMessage: String?)
|
class BintrayResponse(val jo: JsonObject?, val errorMessage: String?)
|
||||||
|
|
||||||
fun parseResponse(r: Response) : JCenterResponse {
|
fun parseResponse(r: Response): BintrayResponse {
|
||||||
val networkResponse = r.networkResponse()
|
val networkResponse = r.networkResponse()
|
||||||
if (networkResponse.code() != 200) {
|
if (networkResponse.code() != 200) {
|
||||||
val message = networkResponse.message()
|
val message = networkResponse.message()
|
||||||
val errorObject = JsonParser().parse(r.body().string()).asJsonObject
|
val errorObject = JsonParser().parse(r.body().string()).asJsonObject
|
||||||
return JCenterResponse(null, message + ": " + errorObject.get("message").asString)
|
return BintrayResponse(null, message + ": " + errorObject.get("message").asString)
|
||||||
} else {
|
} else {
|
||||||
return JCenterResponse(JsonParser().parse(r.body().string()).asJsonObject, null)
|
return BintrayResponse(JsonParser().parse(r.body().string()).asJsonObject, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun getPackage() : JCenterPackage {
|
|
||||||
// val url = arrayListOf(BINTRAY_URL_API, "packages", "cbeust", "maven", "kobalt").joinToString("/")
|
|
||||||
// val response = http.get(url).getAsString()
|
|
||||||
// val result = parseResponse(response)
|
|
||||||
// return JCenterPackage(result)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JCenterApi @Inject constructor (
|
class BintrayApi @Inject constructor (
|
||||||
@Nullable @Assisted("username") val username: String?,
|
@Nullable @Assisted("username") val username: String?,
|
||||||
@Nullable @Assisted("password") val password: String?,
|
@Nullable @Assisted("password") val password: String?,
|
||||||
@Nullable @Assisted("org") val org: String?,
|
@Nullable @Assisted("org") val org: String?,
|
||||||
override val http: Http, val gpg: Gpg, val executors: KobaltExecutors) : UnauthenticatedJCenterApi(http) {
|
override val http: Http, val gpg: Gpg, val executors: KobaltExecutors) : UnauthenticatedBintrayApi(http) {
|
||||||
|
|
||||||
interface IFactory {
|
interface IFactory {
|
||||||
fun create(@Nullable @Assisted("username") username: String?,
|
fun create(@Nullable @Assisted("username") username: String?,
|
||||||
@Nullable @Assisted("password") password: String?,
|
@Nullable @Assisted("password") password: String?,
|
||||||
@Nullable @Assisted("org") org: String?) : JCenterApi
|
@Nullable @Assisted("org") org: String?) : BintrayApi
|
||||||
}
|
}
|
||||||
|
|
||||||
fun packageExists(packageName: String) : Boolean {
|
fun packageExists(packageName: String) : Boolean {
|
||||||
val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", org ?: username!!,
|
val url = arrayListOf(UnauthenticatedBintrayApi.BINTRAY_URL_API, "packages", org ?: username!!,
|
||||||
"maven", packageName)
|
"maven", packageName)
|
||||||
.joinToString("/")
|
.joinToString("/")
|
||||||
val jcResponse = parseResponse(http.get(username, password, url))
|
val jcResponse = parseResponse(http.get(username, password, url))
|
||||||
|
|
||||||
if (jcResponse.errorMessage != null) {
|
if (jcResponse.errorMessage != null) {
|
||||||
throw KobaltException("Error from JCenter: ${jcResponse.errorMessage}")
|
throw KobaltException("Error from Bintray: ${jcResponse.errorMessage}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return jcResponse.jo!!.get("name").asString == packageName
|
return jcResponse.jo!!.get("name").asString == packageName
|
||||||
}
|
}
|
||||||
|
|
||||||
// class ForPost(val name: String, val license: Array<String>)
|
fun uploadMaven(project: Project, files: List<File>, config: BintrayConfig?) : TaskResult {
|
||||||
//
|
|
||||||
// fun createPackage(packageName: String) : String {
|
|
||||||
// val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", username!!, "maven").join("/")
|
|
||||||
// val jsonString = Gson().toJson(ForPost(packageName, arrayOf("Apache 2.0")))
|
|
||||||
// return http.post(username, password, url, jsonString)
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun uploadMaven(project: Project, files: List<File>, config: JCenterConfig?) : TaskResult {
|
|
||||||
if (! packageExists(project.name)) {
|
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")
|
||||||
|
@ -93,7 +78,7 @@ public class JCenterApi @Inject constructor (
|
||||||
|
|
||||||
val fileToPath: (File) -> String = { f: File ->
|
val fileToPath: (File) -> String = { f: File ->
|
||||||
arrayListOf(
|
arrayListOf(
|
||||||
UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT,
|
UnauthenticatedBintrayApi.BINTRAY_URL_API_CONTENT,
|
||||||
org ?: username!!,
|
org ?: username!!,
|
||||||
"maven",
|
"maven",
|
||||||
project.name,
|
project.name,
|
||||||
|
@ -108,12 +93,12 @@ public class JCenterApi @Inject constructor (
|
||||||
return upload(files, config, fileToPath, generateMd5 = true)
|
return upload(files, config, fileToPath, generateMd5 = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadFile(file: File, url: String, config: JCenterConfig, generateMd5: Boolean = false) =
|
fun uploadFile(file: File, url: String, config: BintrayConfig?, generateMd5: Boolean = false) =
|
||||||
upload(arrayListOf(file), config, {
|
upload(arrayListOf(file), config, {
|
||||||
f: File -> "${UnauthenticatedJCenterApi.BINTRAY_URL_API_CONTENT}/${org ?: username}/generic/$url"},
|
f: File -> "${UnauthenticatedBintrayApi.BINTRAY_URL_API_CONTENT}/${org ?: username}/generic/$url"},
|
||||||
generateMd5)
|
generateMd5)
|
||||||
|
|
||||||
private fun upload(files: List<File>, config: JCenterConfig?, fileToPath: (File) -> String,
|
private fun upload(files: List<File>, config: BintrayConfig?, fileToPath: (File) -> String,
|
||||||
generateMd5: Boolean = false) : TaskResult {
|
generateMd5: Boolean = false) : TaskResult {
|
||||||
val filesToUpload = arrayListOf<File>()
|
val filesToUpload = arrayListOf<File>()
|
||||||
|
|
||||||
|
@ -146,7 +131,7 @@ public class JCenterApi @Inject constructor (
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Uploads can'be done in parallel or JCenter rejects them
|
// Uploads can'be done in parallel or Bintray rejects them
|
||||||
//
|
//
|
||||||
val fileCount = filesToUpload.size
|
val fileCount = filesToUpload.size
|
||||||
if (fileCount > 0) {
|
if (fileCount > 0) {
|
||||||
|
@ -165,7 +150,7 @@ public class JCenterApi @Inject constructor (
|
||||||
filesToUpload.forEach { file ->
|
filesToUpload.forEach { file ->
|
||||||
http.uploadFile(username, password, fileToPath(file) + optionPath,
|
http.uploadFile(username, password, fileToPath(file) + optionPath,
|
||||||
TypedFile(MediaType.ANY_APPLICATION_TYPE.toString(), file),
|
TypedFile(MediaType.ANY_APPLICATION_TYPE.toString(), file),
|
||||||
post = false, // JCenter requires PUT
|
post = false, // Bintray requires PUT
|
||||||
success = { r: Response -> results.add(true) },
|
success = { r: Response -> results.add(true) },
|
||||||
error = { r: Response ->
|
error = { r: Response ->
|
||||||
results.add(false)
|
results.add(false)
|
|
@ -16,14 +16,14 @@ import javax.inject.Singleton
|
||||||
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER")
|
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER")
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory,
|
public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory,
|
||||||
val jcenterFactory: JCenterApi.IFactory, val github: GithubApi, val localProperties: LocalProperties)
|
val bintrayFactory: BintrayApi.IFactory, val github: GithubApi, val localProperties: LocalProperties)
|
||||||
: BasePlugin() {
|
: BasePlugin() {
|
||||||
|
|
||||||
override val name = PLUGIN_NAME
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PLUGIN_NAME = "Publish"
|
const val PLUGIN_NAME = "Publish"
|
||||||
private const val TASK_UPLOAD_JCENTER = "uploadJcenter"
|
private const val TASK_UPLOAD_BINTRAY = "uploadBintray"
|
||||||
private const val TASK_UPLOAD_GITHUB = "uploadGithub"
|
private const val TASK_UPLOAD_GITHUB = "uploadGithub"
|
||||||
private const val TASK_GENERATE_POM = "generatePom"
|
private const val TASK_GENERATE_POM = "generatePom"
|
||||||
|
|
||||||
|
@ -55,47 +55,22 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@Task(name = TASK_UPLOAD_JCENTER, description = "Upload files to JCenter",
|
@Task(name = TASK_UPLOAD_BINTRAY, description = "Upload files to Bintray",
|
||||||
runAfter = arrayOf(TASK_GENERATE_POM))
|
runAfter = arrayOf(TASK_GENERATE_POM))
|
||||||
fun taskUploadJcenter(project: Project): TaskResult {
|
fun taskUploadBintray(project: Project): TaskResult {
|
||||||
validateProject(project)
|
validateProject(project)
|
||||||
return uploadJcenter(project)
|
return uploadBintray(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Task(name = TASK_UPLOAD_GITHUB, description = "Upload files to Github",
|
private fun uploadBintray(project: Project) : TaskResult {
|
||||||
runAfter = arrayOf(TASK_GENERATE_POM))
|
|
||||||
fun taskUploadGithub(project: Project): TaskResult {
|
|
||||||
validateProject(project)
|
|
||||||
return uploadGithub(project)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun uploadGithub(project: Project) : TaskResult {
|
|
||||||
val configuration = githubConfigurations[project.name]
|
|
||||||
|
|
||||||
//
|
|
||||||
// Upload individual files, if applicable
|
|
||||||
//
|
|
||||||
if (configuration != null) {
|
|
||||||
configuration.files.forEach {
|
|
||||||
log(2, "Uploading $it tag: ${project.version}")
|
|
||||||
github.uploadRelease(project.name, project.version!!, it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn("Couldn't find any github{} configuration, not uploading anything")
|
|
||||||
}
|
|
||||||
|
|
||||||
return TaskResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun uploadJcenter(project: Project) : TaskResult {
|
|
||||||
val docUrl = DocUrl.PUBLISH_PLUGIN_URL
|
val docUrl = DocUrl.PUBLISH_PLUGIN_URL
|
||||||
val user = localProperties.get(PROPERTY_BINTRAY_USER, docUrl)
|
val user = localProperties.get(PROPERTY_BINTRAY_USER, docUrl)
|
||||||
val password = localProperties.get(PROPERTY_BINTRAY_PASSWORD, docUrl)
|
val password = localProperties.get(PROPERTY_BINTRAY_PASSWORD, docUrl)
|
||||||
val org = localProperties.getNoThrows(PROPERTY_BINTRAY_ORG, docUrl)
|
val org = localProperties.getNoThrows(PROPERTY_BINTRAY_ORG, docUrl)
|
||||||
|
|
||||||
val jcenter = jcenterFactory.create(user, password, org)
|
val jcenter = bintrayFactory.create(user, password, org)
|
||||||
var success = false
|
var success = false
|
||||||
val configuration = jcenterConfigurations[project.name]
|
val configuration = bintrayConfigurations[project.name]
|
||||||
val messages = arrayListOf<String>()
|
val messages = arrayListOf<String>()
|
||||||
|
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
|
@ -125,12 +100,37 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
return TaskResult(success, messages.joinToString("\n "))
|
return TaskResult(success, messages.joinToString("\n "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Task(name = TASK_UPLOAD_GITHUB, description = "Upload files to Github",
|
||||||
|
runAfter = arrayOf(TASK_GENERATE_POM))
|
||||||
|
fun taskUploadGithub(project: Project): TaskResult {
|
||||||
|
validateProject(project)
|
||||||
|
return uploadGithub(project)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun uploadGithub(project: Project) : TaskResult {
|
||||||
|
val configuration = githubConfigurations[project.name]
|
||||||
|
|
||||||
|
//
|
||||||
|
// Upload individual files, if applicable
|
||||||
|
//
|
||||||
|
if (configuration != null) {
|
||||||
|
configuration.files.forEach {
|
||||||
|
log(2, "Uploading $it tag: ${project.version}")
|
||||||
|
github.uploadRelease(project.name, project.version!!, it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn("Couldn't find any github{} configuration, not uploading anything")
|
||||||
|
}
|
||||||
|
|
||||||
|
return TaskResult()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of project name -> JCenterConfiguration
|
* Map of project name -> BintrayConfig
|
||||||
*/
|
*/
|
||||||
private val jcenterConfigurations = hashMapOf<String, JCenterConfig>()
|
private val bintrayConfigurations = hashMapOf<String, BintrayConfig>()
|
||||||
fun addJCenterConfiguration(projectName: String, config: JCenterConfig) {
|
fun addBintrayConfiguration(projectName: String, config: BintrayConfig) {
|
||||||
jcenterConfigurations.put(projectName, config)
|
bintrayConfigurations.put(projectName, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,18 +159,18 @@ public fun Project.github(init: GithubConfig.() -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class JCenterConfig(val project: Project) {
|
data class BintrayConfig(val project: Project) {
|
||||||
/**
|
/**
|
||||||
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
||||||
* Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to
|
* Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to
|
||||||
* JCenter on the bintray web site. By default, files are not published.
|
* Bintray. By default, files are not published.
|
||||||
*/
|
*/
|
||||||
@Directive
|
@Directive
|
||||||
var publish: Boolean = false
|
var publish: Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, sign the files with GPG. This is only required if you plan to later synchronize these files
|
* If true, sign the files with GPG. This is only required if you plan to later synchronize these files
|
||||||
* from JCenter to Maven Central. Keep this to false if you are only interested in uploading to JCenter.
|
* from Bintray to Maven Central. Keep this to false if you are only interested in uploading to JCenter.
|
||||||
*/
|
*/
|
||||||
@Directive
|
@Directive
|
||||||
var sign: Boolean = false
|
var sign: Boolean = false
|
||||||
|
@ -184,9 +184,9 @@ data class JCenterConfig(val project: Project) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
public fun Project.jcenter(init: JCenterConfig.() -> Unit) {
|
public fun Project.bintray(init: BintrayConfig.() -> Unit) {
|
||||||
with(JCenterConfig(this)) {
|
with(BintrayConfig(this)) {
|
||||||
init()
|
init()
|
||||||
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addJCenterConfiguration(name, this)
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue