mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
AetherDependency.
This commit is contained in:
parent
930caf73bf
commit
40a42b4312
2 changed files with 82 additions and 35 deletions
|
@ -4,6 +4,7 @@ import com.beust.kobalt.HostConfig
|
|||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.misc.Version
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import kotlinx.dom.asElementList
|
||||
|
@ -21,7 +22,8 @@ import javax.xml.xpath.XPathFactory
|
|||
* http://repo1.maven.org/maven2/nl/komponents/kovenant/kovenant/3.0.0/
|
||||
*/
|
||||
class RepoFinderCallable @Inject constructor(@Assisted val id: String,
|
||||
@Assisted val repo: HostConfig, val localRepo: LocalRepo, val pomFactory: Pom.IFactory)
|
||||
@Assisted val repo: HostConfig, val localRepo: LocalRepo, val pomFactory: Pom.IFactory,
|
||||
val dependencyManager: DependencyManager)
|
||||
: Callable<List<RepoFinder .RepoResult>> {
|
||||
|
||||
interface IFactory {
|
||||
|
@ -91,10 +93,16 @@ class RepoFinderCallable @Inject constructor(@Assisted val id: String,
|
|||
File(localRepo.toFullPath(depPomFile)).let { pomFile ->
|
||||
pomFile.parentFile.mkdirs()
|
||||
Kurl(HostConfig(url)).toFile(pomFile)
|
||||
val dependencies = Pom2(pomFile).pom.dependencies
|
||||
val pom2 = Pom2.parse(pomFile, dependencyManager).value
|
||||
val result = arrayListOf<RepoFinder.RepoResult>()
|
||||
dependencies.map { it.id }.forEach {
|
||||
result.addAll(RepoFinderCallable(it, repo, localRepo, pomFactory).call())
|
||||
if (pom2 != null) {
|
||||
val dependencies = pom2.pomProject.dependencies
|
||||
dependencies.map { it.id(pom2) }.forEach {
|
||||
result.addAll(RepoFinderCallable(it, repo, localRepo, pomFactory,
|
||||
dependencyManager).call())
|
||||
}
|
||||
} else {
|
||||
warn("Couldn't parse $pomFile")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,25 +1,33 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.google.inject.Inject
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.maven.CompletedFuture
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
import com.beust.kobalt.misc.log
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
import org.eclipse.aether.artifact.DefaultArtifact
|
||||
import org.eclipse.aether.collection.CollectRequest
|
||||
import org.eclipse.aether.collection.CollectResult
|
||||
import org.eclipse.aether.graph.Dependency
|
||||
import org.eclipse.aether.graph.DependencyNode
|
||||
import org.eclipse.aether.resolution.ArtifactResult
|
||||
import org.eclipse.aether.resolution.DependencyRequest
|
||||
import org.eclipse.aether.util.artifact.JavaScopes
|
||||
import org.eclipse.aether.util.filter.DependencyFilterUtils
|
||||
import java.io.File
|
||||
import java.util.concurrent.Future
|
||||
|
||||
class Aether @Inject constructor(val settings: KobaltSettings){
|
||||
fun call3() {
|
||||
class Aether(val localRepo: File = File(homeDir(".kobalt/repository"))) {
|
||||
fun transitiveDependencies(id: String): List<ArtifactResult>? {
|
||||
println("------------------------------------------------------------")
|
||||
|
||||
val system = Booter.newRepositorySystem()
|
||||
|
||||
val session = Booter.newRepositorySystemSession(system, File(settings.localRepo))
|
||||
val session = Booter.newRepositorySystemSession(system, localRepo)
|
||||
|
||||
val artifact = DefaultArtifact("org.testng:testng:6.9.9")
|
||||
val artifact = DefaultArtifact(id)
|
||||
|
||||
val classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE)
|
||||
|
||||
|
@ -29,35 +37,66 @@ class Aether @Inject constructor(val settings: KobaltSettings){
|
|||
|
||||
val dependencyRequest = DependencyRequest(collectRequest, classpathFlter)
|
||||
|
||||
val artifactResults = system.resolveDependencies(session, dependencyRequest).artifactResults
|
||||
val result = system.resolveDependencies(session, dependencyRequest).artifactResults
|
||||
|
||||
for (artifactResult in artifactResults) {
|
||||
println(artifactResult.artifact.toString() + " resolved to " + artifactResult.artifact.file)
|
||||
if (KobaltLogger.LOG_LEVEL > 1) {
|
||||
for (artifactResult in result) {
|
||||
log(2, artifactResult.artifact.toString() + " resolved to " + artifactResult.artifact.file)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// fun call2() {
|
||||
// val request = ArtifactRequest().apply {
|
||||
// artifact = DefaultArtifact(id)
|
||||
// repositories = listOf(RemoteRepository("Maven", "", repo.url))
|
||||
// }
|
||||
// val repoSystem = DefaultRepositorySystem().apply {
|
||||
// val artifactResolver = DefaultArtifactResolver().apply {
|
||||
// setRemoteRepositoryManager(DefaultRemoteRepositoryManager().apply {
|
||||
// addRepositoryConnectorFactory(WagonRepositoryConnectorFactory())
|
||||
// })
|
||||
// setVersionResolver {
|
||||
// p0, request -> VersionResult(request)
|
||||
// }
|
||||
// }
|
||||
// setArtifactResolver(artifactResolver)
|
||||
// }
|
||||
// val session = DefaultRepositorySystemSession().apply {
|
||||
// localRepositoryManager = SimpleLocalRepositoryManager(File("/Users/beust/.aether"))
|
||||
// }
|
||||
// val artifact = repoSystem.resolveArtifact(session, request)
|
||||
// println("Artifact: " + artifact)
|
||||
// }
|
||||
fun directDependencies(id: String): CollectResult? {
|
||||
println("------------------------------------------------------------")
|
||||
|
||||
val system = Booter.newRepositorySystem()
|
||||
|
||||
val session = Booter.newRepositorySystemSession(system, localRepo)
|
||||
|
||||
val artifact = DefaultArtifact(id)
|
||||
|
||||
val classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE)
|
||||
|
||||
val collectRequest = CollectRequest()
|
||||
collectRequest.root = Dependency(artifact, JavaScopes.COMPILE)
|
||||
collectRequest.repositories = Booter.newRepositories(Kobalt.repos.map { it.url })
|
||||
|
||||
val result = system.collectDependencies(session, collectRequest)
|
||||
val root = result.root
|
||||
val icp = AetherDependency(root)
|
||||
println("Dep: " + root)
|
||||
return result
|
||||
}
|
||||
|
||||
class AetherDependency(val root: DependencyNode): IClasspathDependency {
|
||||
override val id: String = toId(root.artifact)
|
||||
|
||||
private fun toId(a: Artifact) = with(a) {
|
||||
groupId + ":" + artifactId + ":" + version
|
||||
}
|
||||
|
||||
override val jarFile: Future<File>
|
||||
get() = CompletedFuture(root.artifact.file)
|
||||
|
||||
override fun toMavenDependencies() = let { md ->
|
||||
org.apache.maven.model.Dependency().apply {
|
||||
root.artifact.let { md ->
|
||||
groupId = md.groupId
|
||||
artifactId = md.artifactId
|
||||
version = md.version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun directDependencies() = root.children.map { AetherDependency(it) }
|
||||
|
||||
override val shortId = root.artifact.groupId + ":" + root.artifact.artifactId
|
||||
}
|
||||
}
|
||||
|
||||
fun main(argv: Array<String>) {
|
||||
val dd = Aether().directDependencies("org.testng:testng:6.9.9")
|
||||
println("DD: " + dd)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue