From fd2c9a932f74edc76b84e38392733c9c1dff94a9 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 7 Apr 2016 06:22:58 -0800 Subject: [PATCH] Lazy jar get. --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 12 ++++++++---- .../kotlin/com/beust/kobalt/maven/aether/Aether.kt | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index efd8e6e4..bf4a732b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -7,6 +7,8 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KFiles import java.io.File import java.util.* +import java.util.concurrent.Future +import java.util.concurrent.FutureTask open class Project( @Directive open var name: String = "", @@ -146,14 +148,16 @@ class Dependencies(val project: Project, val excludedDependencies: ArrayList) { /** - * Add the dependencies to the given ArrayList and return a list of jar files corresponding to - * these dependencies. + * Add the dependencies to the given ArrayList and return a list of future jar files corresponding to + * these dependencies. Futures are necessary here since this code is invoked from the build file and + * we might not have set up the extra IRepositoryContributors just yet. By the time these + * future tasks receive a get(), the repos will be correct. */ private fun addToDependencies(project: Project, dependencies: ArrayList, - dep: Array): List + dep: Array): List> = with(dep.map { DependencyManager.create(it, project)}) { dependencies.addAll(this) - this.map { it.jarFile.get() } + this.map { FutureTask { it.jarFile.get() } } } @Directive diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt index 3ae78f94..62265e77 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt @@ -41,9 +41,10 @@ class KobaltAether @Inject constructor (val settings: KobaltSettings, val aether * Create an IClasspathDependency from a Kobalt id. */ fun create(id: String): IClasspathDependency { - val cr = aether.transitiveDependencies(DefaultArtifact(MavenId.toKobaltId(id))) - return if (cr != null) AetherDependency(cr.root.artifact) - else throw KobaltException("Couldn't resolve $id") + return AetherDependency(DefaultArtifact(id)) +// val cr = aether.directDependencies(DefaultArtifact(MavenId.toKobaltId(id))) +// return if (cr != null) AetherDependency(cr.root.artifact) +// else throw KobaltException("Couldn't resolve $id") } /**