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

Better uploading.

This commit is contained in:
Cedric Beust 2015-10-15 01:57:29 -07:00
parent dffb75483d
commit 98f85bf674

View file

@ -126,39 +126,39 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val
val options = arrayListOf<String>() val options = arrayListOf<String>()
if (configuration?.publish == true) options.add("publish=1") if (configuration?.publish == true) options.add("publish=1")
val optionPath = StringBuffer()
if (options.size() > 0) {
optionPath.append("?" + options.join("&"))
}
// //
// TODO: These files should be uploaded from a thread pool instead of serially // Uploads can'be done in parallel or JCenter rejects them
// //
val fileCount = filesToUpload.size() val fileCount = filesToUpload.size()
log(1, "Found $fileCount artifacts to upload") if (fileCount > 0) {
val callables = filesToUpload.map { FileUploadCallable(username, password, fileToPath(it), it) } log(1, "Found $fileCount artifacts to upload: " + filesToUpload.get(0)
+ if (fileCount > 1) "..." else "")
var i = 1 var i = 1
val results = executors.completionService("FileUpload", 5, 60000000, callables, { tr: TaskResult -> val errorMessages = arrayListOf<String>()
val last = i >= fileCount filesToUpload.forEach { file ->
val end = if (last) "\n" else "" http.uploadFile(username, password, fileToPath(file) + optionPath, file,
log(1, " Uploading " + (i++) + " / $fileCount$end", false) { },
{ r: Response ->
val jo = parseResponse(r.body().string())
errorMessages.add(jo.string("message") ?: "No message found")
}) })
val errorMessages = results.filter { ! it.success }.map { it.errorMessage!! } val end = if (i >= fileCount) "\n" else ""
log(1, " Uploading " + (i++) + " / $fileCount$end", false)
}
if (errorMessages.isEmpty()) { if (errorMessages.isEmpty()) {
return TaskResult() return TaskResult()
} else { } else {
error("Errors while uploading:\n" + errorMessages.map { " $it" }.join("\n")) error("Errors while uploading:\n" + errorMessages.map { " $it" }.join("\n"))
return com.beust.kobalt.internal.TaskResult(false, errorMessages.join("\n")) return TaskResult(false, errorMessages.join("\n"))
} }
} else {
warn("Found no artifacts to upload")
return TaskResult()
} }
inner class FileUploadCallable(val username: String?, val password: String?, val url: String, val file: File)
: Callable<TaskResult> {
override fun call(): TaskResult? {
var result: TaskResult? = null
http.uploadFile(username, password, url, file,
{ result = TaskResult() },
{ r: Response ->
val jo = parseResponse(r.body().string())
result = TaskResult(false, jo.string("message") ?: "No message found")
})
return result
}
} }
} }