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:
parent
a29d837f42
commit
01df4b8d94
14 changed files with 56 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,6 +7,7 @@ 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.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.DependencyExecutor
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.plugin.publish.BintrayApi
|
||||
|
@ -33,7 +34,8 @@ public open class MainModule(val args: Args, val settings: KobaltSettings) : Abs
|
|||
BintrayApi.IFactory::class.java,
|
||||
Pom.IFactory::class.java,
|
||||
BuildFileCompiler.IFactory::class.java,
|
||||
ArtifactFetcher.IFactory::class.java)
|
||||
ArtifactFetcher.IFactory::class.java,
|
||||
MavenDependency.IFactory::class.java)
|
||||
.forEach {
|
||||
install(builder.build(it))
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
|||
val executor = executors.miscExecutor
|
||||
|
||||
fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
|
||||
val dep = MavenDependency.create(d.id, executor)
|
||||
val dep = MavenDependency.create(d.id, executor = executor)
|
||||
return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,8 @@ class KotlinCompiler @Inject constructor(
|
|||
otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
|
||||
|
||||
val executor = executors.newExecutor("KotlinCompiler", 10)
|
||||
val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION", executor)
|
||||
val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION",
|
||||
executor = executor)
|
||||
val deps = dependencyManager.transitiveClosure(listOf(compilerDep))
|
||||
|
||||
// Force a download of the compiler dependencies
|
||||
|
|
|
@ -94,7 +94,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
|
||||
private fun getKotlinCompilerJar(name: String): String {
|
||||
val id = "org.jetbrains.kotlin:$name:${KotlinCompiler.KOTLIN_VERSION}"
|
||||
val dep = MavenDependency.create(id, executors.miscExecutor)
|
||||
val dep = MavenDependency.create(id, executor = executors.miscExecutor)
|
||||
val result = dep.jarFile.get().absolutePath
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class DownloadTest @Inject constructor(
|
|||
|
||||
if (success) {
|
||||
arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach {
|
||||
val dep = depFactory.create(it, executor)
|
||||
val dep = depFactory.create(it, executor = executor)
|
||||
val future = dep.jarFile
|
||||
Assert.assertFalse(future is CompletedFuture)
|
||||
val file = future.get()
|
||||
|
@ -62,7 +62,7 @@ class DownloadTest @Inject constructor(
|
|||
public fun shouldDownloadNoVersion() {
|
||||
val success = deleteDir()
|
||||
if (success) {
|
||||
val dep = depFactory.create(idNoVersion, executor)
|
||||
val dep = depFactory.create(idNoVersion, executor = executor)
|
||||
|
||||
val future = dep.jarFile
|
||||
val file = future.get()
|
||||
|
@ -80,7 +80,7 @@ class DownloadTest @Inject constructor(
|
|||
val range = "[2.5,)"
|
||||
val expected = "3.0-alpha-1"
|
||||
|
||||
val dep = depFactory.create("javax.servlet:servlet-api:$range", executor)
|
||||
val dep = depFactory.create("javax.servlet:servlet-api:$range", executor = executor)
|
||||
val future = dep.jarFile
|
||||
val file = future.get()
|
||||
Assert.assertFalse(future is CompletedFuture)
|
||||
|
@ -91,7 +91,7 @@ class DownloadTest @Inject constructor(
|
|||
@Test
|
||||
public fun shouldFindLocalJar() {
|
||||
MavenDependency.create("$idNoVersion$version")
|
||||
val dep = depFactory.create("$idNoVersion$version", executor)
|
||||
val dep = depFactory.create("$idNoVersion$version", executor = executor)
|
||||
val future = dep.jarFile
|
||||
// Assert.assertTrue(future is CompletedFuture)
|
||||
val file = future.get()
|
||||
|
|
|
@ -24,8 +24,8 @@ class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
|||
|
||||
@Test(enabled = false)
|
||||
fun metadataForSnapshots() {
|
||||
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", executor)
|
||||
.jarFile
|
||||
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT",
|
||||
executor = executor).jarFile
|
||||
Assert.assertTrue(jar.get().exists())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue