mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -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.api.IClasspathDependency
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.maven.MavenId
|
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.Filters
|
||||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.Node
|
import com.beust.kobalt.misc.Node
|
||||||
import com.beust.kobalt.misc.kobaltLog
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
import org.eclipse.aether.artifact.DefaultArtifact
|
||||||
|
import org.eclipse.aether.graph.DependencyNode
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,14 +31,34 @@ class ResolveDependency @Inject constructor(
|
||||||
|
|
||||||
fun run(id: String) = displayDependenciesFor(id)
|
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) {
|
private fun displayDependenciesFor(id: String) {
|
||||||
val mavenId = MavenId.create(id)
|
val mavenId = MavenId.create(id)
|
||||||
val resolved : DependencyResult =
|
val resolved : PairResult =
|
||||||
if (mavenId.hasVersion) {
|
if (mavenId.hasVersion) {
|
||||||
val dep = aether.resolveToDependencies(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)[0]
|
val node = aether.resolve(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)
|
||||||
DependencyResult(dep, "")
|
PairResult(AetherDependency(node.root.artifact), node.artifactResults[0].repository.id)
|
||||||
} else {
|
} else {
|
||||||
aether.latestArtifact(mavenId.groupId, mavenId.artifactId)
|
latestArtifact(mavenId.groupId, mavenId.artifactId)
|
||||||
}
|
}
|
||||||
|
|
||||||
displayDependencies(resolved.dependency, resolved.repoUrl)
|
displayDependencies(resolved.dependency, resolved.repoUrl)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class KobaltContext(val args: Args) {
|
||||||
FileType.JAVADOC -> toQualifier(dep, "", "javadoc")
|
FileType.JAVADOC -> toQualifier(dep, "", "javadoc")
|
||||||
FileType.OTHER -> id
|
FileType.OTHER -> id
|
||||||
}
|
}
|
||||||
val resolved = resolver.resolve(fullId).artifact
|
val resolved = resolver.resolveToArtifact(fullId)
|
||||||
if (resolved != null) {
|
if (resolved != null) {
|
||||||
return resolved.file
|
return resolved.file
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -150,8 +150,8 @@ class Dependencies(val project: Project,
|
||||||
val resolved =
|
val resolved =
|
||||||
if (KobaltMavenResolver.isRangeVersion(it)) {
|
if (KobaltMavenResolver.isRangeVersion(it)) {
|
||||||
// Range id
|
// Range id
|
||||||
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolve(it)
|
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToArtifact(it)
|
||||||
val result = KobaltMavenResolver.artifactToId(node.artifact)
|
val result = KobaltMavenResolver.artifactToId(node)
|
||||||
kobaltLog(2, "Resolved range id $it to $result")
|
kobaltLog(2, "Resolved range id $it to $result")
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -62,7 +62,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
|
||||||
*/
|
*/
|
||||||
override fun createMaven(id: String, optional: Boolean) : IClasspathDependency=
|
override fun createMaven(id: String, optional: Boolean) : IClasspathDependency=
|
||||||
if (KobaltMavenResolver.isRangeVersion(id)) {
|
if (KobaltMavenResolver.isRangeVersion(id)) {
|
||||||
Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToDependencies(id)[0]
|
Kobalt.INJECTOR.getInstance(DependencyManager::class.java).create(id, optional)
|
||||||
} else {
|
} else {
|
||||||
resolver.create(id, optional)
|
resolver.create(id, optional)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
|
||||||
CompletedFuture(file)
|
CompletedFuture(file)
|
||||||
} else {
|
} else {
|
||||||
val td = aether.resolve(artifact, null)
|
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
|
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.api.Kobalt
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
import com.beust.kobalt.internal.getProxy
|
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.DefaultDependencyNode
|
||||||
import org.eclipse.aether.graph.Dependency
|
import org.eclipse.aether.graph.Dependency
|
||||||
import org.eclipse.aether.graph.DependencyFilter
|
import org.eclipse.aether.graph.DependencyFilter
|
||||||
import org.eclipse.aether.graph.DependencyNode
|
|
||||||
import org.eclipse.aether.repository.RemoteRepository
|
import org.eclipse.aether.repository.RemoteRepository
|
||||||
import org.eclipse.aether.resolution.DependencyRequest
|
import org.eclipse.aether.resolution.DependencyRequest
|
||||||
|
import org.eclipse.aether.resolution.DependencyResult
|
||||||
import org.eclipse.aether.resolution.VersionRangeRequest
|
import org.eclipse.aether.resolution.VersionRangeRequest
|
||||||
import org.eclipse.aether.resolution.VersionRangeResult
|
import org.eclipse.aether.resolution.VersionRangeResult
|
||||||
|
|
||||||
|
@ -32,45 +30,38 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
fun isRangeVersion(id: String) = id.contains(",")
|
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 dependencyRequest = DependencyRequest(createCollectRequest(id, scope), filter)
|
||||||
val result = system.resolveDependencies(session, dependencyRequest)
|
val result = system.resolveDependencies(session, dependencyRequest)
|
||||||
|
|
||||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||||
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
||||||
return result.root
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null)
|
fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null)
|
||||||
= resolve(artifactToId(artifact), scope, filter)
|
= resolve(artifactToId(artifact), scope, filter)
|
||||||
|
|
||||||
fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : List<String> {
|
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 =
|
val children =
|
||||||
root.children.filter {
|
rr.root.children.filter {
|
||||||
filter == null || filter.accept(DefaultDependencyNode(it.dependency), emptyList())
|
filter == null || filter.accept(DefaultDependencyNode(it.dependency), emptyList())
|
||||||
}.filter {
|
}.filter {
|
||||||
it.dependency.scope != Scope.SYSTEM.scope
|
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)
|
val thisId = artifactToId(it.artifact)
|
||||||
resolveToIds(thisId, scope, filter)
|
resolveToIds(thisId, scope, filter)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveToDependencies(id: String, scope: Scope? = null, filter: DependencyFilter? = null)
|
fun directDependencies(id: String, scope: Scope? = null): CollectResult?
|
||||||
: List<IClasspathDependency> {
|
= system.collectDependencies(session, createCollectRequest(id, scope))
|
||||||
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(artifact: Artifact, scope: Scope? = null): CollectResult?
|
fun directDependencies(artifact: Artifact, scope: Scope? = null): CollectResult?
|
||||||
= artifactToId(artifact).let { id ->
|
= artifactToId(artifact).let { id ->
|
||||||
|
@ -83,29 +74,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
return result
|
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.
|
* Create an IClasspathDependency from a Kobalt id.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.beust.kobalt.KobaltTest
|
||||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.BeforeClass
|
import org.testng.annotations.BeforeClass
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
@ -150,10 +151,9 @@ class DownloadTest @Inject constructor(
|
||||||
// This id has a parent pom which defines moshi version to be 1.1.0. Make sure that this
|
// This id has a parent pom which defines moshi version to be 1.1.0. Make sure that this
|
||||||
// version is being fetched instead of moshi:1.2.0-SNAPSHOT (which gets discarded anyway
|
// version is being fetched instead of moshi:1.2.0-SNAPSHOT (which gets discarded anyway
|
||||||
// since snapshots are not allowed to be returned when looking up a versionless id)
|
// since snapshots are not allowed to be returned when looking up a versionless id)
|
||||||
val host = HostConfig("http://repository.jetbrains.com/all/")
|
|
||||||
val id = "com.squareup.moshi:moshi:1.1.0"
|
val id = "com.squareup.moshi:moshi:1.1.0"
|
||||||
val dr = resolver.resolve(id)
|
val artifact = resolver.resolveToArtifact(id)
|
||||||
Assert.assertEquals(dr.dependency.artifact.version, "1.1.0")
|
assertThat(artifact.version).isEqualTo("1.1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -47,11 +47,11 @@ class MavenResolverTest {
|
||||||
|
|
||||||
@Test(dataProvider = "rangeProvider")
|
@Test(dataProvider = "rangeProvider")
|
||||||
fun kobaltRangeVersion(id: String, expectedVersion: String) {
|
fun kobaltRangeVersion(id: String, expectedVersion: String) {
|
||||||
val result = resolver.resolve(id)
|
val artifact = resolver.resolveToArtifact(id)
|
||||||
assertThat(result.dependency.artifact.version).isEqualTo(expectedVersion)
|
assertThat(artifact.version).isEqualTo(expectedVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
fun aetherShouldNotIncludeOptionalDependencies() {
|
fun aetherShouldNotIncludeOptionalDependencies() {
|
||||||
val artifactResults = resolve("com.squareup.retrofit2:converter-jackson:jar:2.1.0")
|
val artifactResults = resolve("com.squareup.retrofit2:converter-jackson:jar:2.1.0")
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class MavenResolverTest {
|
||||||
assertThat(artifactResults.none { it.toString().contains("android") })
|
assertThat(artifactResults.none { it.toString().contains("android") })
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
fun kobaltAetherShouldNotIncludeOptionalDependencies() {
|
fun kobaltAetherShouldNotIncludeOptionalDependencies() {
|
||||||
val dep = resolver.create("com.squareup.retrofit2:converter-jackson:jar:2.1.0", optional = false)
|
val dep = resolver.create("com.squareup.retrofit2:converter-jackson:jar:2.1.0", optional = false)
|
||||||
val closure = dependencyManager.transitiveClosure(listOf(dep))
|
val closure = dependencyManager.transitiveClosure(listOf(dep))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue