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:
parent
a3d4558dd7
commit
cae28c515c
4 changed files with 13 additions and 24 deletions
|
@ -47,15 +47,6 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
|
||||||
fun create(@Assisted("url") url: String, @Assisted("fileName") fileName: String) : ArtifactFetcher
|
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 {
|
override fun call() : File {
|
||||||
val k = Kurl(url + ".md5", http)
|
val k = Kurl(url + ".md5", http)
|
||||||
val remoteMd5 =
|
val remoteMd5 =
|
||||||
|
@ -64,15 +55,14 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
|
||||||
|
|
||||||
val file = File(fileName)
|
val file = File(fileName)
|
||||||
file.parentFile.mkdirs()
|
file.parentFile.mkdirs()
|
||||||
val bytes = getBytes(url)
|
Kurl(url, http).toFile(file)
|
||||||
if (remoteMd5 != null && remoteMd5 != Md5.toMd5(bytes)) {
|
log(1, " Downloaded $url")
|
||||||
|
|
||||||
|
if (remoteMd5 != null && remoteMd5 != Md5.toMd5(file)) {
|
||||||
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)
|
|
||||||
|
|
||||||
log(1, "Downloaded $url")
|
|
||||||
|
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.URLConnection
|
import java.net.URLConnection
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.properties.Delegates
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstracts a URL so that it works transparently on either http:// or file://
|
* 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
|
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
|
fun toOutputStream(os: OutputStream) = ByteStreams.copy(connection.inputStream, os)
|
||||||
get() {
|
|
||||||
val buffer = ByteArrayOutputStream(estimatedSize)
|
fun toFile(file: File) = toOutputStream(FileOutputStream(file))
|
||||||
ByteStreams.copy(connection.inputStream, buffer)
|
|
||||||
return buffer.toByteArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
val string: String
|
val string: String
|
||||||
get() {
|
get() {
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class AndroidPlugin @Inject constructor() : BasePlugin() {
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
log(1, "Applying plug-in Android on project $project")
|
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 {
|
fun dirGet(dir: Path, vararg others: String) : String {
|
||||||
|
|
|
@ -54,7 +54,8 @@ public class JavaPlugin @Inject constructor(
|
||||||
javac!!.absolutePath,
|
javac!!.absolutePath,
|
||||||
"-d", outputDirectory.absolutePath)
|
"-d", outputDirectory.absolutePath)
|
||||||
if (cpList.size > 0) {
|
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)
|
validateClasspath(stringClasspath)
|
||||||
args.add("-classpath")
|
args.add("-classpath")
|
||||||
args.add(stringClasspath.joinToString(File.pathSeparator))
|
args.add(stringClasspath.joinToString(File.pathSeparator))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue