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

Support for container poms.

Fix #132.
This commit is contained in:
Cedric Beust 2016-02-27 10:28:45 -08:00
parent 4bfe42545e
commit ecbb7ba732
2 changed files with 40 additions and 5 deletions

View file

@ -25,7 +25,8 @@ import javax.xml.xpath.XPathFactory
* Find the repo that contains the given dependency among a list of repos. Searches are performed in parallel and * Find the repo that contains the given dependency among a list of repos. Searches are performed in parallel and
* cached so we never make a network call for the same dependency more than once. * cached so we never make a network call for the same dependency more than once.
*/ */
class RepoFinder @Inject constructor(val executors: KobaltExecutors) { class RepoFinder @Inject constructor(val executors: KobaltExecutors, val localRepo: LocalRepo,
val pomFactory: Pom.IFactory) {
fun findCorrectRepo(id: String) = FOUND_REPOS.get(id) fun findCorrectRepo(id: String) = FOUND_REPOS.get(id)
/** /**
@ -147,14 +148,36 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
} else { } else {
val dep = SimpleDep(mavenId) val dep = SimpleDep(mavenId)
// Try to find the jar file // Try to find the jar file
val attemptPaths = listOf(dep.toJarFile(dep.version), dep.toAarFile(dep.version), val depPomFile = dep.toPomFile(dep.version)
dep.toPomFile(dep.version)) val attemptPaths = listOf(dep.toJarFile(dep.version), dep.toAarFile(dep.version), depPomFile)
val attemptUrls = attemptPaths.map { repo.copy(url = repo.url + it )} + val attemptUrls = attemptPaths.map { repo.copy(url = repo.url + it )} +
attemptPaths.map { repo.copy(url = repo.url + File(it).parentFile.path.replace("\\", "/")) } attemptPaths.map { repo.copy(url = repo.url + File(it).parentFile.path.replace("\\", "/")) }
val firstFound = attemptUrls.map { Kurl(it)}.firstOrNull { it.exists } val firstFound = attemptUrls.map { Kurl(it)}.firstOrNull { it.exists }
log(3, "Result for $repoUrl for $id: $firstFound") if (firstFound != null) {
return listOf(RepoResult(repo, Version.of(dep.version), firstFound?.hostInfo?.url)) val url = firstFound.hostInfo.url
if (url.endsWith("ar")) {
log(3, "Result for $repoUrl for $id: $firstFound")
return listOf(RepoResult(repo, Version.of(dep.version), firstFound.hostInfo.url))
} else if (url.endsWith(".pom")) {
log(2, "Found container pom: " + firstFound)
File(localRepo.toFullPath(depPomFile)).let { pomFile ->
pomFile.parentFile.mkdirs()
Kurl(HostConfig(url)).toFile(pomFile)
val dependencies = pomFactory.create(id, pomFile).dependencies
val result = arrayListOf<RepoResult>()
dependencies.map { it.id }.forEach {
result.addAll(RepoFinderCallable(it, repo).call())
}
return result
}
} else {
return listOf(RepoResult(repo, Version.of(dep.version), firstFound.hostInfo.url))
}
} else {
log(2, "Couldn't find " + dep)
return emptyList()
}
} }
} }
} }

View file

@ -21,6 +21,7 @@ import kotlin.properties.Delegates
class DownloadTest @Inject constructor( class DownloadTest @Inject constructor(
val depFactory: DepFactory, val depFactory: DepFactory,
val localRepo: LocalRepo, val localRepo: LocalRepo,
val mdFactory: MavenDependency.IFactory,
val executors: KobaltExecutors) : KobaltTest() { val executors: KobaltExecutors) : KobaltTest() {
private var executor: ExecutorService by Delegates.notNull() private var executor: ExecutorService by Delegates.notNull()
@ -140,5 +141,16 @@ class DownloadTest @Inject constructor(
val id = "http://jitpack.io/com/github/JakeWharton/RxBinding/rxbinding-kotlin/542cd7e8a4/rxbinding-kotlin-542cd7e8a4.aar" val id = "http://jitpack.io/com/github/JakeWharton/RxBinding/rxbinding-kotlin/542cd7e8a4/rxbinding-kotlin-542cd7e8a4.aar"
Assert.assertTrue(Kurl(HostConfig(id)).exists) Assert.assertTrue(Kurl(HostConfig(id)).exists)
} }
@Test
fun containerPomTest() {
File(localRepo.toFullPath("nl/komponents/kovenant")).deleteRecursively()
val dep = mdFactory.create(MavenId.create("nl.komponents.kovenant:kovenant:3.0.0"), executor = executor,
downloadSources = false, downloadJavadocs = false)
dep.directDependencies().forEach {
Assert.assertTrue(it.jarFile.get().exists(), "Dependency was not downloaded: $it")
}
}
} }