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

Kurl.IFactory.

This commit is contained in:
Cedric Beust 2015-10-28 20:07:44 -07:00
parent 3ce5e8e40f
commit 4fa253cea2
4 changed files with 13 additions and 11 deletions

View file

@ -42,20 +42,20 @@ class DownloadManager @Inject constructor(val factory: ArtifactFetcher.IFactory)
*/
class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
@Assisted("fileName") val fileName: String,
val files: KFiles, val http: Http) : Callable<File> {
val files: KFiles, val urlFactory: Kurl.IFactory) : Callable<File> {
interface IFactory {
fun create(@Assisted("url") url: String, @Assisted("fileName") fileName: String) : ArtifactFetcher
}
override fun call() : File {
val k = Kurl(url + ".md5", http)
val k = urlFactory.create(url + ".md5")
val remoteMd5 =
if (k.exists) k.string.trim(' ', '\t', '\n').substring(0, 32)
else null
val file = File(fileName)
file.parentFile.mkdirs()
Kurl(url, http).toFile(file)
urlFactory.create(url).toFile(file)
log(1, " Downloaded $url")
if (remoteMd5 != null && remoteMd5 != Md5.toMd5(file)) {

View file

@ -10,11 +10,15 @@ import javax.inject.Inject
/**
* Abstracts a URL so that it works transparently on either http:// or file://
*/
public class Kurl @Inject constructor(@Assisted val url: String, val http: Http) {
class Kurl @Inject constructor(@Assisted val url: String) {
val connection : URLConnection by lazy {
URL(url).openConnection()
}
interface IFactory {
fun create(url: String) : Kurl
}
val exists : Boolean
get() {
val result =

View file

@ -21,7 +21,7 @@ import kotlin.dom.parseXml
* Find the repo that contains the given dependency among a list of repos. Searches are performed in parallel and
* cached so we never make a network call for the same dependency more than once.
*/
public class RepoFinder @Inject constructor(val http: Http, val executors: KobaltExecutors) {
public class RepoFinder @Inject constructor(val urlFactory: Kurl.IFactory, val executors: KobaltExecutors) {
public fun findCorrectRepo(id: String): RepoResult {
return FOUND_REPOS.get(id)
}
@ -97,12 +97,12 @@ public class RepoFinder @Inject constructor(val http: Http, val executors: Kobal
val dep = SimpleDep(groupId, artifactId, packaging, version)
// Try to find the jar file
val urlJar = repoUrl + dep.toJarFile(dep.version)
val hasJar = Kurl(urlJar, http).exists
val hasJar = urlFactory.create(urlJar).exists
val found =
if (! hasJar) {
// No jar, try to find the directory
val url = repoUrl + File(dep.toJarFile(dep.version)).parentFile.path
http.get(url).code == 200
urlFactory.create(url).exists
} else {
true
}

View file

@ -2,10 +2,7 @@ package com.beust.kobalt.misc
import com.beust.kobalt.Args
import com.beust.kobalt.kotlin.BuildFileCompiler
import com.beust.kobalt.maven.ArtifactFetcher
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.Pom
import com.beust.kobalt.maven.PomGenerator
import com.beust.kobalt.maven.*
import com.beust.kobalt.plugin.publish.JCenterApi
import com.google.inject.AbstractModule
import com.google.inject.BindingAnnotation
@ -41,6 +38,7 @@ public open class MainModule(val args: Args) : AbstractModule() {
JCenterApi.IFactory::class.java,
Pom.IFactory::class.java,
BuildFileCompiler.IFactory::class.java,
Kurl.IFactory::class.java,
ArtifactFetcher.IFactory::class.java)
.forEach {
install(builder.build(it))