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

Enable source downloading.

This commit is contained in:
Cedric Beust 2016-02-13 08:48:49 -08:00
parent a29d837f42
commit 01df4b8d94
14 changed files with 56 additions and 27 deletions

View file

@ -152,7 +152,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
//
// Load all the jar files synchronously (can't compile the build script until
// they are installed locally).
depFactory.create(it.id, executor)
depFactory.create(it.id, executor = executor)
//
// Open the jar, parse its kobalt-plugin.xml and add the resulting PluginInfo to pluginInfo

View file

@ -5,6 +5,7 @@ import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.RepoFinder
import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Node
import com.beust.kobalt.misc.log
import com.google.inject.Inject
@ -13,7 +14,10 @@ import java.util.*
/**
* Display information about a Maven id.
*/
class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val localRepo: LocalRepo) {
class ResolveDependency @Inject constructor(val repoFinder: RepoFinder,
val localRepo: LocalRepo,
val executors: KobaltExecutors,
val mdFactory: MavenDependency.IFactory) {
val increment = 8
val leftFirst = "\u2558"
val leftMiddle = "\u255f"
@ -26,11 +30,13 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val loca
val repoResult = repoFinder.findCorrectRepo(id)
val indent = -1
val originalDep = MavenDependency.create(id)
val mavenId = MavenId.create(id)
val originalDep = mdFactory.create(mavenId, executors.dependencyExecutor, true, true)
val packaging = if (mavenId.packaging != null) "@" + mavenId.packaging else ""
// We want to display the dependencies of the id we found, not the one we queries
val dep = MavenDependency.create(originalDep.shortId + repoResult.version + packaging)
val dep = mdFactory.create(MavenId.create(originalDep.shortId + repoResult.version + packaging),
executors.dependencyExecutor, true, true)
val root = Node(Dep(dep, indent))
val seen = hashSetOf(id)
root.addChildren(findChildren(root, seen))

View file

@ -13,7 +13,7 @@ public class JarFinder {
fun byIdFuture(id: String) : Future<File> {
val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java).miscExecutor
val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java)
return depFactory.create(id, executor).jarFile
return depFactory.create(id, executor = executor).jarFile
}
/**

View file

@ -18,6 +18,9 @@ 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) {

View file

@ -14,8 +14,7 @@ import javax.inject.Inject
public class DepFactory @Inject constructor(val localRepo: LocalRepo,
val remoteRepo: RepoFinder,
val executors: KobaltExecutors,
val downloadManager: DownloadManager,
val pomFactory: Pom.IFactory) {
val mavenDependencyFactory: MavenDependency.IFactory) {
companion object {
val defExecutor : ExecutorService by lazy {
@ -26,7 +25,8 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
/**
* Parse the id and return the correct IClasspathDependency
*/
public fun create(id: String, executor: ExecutorService = defExecutor, localFirst : Boolean = true)
fun create(id: String, downloadSources: Boolean = false, downloadJavadocs: Boolean = false,
localFirst : Boolean = true, executor: ExecutorService = defExecutor)
: IClasspathDependency {
if (id.startsWith(FileDependency.PREFIX_FILE)) {
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
@ -53,8 +53,9 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
}
}
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version),
executor, localRepo, remoteRepo, pomFactory, downloadManager)
val resultMavenId = MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version)
return mavenDependencyFactory.create(resultMavenId, executor, downloadSources, downloadJavadocs)
}
}
}

View file

@ -58,7 +58,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
dependencies.forEach { projectDependency ->
result.add(projectDependency)
projectDependency.id.let {
result.add(depFactory.create(it, executor))
result.add(depFactory.create(it, executor = executor))
val downloaded = transitiveClosure(projectDependency.directDependencies())
result.addAll(downloaded)

View file

@ -9,6 +9,7 @@ import com.beust.kobalt.misc.DependencyExecutor
import com.beust.kobalt.misc.Versions
import com.beust.kobalt.misc.warn
import com.google.inject.Key
import com.google.inject.assistedinject.Assisted
import org.apache.maven.model.Dependency
import java.io.File
import java.util.concurrent.ExecutorService
@ -16,8 +17,11 @@ import java.util.concurrent.Future
import javax.inject.Inject
import kotlin.properties.Delegates
public class MavenDependency @Inject constructor(mavenId: MavenId,
val executor: ExecutorService,
class MavenDependency @Inject constructor(
@Assisted mavenId: MavenId,
@Assisted val executor: ExecutorService,
@Assisted("downloadSources") val downloadSources: Boolean,
@Assisted("downloadJavadocs") val downloadJavadocs: Boolean,
override val localRepo: LocalRepo,
val repoFinder: RepoFinder,
val pomFactory: Pom.IFactory,
@ -26,6 +30,12 @@ public class MavenDependency @Inject constructor(mavenId: MavenId,
override var jarFile: Future<File> by Delegates.notNull()
var pomFile: Future<File> by Delegates.notNull()
interface IFactory {
fun create(mavenId: MavenId, executor: ExecutorService,
@Assisted("downloadSources") downloadSources: Boolean,
@Assisted("downloadJavadocs") downloadJavadocs: Boolean) : MavenDependency
}
init {
val jar = File(localRepo.toFullPath(toJarFile(version)))
val aar = File(localRepo.toFullPath(toAarFile(version)))
@ -52,12 +62,17 @@ public class MavenDependency @Inject constructor(mavenId: MavenId,
}
companion object {
val executor = Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java))
val defaultExecutor =
Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java))
val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java)
fun create(id: String, ex: ExecutorService = executor) = depFactory.create(id, ex)
fun create(id: String, downloadSources: Boolean = false, downloadJavadocs: Boolean = false,
executor: ExecutorService = defaultExecutor)
= depFactory.create(id, downloadSources, downloadJavadocs, executor = executor)
fun create(mavenId: MavenId, ex: ExecutorService = executor) = depFactory.create(mavenId.toId, ex)
fun create(mavenId: MavenId, downloadSources: Boolean = false, downloadJavadocs: Boolean = false,
executor: ExecutorService = defaultExecutor)
= create(mavenId.toId, downloadSources, downloadJavadocs, executor)
}
override fun toString() = mavenId.toId

View file

@ -22,7 +22,8 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory,
cds.forEach { compileDependency ->
if (MavenId.isMavenId(compileDependency.id)) {
try {
val dep = depFactory.create(compileDependency.shortId, executor, localFirst = false)
val dep = depFactory.create(compileDependency.shortId, localFirst = false,
executor = executor)
if (dep is MavenDependency) {
val other = compileDependency as MavenDependency
if (dep.id != compileDependency.id