mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
parent
4bfe42545e
commit
ecbb7ba732
2 changed files with 40 additions and 5 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import kotlin.properties.Delegates
|
|||
class DownloadTest @Inject constructor(
|
||||
val depFactory: DepFactory,
|
||||
val localRepo: LocalRepo,
|
||||
val mdFactory: MavenDependency.IFactory,
|
||||
val executors: KobaltExecutors) : KobaltTest() {
|
||||
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"
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue