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

Make ArtifactFetcher use Kurl.

This commit is contained in:
Cedric Beust 2015-10-28 07:21:19 -07:00
parent a3d4558dd7
commit cae28c515c
4 changed files with 13 additions and 24 deletions

View file

@ -47,15 +47,6 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
fun create(@Assisted("url") url: String, @Assisted("fileName") fileName: String) : ArtifactFetcher
}
/** The Kotlin compiler is about 17M and downloading it with the default buffer size takes forever */
private val estimatedSize: Int
get() = if (url.contains("kotlin-compiler")) 18000000 else 1000000
private fun getBytes(url: String) : ByteArray {
log(2, "$url: downloading to $fileName")
return Kurl(url, http).bytes
}
override fun call() : File {
val k = Kurl(url + ".md5", http)
val remoteMd5 =
@ -64,15 +55,14 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
val file = File(fileName)
file.parentFile.mkdirs()
val bytes = getBytes(url)
if (remoteMd5 != null && remoteMd5 != Md5.toMd5(bytes)) {
Kurl(url, http).toFile(file)
log(1, " Downloaded $url")
if (remoteMd5 != null && remoteMd5 != Md5.toMd5(file)) {
throw KobaltException("MD5 not matching for $url")
} else {
log(2, "No md5 found for $url, skipping md5 check")
}
files.saveFile(file, bytes)
log(1, "Downloaded $url")
return file
}

View file

@ -7,7 +7,6 @@ import java.net.HttpURLConnection
import java.net.URL
import java.net.URLConnection
import javax.inject.Inject
import kotlin.properties.Delegates
/**
* Abstracts a URL so that it works transparently on either http:// or file://
@ -34,14 +33,13 @@ public class Kurl @Inject constructor(@Assisted val url: String, val http: Http)
return result
}
val estimatedSize = 18000000
/** The Kotlin compiler is about 17M and downloading it with the default buffer size takes forever */
private val estimatedSize: Int
get() = if (url.contains("kotlin-compiler")) 18000000 else 1000000
val bytes : ByteArray
get() {
val buffer = ByteArrayOutputStream(estimatedSize)
ByteStreams.copy(connection.inputStream, buffer)
return buffer.toByteArray()
}
fun toOutputStream(os: OutputStream) = ByteStreams.copy(connection.inputStream, os)
fun toFile(file: File) = toOutputStream(FileOutputStream(file))
val string: String
get() {

View file

@ -35,7 +35,7 @@ public class AndroidPlugin @Inject constructor() : BasePlugin() {
override fun apply(project: Project, context: KobaltContext) {
log(1, "Applying plug-in Android on project $project")
project.compileDependencies.add(FileDependency(androidJar.toString()))
// project.compileDependencies.add(FileDependency(androidJar.toString()))
}
fun dirGet(dir: Path, vararg others: String) : String {

View file

@ -54,7 +54,8 @@ public class JavaPlugin @Inject constructor(
javac!!.absolutePath,
"-d", outputDirectory.absolutePath)
if (cpList.size > 0) {
val stringClasspath = cpList.map { it.jarFile.get().absolutePath }
val fullClasspath = dependencyManager.transitiveClosure(cpList)
val stringClasspath = fullClasspath.map { it.jarFile.get().absolutePath }
validateClasspath(stringClasspath)
args.add("-classpath")
args.add(stringClasspath.joinToString(File.pathSeparator))