mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Fix hosts for ResolveDependency.
This commit is contained in:
parent
8e583c5a73
commit
75dda87fdd
9 changed files with 50 additions and 65 deletions
|
@ -3,13 +3,15 @@ package com.beust.kobalt
|
|||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
import com.beust.kobalt.maven.aether.DependencyResult
|
||||
import com.beust.kobalt.maven.aether.AetherDependency
|
||||
import com.beust.kobalt.maven.aether.Filters
|
||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.Node
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.aether.artifact.DefaultArtifact
|
||||
import org.eclipse.aether.graph.DependencyNode
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -29,14 +31,34 @@ class ResolveDependency @Inject constructor(
|
|||
|
||||
fun run(id: String) = displayDependenciesFor(id)
|
||||
|
||||
private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode {
|
||||
val artifact = DefaultArtifact(group, artifactId, extension, "(0,]")
|
||||
val resolved = aether.resolveVersion(artifact)
|
||||
if (resolved != null) {
|
||||
val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension,
|
||||
resolved.highestVersion.toString())
|
||||
val artifactResult = aether.resolve(KobaltMavenResolver.artifactToId(newArtifact), null)
|
||||
return artifactResult.root
|
||||
} else {
|
||||
throw KobaltException("Couldn't find latest artifact for $group:$artifactId")
|
||||
}
|
||||
}
|
||||
|
||||
class PairResult(val dependency: IClasspathDependency, val repoUrl: String)
|
||||
|
||||
fun latestArtifact(group: String, artifactId: String, extension: String = "jar"): PairResult
|
||||
= latestMavenArtifact(group, artifactId, extension).let {
|
||||
PairResult(AetherDependency(it.artifact), "(TBD repo)")
|
||||
}
|
||||
|
||||
private fun displayDependenciesFor(id: String) {
|
||||
val mavenId = MavenId.create(id)
|
||||
val resolved : DependencyResult =
|
||||
val resolved : PairResult =
|
||||
if (mavenId.hasVersion) {
|
||||
val dep = aether.resolveToDependencies(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)[0]
|
||||
DependencyResult(dep, "")
|
||||
val node = aether.resolve(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)
|
||||
PairResult(AetherDependency(node.root.artifact), node.artifactResults[0].repository.id)
|
||||
} else {
|
||||
aether.latestArtifact(mavenId.groupId, mavenId.artifactId)
|
||||
latestArtifact(mavenId.groupId, mavenId.artifactId)
|
||||
}
|
||||
|
||||
displayDependencies(resolved.dependency, resolved.repoUrl)
|
||||
|
|
|
@ -53,7 +53,7 @@ class KobaltContext(val args: Args) {
|
|||
FileType.JAVADOC -> toQualifier(dep, "", "javadoc")
|
||||
FileType.OTHER -> id
|
||||
}
|
||||
val resolved = resolver.resolve(fullId).artifact
|
||||
val resolved = resolver.resolveToArtifact(fullId)
|
||||
if (resolved != null) {
|
||||
return resolved.file
|
||||
} else {
|
||||
|
|
|
@ -150,8 +150,8 @@ class Dependencies(val project: Project,
|
|||
val resolved =
|
||||
if (KobaltMavenResolver.isRangeVersion(it)) {
|
||||
// Range id
|
||||
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolve(it)
|
||||
val result = KobaltMavenResolver.artifactToId(node.artifact)
|
||||
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToArtifact(it)
|
||||
val result = KobaltMavenResolver.artifactToId(node)
|
||||
kobaltLog(2, "Resolved range id $it to $result")
|
||||
result
|
||||
} else {
|
||||
|
|
|
@ -62,7 +62,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
|
|||
*/
|
||||
override fun createMaven(id: String, optional: Boolean) : IClasspathDependency=
|
||||
if (KobaltMavenResolver.isRangeVersion(id)) {
|
||||
Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToDependencies(id)[0]
|
||||
Kobalt.INJECTOR.getInstance(DependencyManager::class.java).create(id, optional)
|
||||
} else {
|
||||
resolver.create(id, optional)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
|
|||
CompletedFuture(file)
|
||||
} else {
|
||||
val td = aether.resolve(artifact, null)
|
||||
CompletedFuture(td.artifact.file)
|
||||
CompletedFuture(td.root.artifact.file)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
|
||||
class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String)
|
|
@ -1,7 +1,5 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.getProxy
|
||||
|
@ -16,9 +14,9 @@ import org.eclipse.aether.collection.CollectResult
|
|||
import org.eclipse.aether.graph.DefaultDependencyNode
|
||||
import org.eclipse.aether.graph.Dependency
|
||||
import org.eclipse.aether.graph.DependencyFilter
|
||||
import org.eclipse.aether.graph.DependencyNode
|
||||
import org.eclipse.aether.repository.RemoteRepository
|
||||
import org.eclipse.aether.resolution.DependencyRequest
|
||||
import org.eclipse.aether.resolution.DependencyResult
|
||||
import org.eclipse.aether.resolution.VersionRangeRequest
|
||||
import org.eclipse.aether.resolution.VersionRangeResult
|
||||
|
||||
|
@ -32,45 +30,38 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
fun isRangeVersion(id: String) = id.contains(",")
|
||||
}
|
||||
|
||||
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null): DependencyNode {
|
||||
fun resolveToArtifact(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : Artifact
|
||||
= resolve(id, scope, filter).root.artifact
|
||||
|
||||
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null): DependencyResult {
|
||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope), filter)
|
||||
val result = system.resolveDependencies(session, dependencyRequest)
|
||||
|
||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
||||
return result.root
|
||||
return result
|
||||
}
|
||||
|
||||
fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null)
|
||||
= resolve(artifactToId(artifact), scope, filter)
|
||||
|
||||
fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : List<String> {
|
||||
val root = resolve(id, scope, filter)
|
||||
val rr = resolve(id, scope, filter)
|
||||
val children =
|
||||
root.children.filter {
|
||||
rr.root.children.filter {
|
||||
filter == null || filter.accept(DefaultDependencyNode(it.dependency), emptyList())
|
||||
}.filter {
|
||||
it.dependency.scope != Scope.SYSTEM.scope
|
||||
}
|
||||
val result = listOf(artifactToId(root.artifact)) + children.flatMap {
|
||||
val result = listOf(artifactToId(rr.root.artifact)) + children.flatMap {
|
||||
val thisId = artifactToId(it.artifact)
|
||||
resolveToIds(thisId, scope, filter)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun resolveToDependencies(id: String, scope: Scope? = null, filter: DependencyFilter? = null)
|
||||
: List<IClasspathDependency> {
|
||||
val result = resolveToIds(id, scope, filter).map {
|
||||
create(it, false)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun directDependencies(id: String, scope: Scope? = null): CollectResult? {
|
||||
val result = system.collectDependencies(session, createCollectRequest(id, scope))
|
||||
return result
|
||||
}
|
||||
fun directDependencies(id: String, scope: Scope? = null): CollectResult?
|
||||
= system.collectDependencies(session, createCollectRequest(id, scope))
|
||||
|
||||
fun directDependencies(artifact: Artifact, scope: Scope? = null): CollectResult?
|
||||
= artifactToId(artifact).let { id ->
|
||||
|
@ -83,29 +74,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
return result
|
||||
}
|
||||
|
||||
private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode {
|
||||
val artifact = DefaultArtifact(group, artifactId, extension, "(0,]")
|
||||
val resolved = resolveVersion(artifact)
|
||||
if (resolved != null) {
|
||||
val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension,
|
||||
resolved.highestVersion.toString())
|
||||
val artifactResult = resolve(artifactToId(newArtifact), null)
|
||||
return artifactResult
|
||||
// if (artifactResult != null) {
|
||||
// return artifactResult
|
||||
// } else {
|
||||
// throw KobaltException("Couldn't find latest artifact for $group:$artifactId")
|
||||
// }
|
||||
} else {
|
||||
throw KobaltException("Couldn't find latest artifact for $group:$artifactId")
|
||||
}
|
||||
}
|
||||
|
||||
fun latestArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyResult
|
||||
= latestMavenArtifact(group, artifactId, extension).let {
|
||||
DependencyResult(AetherDependency(it.artifact), "(TBD repo)")
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an IClasspathDependency from a Kobalt id.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue