mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28: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
|
// Load all the jar files synchronously (can't compile the build script until
|
||||||
// they are installed locally).
|
// 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
|
// 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.MavenId
|
||||||
import com.beust.kobalt.maven.RepoFinder
|
import com.beust.kobalt.maven.RepoFinder
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.Node
|
import com.beust.kobalt.misc.Node
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
@ -13,7 +14,10 @@ import java.util.*
|
||||||
/**
|
/**
|
||||||
* Display information about a Maven id.
|
* 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 increment = 8
|
||||||
val leftFirst = "\u2558"
|
val leftFirst = "\u2558"
|
||||||
val leftMiddle = "\u255f"
|
val leftMiddle = "\u255f"
|
||||||
|
@ -26,11 +30,13 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val loca
|
||||||
val repoResult = repoFinder.findCorrectRepo(id)
|
val repoResult = repoFinder.findCorrectRepo(id)
|
||||||
|
|
||||||
val indent = -1
|
val indent = -1
|
||||||
val originalDep = MavenDependency.create(id)
|
|
||||||
val mavenId = MavenId.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 ""
|
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
|
// 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 root = Node(Dep(dep, indent))
|
||||||
val seen = hashSetOf(id)
|
val seen = hashSetOf(id)
|
||||||
root.addChildren(findChildren(root, seen))
|
root.addChildren(findChildren(root, seen))
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class JarFinder {
|
||||||
fun byIdFuture(id: String) : Future<File> {
|
fun byIdFuture(id: String) : Future<File> {
|
||||||
val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java).miscExecutor
|
val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java).miscExecutor
|
||||||
val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java)
|
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.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the download of files from a given HostConfig.
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class DownloadManager @Inject constructor(val factory: ArtifactFetcher.IFactory) {
|
class DownloadManager @Inject constructor(val factory: ArtifactFetcher.IFactory) {
|
||||||
class Key(val hostInfo: HostConfig, val fileName: String, val executor: ExecutorService) {
|
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,
|
public class DepFactory @Inject constructor(val localRepo: LocalRepo,
|
||||||
val remoteRepo: RepoFinder,
|
val remoteRepo: RepoFinder,
|
||||||
val executors: KobaltExecutors,
|
val executors: KobaltExecutors,
|
||||||
val downloadManager: DownloadManager,
|
val mavenDependencyFactory: MavenDependency.IFactory) {
|
||||||
val pomFactory: Pom.IFactory) {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val defExecutor : ExecutorService by lazy {
|
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
|
* 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 {
|
: IClasspathDependency {
|
||||||
if (id.startsWith(FileDependency.PREFIX_FILE)) {
|
if (id.startsWith(FileDependency.PREFIX_FILE)) {
|
||||||
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
|
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 ->
|
dependencies.forEach { projectDependency ->
|
||||||
result.add(projectDependency)
|
result.add(projectDependency)
|
||||||
projectDependency.id.let {
|
projectDependency.id.let {
|
||||||
result.add(depFactory.create(it, executor))
|
result.add(depFactory.create(it, executor = executor))
|
||||||
val downloaded = transitiveClosure(projectDependency.directDependencies())
|
val downloaded = transitiveClosure(projectDependency.directDependencies())
|
||||||
|
|
||||||
result.addAll(downloaded)
|
result.addAll(downloaded)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.beust.kobalt.misc.DependencyExecutor
|
||||||
import com.beust.kobalt.misc.Versions
|
import com.beust.kobalt.misc.Versions
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import com.google.inject.Key
|
import com.google.inject.Key
|
||||||
|
import com.google.inject.assistedinject.Assisted
|
||||||
import org.apache.maven.model.Dependency
|
import org.apache.maven.model.Dependency
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
|
@ -16,8 +17,11 @@ import java.util.concurrent.Future
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class MavenDependency @Inject constructor(mavenId: MavenId,
|
class MavenDependency @Inject constructor(
|
||||||
val executor: ExecutorService,
|
@Assisted mavenId: MavenId,
|
||||||
|
@Assisted val executor: ExecutorService,
|
||||||
|
@Assisted("downloadSources") val downloadSources: Boolean,
|
||||||
|
@Assisted("downloadJavadocs") val downloadJavadocs: Boolean,
|
||||||
override val localRepo: LocalRepo,
|
override val localRepo: LocalRepo,
|
||||||
val repoFinder: RepoFinder,
|
val repoFinder: RepoFinder,
|
||||||
val pomFactory: Pom.IFactory,
|
val pomFactory: Pom.IFactory,
|
||||||
|
@ -26,6 +30,12 @@ public class MavenDependency @Inject constructor(mavenId: MavenId,
|
||||||
override var jarFile: Future<File> by Delegates.notNull()
|
override var jarFile: Future<File> by Delegates.notNull()
|
||||||
var pomFile: 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 {
|
init {
|
||||||
val jar = File(localRepo.toFullPath(toJarFile(version)))
|
val jar = File(localRepo.toFullPath(toJarFile(version)))
|
||||||
val aar = File(localRepo.toFullPath(toAarFile(version)))
|
val aar = File(localRepo.toFullPath(toAarFile(version)))
|
||||||
|
@ -52,12 +62,17 @@ public class MavenDependency @Inject constructor(mavenId: MavenId,
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
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)
|
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
|
override fun toString() = mavenId.toId
|
||||||
|
|
|
@ -22,7 +22,8 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory,
|
||||||
cds.forEach { compileDependency ->
|
cds.forEach { compileDependency ->
|
||||||
if (MavenId.isMavenId(compileDependency.id)) {
|
if (MavenId.isMavenId(compileDependency.id)) {
|
||||||
try {
|
try {
|
||||||
val dep = depFactory.create(compileDependency.shortId, executor, localFirst = false)
|
val dep = depFactory.create(compileDependency.shortId, localFirst = false,
|
||||||
|
executor = executor)
|
||||||
if (dep is MavenDependency) {
|
if (dep is MavenDependency) {
|
||||||
val other = compileDependency as MavenDependency
|
val other = compileDependency as MavenDependency
|
||||||
if (dep.id != compileDependency.id
|
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.LocalRepo
|
||||||
import com.beust.kobalt.maven.Pom
|
import com.beust.kobalt.maven.Pom
|
||||||
import com.beust.kobalt.maven.PomGenerator
|
import com.beust.kobalt.maven.PomGenerator
|
||||||
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.DependencyExecutor
|
import com.beust.kobalt.misc.DependencyExecutor
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.plugin.publish.BintrayApi
|
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,
|
BintrayApi.IFactory::class.java,
|
||||||
Pom.IFactory::class.java,
|
Pom.IFactory::class.java,
|
||||||
BuildFileCompiler.IFactory::class.java,
|
BuildFileCompiler.IFactory::class.java,
|
||||||
ArtifactFetcher.IFactory::class.java)
|
ArtifactFetcher.IFactory::class.java,
|
||||||
|
MavenDependency.IFactory::class.java)
|
||||||
.forEach {
|
.forEach {
|
||||||
install(builder.build(it))
|
install(builder.build(it))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
||||||
val executor = executors.miscExecutor
|
val executor = executors.miscExecutor
|
||||||
|
|
||||||
fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
|
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)
|
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 {
|
otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
|
||||||
|
|
||||||
val executor = executors.newExecutor("KotlinCompiler", 10)
|
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))
|
val deps = dependencyManager.transitiveClosure(listOf(compilerDep))
|
||||||
|
|
||||||
// Force a download of the compiler dependencies
|
// Force a download of the compiler dependencies
|
||||||
|
|
|
@ -94,7 +94,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
|
|
||||||
private fun getKotlinCompilerJar(name: String): String {
|
private fun getKotlinCompilerJar(name: String): String {
|
||||||
val id = "org.jetbrains.kotlin:$name:${KotlinCompiler.KOTLIN_VERSION}"
|
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
|
val result = dep.jarFile.get().absolutePath
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class DownloadTest @Inject constructor(
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach {
|
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
|
val future = dep.jarFile
|
||||||
Assert.assertFalse(future is CompletedFuture)
|
Assert.assertFalse(future is CompletedFuture)
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
|
@ -62,7 +62,7 @@ class DownloadTest @Inject constructor(
|
||||||
public fun shouldDownloadNoVersion() {
|
public fun shouldDownloadNoVersion() {
|
||||||
val success = deleteDir()
|
val success = deleteDir()
|
||||||
if (success) {
|
if (success) {
|
||||||
val dep = depFactory.create(idNoVersion, executor)
|
val dep = depFactory.create(idNoVersion, executor = executor)
|
||||||
|
|
||||||
val future = dep.jarFile
|
val future = dep.jarFile
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
|
@ -80,7 +80,7 @@ class DownloadTest @Inject constructor(
|
||||||
val range = "[2.5,)"
|
val range = "[2.5,)"
|
||||||
val expected = "3.0-alpha-1"
|
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 future = dep.jarFile
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
Assert.assertFalse(future is CompletedFuture)
|
Assert.assertFalse(future is CompletedFuture)
|
||||||
|
@ -91,7 +91,7 @@ class DownloadTest @Inject constructor(
|
||||||
@Test
|
@Test
|
||||||
public fun shouldFindLocalJar() {
|
public fun shouldFindLocalJar() {
|
||||||
MavenDependency.create("$idNoVersion$version")
|
MavenDependency.create("$idNoVersion$version")
|
||||||
val dep = depFactory.create("$idNoVersion$version", executor)
|
val dep = depFactory.create("$idNoVersion$version", executor = executor)
|
||||||
val future = dep.jarFile
|
val future = dep.jarFile
|
||||||
// Assert.assertTrue(future is CompletedFuture)
|
// Assert.assertTrue(future is CompletedFuture)
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
|
|
|
@ -24,8 +24,8 @@ class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
fun metadataForSnapshots() {
|
fun metadataForSnapshots() {
|
||||||
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", executor)
|
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT",
|
||||||
.jarFile
|
executor = executor).jarFile
|
||||||
Assert.assertTrue(jar.get().exists())
|
Assert.assertTrue(jar.get().exists())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue