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
* 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)
/**
@ -147,14 +148,36 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
} else {
val dep = SimpleDep(mavenId)
// Try to find the jar file
val attemptPaths = listOf(dep.toJarFile(dep.version), dep.toAarFile(dep.version),
dep.toPomFile(dep.version))
val depPomFile = 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 )} +
attemptPaths.map { repo.copy(url = repo.url + File(it).parentFile.path.replace("\\", "/")) }
val firstFound = attemptUrls.map { Kurl(it)}.firstOrNull { it.exists }
log(3, "Result for $repoUrl for $id: $firstFound")
return listOf(RepoResult(repo, Version.of(dep.version), firstFound?.hostInfo?.url))
if (firstFound != null) {
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()
}
}
}
}