From 01df4b8d94aefd98222c46e26641401431e827fa Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 13 Feb 2016 08:48:49 -0800 Subject: [PATCH] Enable source downloading. --- .../main/kotlin/com/beust/kobalt/Plugins.kt | 2 +- .../com/beust/kobalt/ResolveDependency.kt | 12 ++++++--- .../kotlin/com/beust/kobalt/api/JarFinder.kt | 2 +- .../com/beust/kobalt/maven/ArtifactFetcher.kt | 3 +++ .../com/beust/kobalt/maven/DepFactory.kt | 11 ++++---- .../beust/kobalt/maven/DependencyManager.kt | 2 +- .../maven/dependency/MavenDependency.kt | 25 +++++++++++++++---- .../com/beust/kobalt/misc/CheckVersions.kt | 3 ++- .../kotlin/com/beust/kobalt/app/MainModule.kt | 4 ++- .../app/remote/GetDependenciesCommand.kt | 2 +- .../kobalt/plugin/kotlin/KotlinCompiler.kt | 3 ++- .../kobalt/plugin/kotlin/KotlinPlugin.kt | 2 +- .../com/beust/kobalt/maven/DownloadTest.kt | 8 +++--- .../com/beust/kobalt/maven/RemoteRepoTest.kt | 4 +-- 14 files changed, 56 insertions(+), 27 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt index 651289c7..5b6532ae 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -152,7 +152,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider { 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 } /** 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 index e067b67d..9a1116bc 100644 --- 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 @@ -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) { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt index 10f2e4a7..59dae026 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt @@ -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) } } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 1a26f54a..b4b31606 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt index 647b29ed..d990fc42 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt @@ -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 by Delegates.notNull() var pomFile: Future 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index e81e8d55..fbcbbecc 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -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 diff --git a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt index 64099484..599747b3 100644 --- a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt @@ -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)) } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt index 9a121abe..8f06577b 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt @@ -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) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 49f27020..6ff95a32 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -115,7 +115,8 @@ class KotlinCompiler @Inject constructor( otherClasspath: List, sourceFiles: List, outputDir: File, args: List) : 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 diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 64f3c99e..9a7c0b2d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -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 } diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index 9d245b40..7838c16c 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -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() diff --git a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt index c25af55e..a03444db 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt @@ -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()) }