1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Resolve range versions as soon as possible.

This commit is contained in:
Cedric Beust 2016-08-03 03:45:44 -08:00
parent e8f7d2bce8
commit eef34e66da
3 changed files with 22 additions and 6 deletions

View file

@ -3,7 +3,9 @@ package com.beust.kobalt.api
import com.beust.kobalt.TestConfig
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.aether.KobaltAether
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import org.apache.maven.model.Model
import java.io.File
import java.util.*
@ -143,10 +145,20 @@ class Dependencies(val project: Project,
*/
private fun addToDependencies(project: Project, dependencies: ArrayList<IClasspathDependency>,
dep: Array<out String>): List<Future<File>>
= with(dep.map { DependencyManager.create(it, project.directory)}) {
= with(dep.map {
val resolved =
if (KobaltAether.isRangeVersion(it)) {
val result = Kobalt.INJECTOR.getInstance(KobaltAether::class.java).resolve(it).dependency.id
log(2, "Resolved range id $it to $result")
result
} else {
it
}
DependencyManager.create(resolved, project.directory)
}) {
dependencies.addAll(this)
this.map { FutureTask { it.jarFile.get() } }
}
}
@Directive
fun compile(vararg dep: String) = addToDependencies(project, dependencies, dep)

View file

@ -77,6 +77,10 @@ class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String
class AetherResult(val artifact: Artifact, val repository: ArtifactRepository)
class KobaltAether @Inject constructor (val settings: KobaltSettings, val aether: Aether) {
companion object {
fun isRangeVersion(id: String) = id.contains(",")
}
/**
* Create an IClasspathDependency from a Kobalt id.
*/
@ -202,7 +206,7 @@ class Aether(localRepo: File, val settings: KobaltSettings, val eventBus: EventB
try {
val scopeFilter = Scope.toFilter(filterScopes)
val result =
if (artifact.version.contains(",")) {
if (KobaltAether.isRangeVersion(artifact.version)) {
val request = rangeRequest(artifact)
val v = system.resolveVersionRange(session, request)
val ar = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.classifier,

View file

@ -180,13 +180,13 @@ private class Main @Inject constructor(
error(buildFile.path.toFile().path + " does not exist")
} else {
val allProjects = projectFinder.initForBuildFile(buildFile, args)
// DONOTCOMMIT
// val data = dependencyData.dependenciesDataFor(homeDir("kotlin/klaxon/kobalt/src/Build.kt"), Args(),
// val data = dependencyData.dependenciesDataFor(homeDir("kotlin/ktor/kobalt/src/Build.kt"), Args(),
// useGraph = true)
// println("Data: $data")
val allProjects = projectFinder.initForBuildFile(buildFile, args)
if (args.projectInfo) {
// --projectInfo
allProjects.forEach {