diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt index a7e22839..df20b05e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt @@ -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() + 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() + } } } } diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index de488f91..25a560e7 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -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") + } + } + }