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

Code clean up.

This commit is contained in:
Cedric Beust 2015-10-12 20:30:07 -07:00
parent 9f6895f527
commit 57f54be654

View file

@ -1,9 +1,7 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.file
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.plugin.packaging.JarUtils
import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache import com.google.common.cache.LoadingCache
@ -66,14 +64,14 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
} }
private fun getBytes(url: String) : ByteArray { private fun getBytes(url: String) : ByteArray {
log(2, "${url}: downloading to ${fileName}") log(2, "$url: downloading to $fileName")
val body = http.get(url) val body = http.get(url)
if (body.code == 200) { if (body.code == 200) {
val buffer = ByteArrayOutputStream(estimatedSize) val buffer = ByteArrayOutputStream(estimatedSize)
body.getAsStream().copyTo(buffer, estimatedSize) body.getAsStream().copyTo(buffer, estimatedSize)
return buffer.toByteArray() return buffer.toByteArray()
} else { } else {
throw KobaltException("${url}: failed to download, code: ${body.code}") throw KobaltException("$url: failed to download, code: ${body.code}")
} }
} }
@ -89,9 +87,9 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
file.parentFile.mkdirs() file.parentFile.mkdirs()
val bytes = getBytes(url) val bytes = getBytes(url)
if (remoteMd5 != null && remoteMd5 != toMd5(bytes)) { if (remoteMd5 != null && remoteMd5 != toMd5(bytes)) {
throw KobaltException("MD5 not matching for ${url}") throw KobaltException("MD5 not matching for $url")
} else { } else {
log(2, "No md5 found for ${url}, skipping md5 check") log(2, "No md5 found for $url, skipping md5 check")
} }
files.saveFile(file, bytes) files.saveFile(file, bytes)