From af5217966f18dc912b76566c2b41b5bc666e3b2f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 11 Apr 2017 11:44:09 -0700 Subject: [PATCH] Better range resolution. --- .../maven/aether/KobaltMavenResolver.kt | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 48b3e836..ccc76ed1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -38,13 +38,27 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER) : Artifact = resolve(id, scope, filter).root.artifact - fun resolve(id: String, scope: Scope? = null, + fun resolve(passedId: String, scope: Scope? = null, filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER, repos: List = emptyList()): DependencyResult { - val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter) + val mavenId = MavenId.toMavenId(passedId) + val id = + if (isRangeVersion(mavenId)) { + val artifact = DefaultArtifact(mavenId) + val request = VersionRangeRequest(artifact, createRepos(repos), null) + val rr = system.resolveVersionRange(session, request) + val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.classifier, + artifact.extension, rr.highestVersion.toString()) + artifactToId(newArtifact) + } else { + passedId + } + + val collectRequest = createCollectRequest(id) + val dependencyRequest = DependencyRequest(collectRequest, filter) val result = system.resolveDependencies(session, dependencyRequest) -// GraphUtil.displayGraph(listOf(result.root), { it -> it.children }, -// { it: DependencyNode, indent: String -> println(indent + it.toString()) }) + // GraphUtil.displayGraph(listOf(result.root), { it -> it.children }, + // { it: DependencyNode, indent: String -> println(indent + it.toString()) }) return result } @@ -109,6 +123,9 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, } } + private fun createRepos(repos: List) : List + = kobaltRepositories + repos.map { createRepo(HostConfig(it)) } + private fun createCollectRequest(id: String, scope: Scope? = null, repos: List = emptyList()) = CollectRequest().apply { val allIds = arrayListOf(MavenId.toMavenId(id)) @@ -116,6 +133,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) } root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope) - repositories = kobaltRepositories + repos.map { createRepo(HostConfig(it)) } + repositories = createRepos(repos) } }