1
0
Fork 0
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:
Cedric Beust 2017-04-01 13:42:09 -07:00
parent 53924366ba
commit b011abc13b
2 changed files with 27 additions and 8 deletions

View file

@ -20,6 +20,7 @@ import org.eclipse.aether.resolution.DependencyRequest
import org.eclipse.aether.resolution.DependencyResult 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
import java.util.*
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
val args: Args, 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 fun resolveToArtifact(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : Artifact
= resolve(id, scope, filter).root.artifact = resolve(id, scope, filter).root.artifact
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null): DependencyResult { fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope), filter) repos: List<String> = emptyList()): DependencyResult {
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), 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 },
@ -90,11 +92,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
private val system = Booter.newRepositorySystem() private val system = Booter.newRepositorySystem()
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus) 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> private val kobaltRepositories: List<RemoteRepository>
get() = Kobalt.repos.map { get() = Kobalt.repos.map {
RemoteRepository.Builder(null, "default", it.url) createRepo(it.url).let { repository ->
// .setSnapshotPolicy(RepositoryPolicy(false, null, null))
.build().let { repository ->
val proxyConfigs = settings.proxyConfigs ?: return@map repository val proxyConfigs = settings.proxyConfigs ?: return@map repository
RemoteRepository.Builder(repository).apply { RemoteRepository.Builder(repository).apply {
setProxy(proxyConfigs.getProxy(repository.protocol)?.toAetherProxy()) 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)) val allIds = arrayListOf(MavenId.toMavenId(id))
if (args.downloadSources) { if (args.downloadSources) {
listOf("sources", "javadoc").forEach { listOf("sources", "javadoc").forEach {
@ -112,9 +116,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
allIds.add(sourceArtifact.toString()) allIds.add(sourceArtifact.toString())
} }
} }
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope) root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
repositories = kobaltRepositories repositories = kobaltRepositories + repos.map { createRepo(it) }
} }
} }

View file

@ -16,6 +16,7 @@ import org.eclipse.aether.graph.Dependency
import org.eclipse.aether.repository.RemoteRepository import org.eclipse.aether.repository.RemoteRepository
import org.eclipse.aether.resolution.ArtifactResult import org.eclipse.aether.resolution.ArtifactResult
import org.eclipse.aether.resolution.DependencyRequest import org.eclipse.aether.resolution.DependencyRequest
import org.eclipse.aether.resolution.DependencyResolutionException
import org.testng.annotations.DataProvider import org.testng.annotations.DataProvider
import org.testng.annotations.Guice import org.testng.annotations.Guice
import org.testng.annotations.Test import org.testng.annotations.Test
@ -68,6 +69,21 @@ class MavenResolverTest {
assertThat(closure.none { it.toString().contains("android") }) 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> { private fun resolve(id: String): List<ArtifactResult> {
val system = Booter.newRepositorySystem() val system = Booter.newRepositorySystem()
val session = Booter.newRepositorySystemSession(system, val session = Booter.newRepositorySystemSession(system,