diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt deleted file mode 100644 index 9a1116bc..00000000 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.beust.kobalt.maven - -import com.beust.kobalt.HostConfig -import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.log -import com.beust.kobalt.misc.warn -import com.google.common.cache.CacheBuilder -import com.google.common.cache.CacheLoader -import com.google.common.cache.LoadingCache -import com.google.inject.assistedinject.Assisted -import java.io.File -import java.nio.file.Files -import java.nio.file.Paths -import java.nio.file.StandardCopyOption -import java.util.concurrent.Callable -import java.util.concurrent.ExecutorService -import java.util.concurrent.Future -import javax.inject.Inject -import javax.inject.Singleton - -/** - * Manages the download of files from a given HostConfig. - */ -@Singleton -class DownloadManager @Inject constructor(val factory: ArtifactFetcher.IFactory) { - class Key(val hostInfo: HostConfig, val fileName: String, val executor: ExecutorService) { - override fun equals(other: Any?): Boolean { - return (other as Key).hostInfo.url == hostInfo.url - } - - override fun hashCode(): Int { - return hostInfo.url.hashCode() - } - } - - private val CACHE : LoadingCache> = CacheBuilder.newBuilder() - .build(object : CacheLoader>() { - override fun load(key: Key): Future { - return key.executor.submit(factory.create(key.hostInfo, key.fileName)) - } - }) - - fun download(hostInfo: HostConfig, fileName: String, executor: ExecutorService) - : Future = CACHE.get(Key(hostInfo, fileName, executor)) -} - -/** - * Fetches an artifact (a file in a Maven repo, .jar, -javadoc.jar, ...) to the given local file. - */ -class ArtifactFetcher @Inject constructor(@Assisted("hostInfo") val hostInfo: HostConfig, - @Assisted("fileName") val fileName: String, - val files: KFiles) : Callable { - interface IFactory { - fun create(@Assisted("hostInfo") hostInfo: HostConfig, @Assisted("fileName") fileName: String) : ArtifactFetcher - } - - override fun call() : File { - val k = Kurl(hostInfo.copy(url = hostInfo.url + ".md5")) - val remoteMd5 = - if (k.exists) k.string.trim(' ', '\t', '\n').substring(0, 32) - else null - - val tmpFile = Paths.get(fileName + ".tmp") - val file = Paths.get(fileName) - val url = hostInfo.url - if (! Files.exists(file)) { - with(tmpFile.toFile()) { - parentFile.mkdirs() - Kurl(hostInfo).toFile(this) - } - log(2, "Done downloading, renaming $tmpFile to $file") - Files.move(tmpFile, file, StandardCopyOption.REPLACE_EXISTING) - log(1, " Downloaded $url") - log(2, " to $file") - } - - val localMd5 = Md5.toMd5(file.toFile()) - if (remoteMd5 != null && remoteMd5 != localMd5) { - warn("MD5 not matching for $url") - } else { - log(2, "No md5 found for $url, skipping md5 check") - } - - return file.toFile() - } -} diff --git a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt index 64099484..f9b06c53 100644 --- a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt @@ -3,7 +3,6 @@ package com.beust.kobalt.app import com.beust.kobalt.Args import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.PluginInfo -import com.beust.kobalt.maven.ArtifactFetcher import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.Pom import com.beust.kobalt.maven.PomGenerator @@ -32,8 +31,7 @@ public open class MainModule(val args: Args, val settings: KobaltSettings) : Abs PomGenerator.IFactory::class.java, BintrayApi.IFactory::class.java, Pom.IFactory::class.java, - BuildFileCompiler.IFactory::class.java, - ArtifactFetcher.IFactory::class.java) + BuildFileCompiler.IFactory::class.java) .forEach { install(builder.build(it)) }