mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Resolve snapshot repos correctly.
Fixes https://github.com/cbeust/kobalt/issues/377.
This commit is contained in:
parent
53924366ba
commit
b011abc13b
2 changed files with 27 additions and 8 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.aether.resolution.DependencyRequest
|
|||
import org.eclipse.aether.resolution.DependencyResult
|
||||
import org.eclipse.aether.resolution.VersionRangeRequest
|
||||
import org.eclipse.aether.resolution.VersionRangeResult
|
||||
import java.util.*
|
||||
|
||||
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||
val args: Args,
|
||||
|
@ -35,8 +36,9 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
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)
|
||||
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
|
||||
repos: List<String> = emptyList()): DependencyResult {
|
||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
||||
val result = system.resolveDependencies(session, dependencyRequest)
|
||||
|
||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||
|
@ -90,11 +92,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
private val system = Booter.newRepositorySystem()
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
||||
|
||||
private fun createRepo(url: String) = RemoteRepository.Builder(Random().nextInt().toString(), "default", url)
|
||||
.build()
|
||||
|
||||
private val kobaltRepositories: List<RemoteRepository>
|
||||
get() = Kobalt.repos.map {
|
||||
RemoteRepository.Builder(null, "default", it.url)
|
||||
// .setSnapshotPolicy(RepositoryPolicy(false, null, null))
|
||||
.build().let { repository ->
|
||||
createRepo(it.url).let { repository ->
|
||||
val proxyConfigs = settings.proxyConfigs ?: return@map repository
|
||||
RemoteRepository.Builder(repository).apply {
|
||||
setProxy(proxyConfigs.getProxy(repository.protocol)?.toAetherProxy())
|
||||
|
@ -102,7 +105,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
}
|
||||
}
|
||||
|
||||
private fun createCollectRequest(id: String, scope: Scope? = null) = CollectRequest().apply {
|
||||
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
|
||||
= CollectRequest().apply {
|
||||
val allIds = arrayListOf(MavenId.toMavenId(id))
|
||||
if (args.downloadSources) {
|
||||
listOf("sources", "javadoc").forEach {
|
||||
|
@ -112,9 +116,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
allIds.add(sourceArtifact.toString())
|
||||
}
|
||||
}
|
||||
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
||||
|
||||
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
||||
repositories = kobaltRepositories
|
||||
repositories = kobaltRepositories + repos.map { createRepo(it) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.aether.graph.Dependency
|
|||
import org.eclipse.aether.repository.RemoteRepository
|
||||
import org.eclipse.aether.resolution.ArtifactResult
|
||||
import org.eclipse.aether.resolution.DependencyRequest
|
||||
import org.eclipse.aether.resolution.DependencyResolutionException
|
||||
import org.testng.annotations.DataProvider
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
|
@ -68,6 +69,21 @@ class MavenResolverTest {
|
|||
assertThat(closure.none { it.toString().contains("android") })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldResolveSnapshots() {
|
||||
try {
|
||||
// Should throw
|
||||
resolver.resolve("org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT")
|
||||
} catch(ex: DependencyResolutionException) {
|
||||
// Success. Note: run the failing test first, because once the resolve succeeds, its
|
||||
// results are cached in the local repo.
|
||||
}
|
||||
|
||||
// Should succeed
|
||||
resolver.resolve("org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT",
|
||||
repos = listOf("https://hub.spigotmc.org/nexus/content/repositories/snapshots"))
|
||||
}
|
||||
|
||||
private fun resolve(id: String): List<ArtifactResult> {
|
||||
val system = Booter.newRepositorySystem()
|
||||
val session = Booter.newRepositorySystemSession(system,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue