mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Improve aar support.
This commit is contained in:
parent
9b94114021
commit
e87438910f
6 changed files with 72 additions and 40 deletions
|
@ -4,7 +4,6 @@ import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.maven.MavenId
|
import com.beust.kobalt.maven.MavenId
|
||||||
import com.beust.kobalt.maven.RepoFinder
|
import com.beust.kobalt.maven.RepoFinder
|
||||||
import com.beust.kobalt.maven.SimpleDep
|
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.Node
|
import com.beust.kobalt.misc.Node
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
|
@ -36,9 +35,8 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val loca
|
||||||
val seen = hashSetOf(id)
|
val seen = hashSetOf(id)
|
||||||
root.addChildren(findChildren(root, seen))
|
root.addChildren(findChildren(root, seen))
|
||||||
|
|
||||||
val simpleDep = SimpleDep(mavenId)
|
val url = repoResult.hostConfig.url + repoResult.path
|
||||||
val url = repoResult.hostConfig.url + simpleDep.toJarFile(repoResult)
|
val localFile = localRepo.toFullPath(repoResult.path!!)
|
||||||
val localFile = localRepo.toFullPath(simpleDep.toJarFile(repoResult))
|
|
||||||
AsciiArt.logBox(listOf(id, url, localFile).map { " $it" }, {s -> println(s) })
|
AsciiArt.logBox(listOf(id, url, localFile).map { " $it" }, {s -> println(s) })
|
||||||
|
|
||||||
display(root.children)
|
display(root.children)
|
||||||
|
|
|
@ -28,8 +28,12 @@ import javax.xml.xpath.XPathFactory
|
||||||
class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
|
class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
|
||||||
fun findCorrectRepo(id: String) = FOUND_REPOS.get(id)
|
fun findCorrectRepo(id: String) = FOUND_REPOS.get(id)
|
||||||
|
|
||||||
data class RepoResult(val hostConfig: HostConfig, val found: Boolean, val version: Version? = null,
|
data class RepoResult(val hostConfig: HostConfig, val version: Version? = null,
|
||||||
val hasJar: Boolean = true, val snapshotVersion: Version? = null)
|
val archiveUrl: String? = null, val snapshotVersion: Version? = null) {
|
||||||
|
val found = archiveUrl != null
|
||||||
|
|
||||||
|
val path = archiveUrl?.substring(hostConfig.url.length)
|
||||||
|
}
|
||||||
|
|
||||||
private val FOUND_REPOS: LoadingCache<String, RepoResult> = CacheBuilder.newBuilder()
|
private val FOUND_REPOS: LoadingCache<String, RepoResult> = CacheBuilder.newBuilder()
|
||||||
.build(object : CacheLoader<String, RepoResult>() {
|
.build(object : CacheLoader<String, RepoResult>() {
|
||||||
|
@ -69,7 +73,7 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
|
||||||
results.sort({ left, right -> right.version!!.compareTo(left.version!!) })
|
results.sort({ left, right -> right.version!!.compareTo(left.version!!) })
|
||||||
return results[0]
|
return results[0]
|
||||||
} else {
|
} else {
|
||||||
return RepoResult(HostConfig(""), false, Version.of(id))
|
return RepoResult(HostConfig(""), Version.of(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +92,12 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
|
||||||
if (mavenId.version == null) {
|
if (mavenId.version == null) {
|
||||||
val ud = UnversionedDep(groupId, artifactId)
|
val ud = UnversionedDep(groupId, artifactId)
|
||||||
val isLocal = repoUrl.startsWith(FileDependency.PREFIX_FILE)
|
val isLocal = repoUrl.startsWith(FileDependency.PREFIX_FILE)
|
||||||
val foundVersion = findCorrectVersionRelease(ud.toMetadataXmlPath(false, isLocal), repoUrl)
|
val path = ud.toMetadataXmlPath(false, isLocal)
|
||||||
|
val foundVersion = findCorrectVersionRelease(path, repoUrl)
|
||||||
if (foundVersion != null) {
|
if (foundVersion != null) {
|
||||||
return RepoResult(repo, true, Version.of(foundVersion))
|
return RepoResult(repo, Version.of(foundVersion), path)
|
||||||
} else {
|
} else {
|
||||||
return RepoResult(repo, false)
|
return RepoResult(repo)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val version = Version.of(mavenId.version)
|
val version = Version.of(mavenId.version)
|
||||||
|
@ -107,35 +112,48 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
|
||||||
val url = repoUrl + metadataXmlPath
|
val url = repoUrl + metadataXmlPath
|
||||||
val kurl = Kurl(HostConfig(url))
|
val kurl = Kurl(HostConfig(url))
|
||||||
val found = kurl.exists
|
val found = kurl.exists
|
||||||
return RepoResult(repo, found, version, true /* hasJar, potential bug here */,
|
return RepoResult(repo, version, url, snapshotVersion)
|
||||||
snapshotVersion)
|
|
||||||
} else {
|
} else {
|
||||||
return RepoResult(repo, false)
|
return RepoResult(repo)
|
||||||
}
|
}
|
||||||
} else if (version.isRangedVersion() ) {
|
} else if (version.isRangedVersion() ) {
|
||||||
val foundVersion = findRangedVersion(SimpleDep(mavenId), repoUrl)
|
val foundVersion = findRangedVersion(SimpleDep(mavenId), repoUrl)
|
||||||
if (foundVersion != null) {
|
if (foundVersion != null) {
|
||||||
return RepoResult(repo, true, foundVersion)
|
return RepoResult(repo, foundVersion)
|
||||||
} else {
|
} else {
|
||||||
return RepoResult(repo, false)
|
return RepoResult(repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val dep = SimpleDep(mavenId)
|
val dep = SimpleDep(mavenId)
|
||||||
// Try to find the jar file
|
// Try to find the jar file
|
||||||
val urlJar = repo.copy(url = repo.url + dep.toJarFile(dep.version))
|
val attemptPaths = listOf(dep.toJarFile(dep.version), dep.toAarFile(dep.version))
|
||||||
val hasJar = Kurl(urlJar).exists
|
val attemptUrls = attemptPaths.map { repo.copy(url = repo.url + it )} +
|
||||||
val found =
|
attemptPaths.map { repo.copy(url = repo.url + File(it).parentFile.path.replace("\\", "/")) }
|
||||||
if (! hasJar) {
|
|
||||||
// No jar, try to find the directory
|
val firstFound = attemptUrls.map { Kurl(it)}.firstOrNull { it.exists }
|
||||||
val url = repo.copy(url = repoUrl
|
// val urlJar = repo.copy(url = repo.url + dep.toJarFile(dep.version))
|
||||||
+ File(dep.toJarFile(dep.version)).parentFile.path.replace("\\", "/"))
|
// var foundPath = ""
|
||||||
Kurl(url).exists
|
// if (Kurl(urlJar).exists) {
|
||||||
} else {
|
// foundPath = dep.toJarFile(dep.version)
|
||||||
true
|
// } else {
|
||||||
}
|
// val urlAar = repo.copy(url = repo.url + dep.toAarFile(dep.version))
|
||||||
log(2, "Result for $repoUrl for $id: $found")
|
// if (Kurl(urlAar).exists) {
|
||||||
return RepoResult(repo, found, Version.of(dep.version), hasJar)
|
// foundPath = dep.toAarFile(dep.version)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// val hasJar = true
|
||||||
|
// val found =
|
||||||
|
// if (! hasJar) {
|
||||||
|
// // No jar, try to find the directory
|
||||||
|
// val url = repo.copy(url = repoUrl
|
||||||
|
// + File(dep.toJarFile(dep.version)).parentFile.path.replace("\\", "/"))
|
||||||
|
// Kurl(url).exists
|
||||||
|
// } else {
|
||||||
|
// true
|
||||||
|
// }
|
||||||
|
log(2, "Result for $repoUrl for $id: $firstFound")
|
||||||
|
return RepoResult(repo, Version.of(dep.version), firstFound?.hostInfo?.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId
|
||||||
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, ".pom")
|
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, ".pom")
|
||||||
|
|
||||||
fun toJarFile(v: String = version) = toFile(Version.of(v), suffix)
|
fun toJarFile(v: String = version) = toFile(Version.of(v), suffix)
|
||||||
|
fun toAarFile(v: String = version) = toFile(Version.of(v), ".aar")
|
||||||
|
|
||||||
fun toPomFileName() = "$artifactId-$version.pom"
|
fun toPomFileName() = "$artifactId-$version.pom"
|
||||||
|
|
||||||
|
|
|
@ -28,17 +28,18 @@ public class MavenDependency @Inject constructor(mavenId: MavenId,
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val jar = File(localRepo.toFullPath(toJarFile(version)))
|
val jar = File(localRepo.toFullPath(toJarFile(version)))
|
||||||
|
val aar = File(localRepo.toFullPath(toAarFile(version)))
|
||||||
val pom = File(localRepo.toFullPath(toPomFile(version)))
|
val pom = File(localRepo.toFullPath(toPomFile(version)))
|
||||||
if (pom.exists()) {
|
if (pom.exists() && (jar.exists() || aar.exists())) {
|
||||||
jarFile = CompletedFuture(jar)
|
jarFile = CompletedFuture(if (jar.exists()) jar else aar)
|
||||||
pomFile = CompletedFuture(pom)
|
pomFile = CompletedFuture(pom)
|
||||||
} else {
|
} else {
|
||||||
val repoResult = repoFinder.findCorrectRepo(mavenId.toId)
|
val repoResult = repoFinder.findCorrectRepo(mavenId.toId)
|
||||||
if (repoResult.found) {
|
if (repoResult.found) {
|
||||||
|
val path = if (jar.exists()) jar.absolutePath else aar.absolutePath
|
||||||
jarFile =
|
jarFile =
|
||||||
if (repoResult.hasJar) {
|
if (repoResult.archiveUrl != null) {
|
||||||
downloadManager.download(HostConfig(url = repoResult.hostConfig.url + toJarFile(repoResult)),
|
downloadManager.download(HostConfig(url = repoResult.archiveUrl), path, executor)
|
||||||
jar.absolutePath, executor)
|
|
||||||
} else {
|
} else {
|
||||||
CompletedFuture(File("nonexistentFile")) // will be filtered out
|
CompletedFuture(File("nonexistentFile")) // will be filtered out
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,9 @@ public class DownloadTest @Inject constructor(
|
||||||
// For now, just hardcoding the result we should have received
|
// For now, just hardcoding the result we should have received
|
||||||
// val repoResult = repoFinder.findCorrectRepo(id)
|
// val repoResult = repoFinder.findCorrectRepo(id)
|
||||||
|
|
||||||
val repoResult = RepoFinder.RepoResult(HostConfig("http://repository.jetbrains.com/all/"),
|
val hc = HostConfig("http://repository.jetbrains.com/all/")
|
||||||
true, Version.of("0.1-SNAPSHOT"), true, Version("0.1-SNAPSHOT", "20151011.112011-29"))
|
val repoResult = RepoFinder.RepoResult(hc,
|
||||||
|
Version.of("0.1-SNAPSHOT"), hc.url, Version("0.1-SNAPSHOT", "20151011.112011-29"))
|
||||||
|
|
||||||
val jarFile = dep.toJarFile(repoResult)
|
val jarFile = dep.toJarFile(repoResult)
|
||||||
val url = repoResult.hostConfig.url + jarFile
|
val url = repoResult.hostConfig.url + jarFile
|
||||||
|
|
|
@ -4,19 +4,18 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.TestModule
|
import com.beust.kobalt.TestModule
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.DependencyExecutor
|
import com.beust.kobalt.misc.DependencyExecutor
|
||||||
import com.beust.kobalt.app.MainModule
|
|
||||||
import com.google.inject.Guice
|
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Test
|
||||||
@org.testng.annotations.Guice(modules = arrayOf(TestModule::class))
|
@org.testng.annotations.Guice(modules = arrayOf(TestModule::class))
|
||||||
public class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
||||||
@DependencyExecutor val executor: ExecutorService, val args: Args){
|
@DependencyExecutor val executor: ExecutorService, val args: Args){
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public fun mavenMetadata() {
|
fun mavenMetadata() {
|
||||||
val dep = MavenDependency.create("org.codehaus.groovy:groovy-all:")
|
val dep = MavenDependency.create("org.codehaus.groovy:groovy-all:")
|
||||||
// Note: this test might fail if a new version of Groovy gets uploaded, need
|
// Note: this test might fail if a new version of Groovy gets uploaded, need
|
||||||
// to find a stable (i.e. abandoned) package
|
// to find a stable (i.e. abandoned) package
|
||||||
|
@ -24,9 +23,23 @@ public class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
public fun metadataForSnapshots() {
|
fun metadataForSnapshots() {
|
||||||
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", executor)
|
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", executor)
|
||||||
.jarFile
|
.jarFile
|
||||||
Assert.assertTrue(jar.get().exists())
|
Assert.assertTrue(jar.get().exists())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resolveAarWithVersion() {
|
||||||
|
val repoResult = repoFinder.findCorrectRepo("com.jakewharton.timber:timber:4.1.0")
|
||||||
|
with(repoResult) {
|
||||||
|
Assert.assertEquals(path, "com/jakewharton/timber/timber/4.1.0/timber-4.1.0.aar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fun resolveAarWithoutVersion() {
|
||||||
|
// val repoResult = repoFinder.findCorrectRepo("com.jakewharton.timber:timber:")
|
||||||
|
// with(repoResult) {
|
||||||
|
// Assert.assertEquals(path, "com/jakewharton/timber/timber/4.1.0/timber-4.1.0.aar")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue