mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 07:57:12 -07:00
* fix sources and javadoc resolution. relates to #372
This commit is contained in:
parent
23bbcd4d84
commit
c54d4c5b2b
2 changed files with 34 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.maven.aether
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.api.Dependencies
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
|
@ -7,10 +8,12 @@ import com.beust.kobalt.maven.CompletedFuture
|
|||
import com.beust.kobalt.misc.StringVersion
|
||||
import com.beust.kobalt.misc.warn
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
import org.eclipse.aether.artifact.DefaultArtifact
|
||||
import org.eclipse.aether.resolution.DependencyResolutionException
|
||||
import java.io.File
|
||||
import java.util.concurrent.Future
|
||||
|
||||
class AetherDependency(val artifact: Artifact, override val optional: Boolean = false)
|
||||
class AetherDependency(val artifact: Artifact, override val optional: Boolean = false, val args: Args? = null)
|
||||
: IClasspathDependency, Comparable<AetherDependency> {
|
||||
val aether: KobaltMavenResolver get() = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java)
|
||||
|
||||
|
@ -25,12 +28,37 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
|
|||
override val jarFile: Future<File>
|
||||
get() =
|
||||
if (artifact.file != null) {
|
||||
resolveSourcesIfNeeded()
|
||||
CompletedFuture(artifact.file)
|
||||
} else {
|
||||
val td = aether.resolve(artifact, null)
|
||||
resolveSourcesIfNeeded()
|
||||
val td = aether.resolve(artifact)
|
||||
CompletedFuture(td.root.artifact.file)
|
||||
}
|
||||
|
||||
private fun resolveSourcesIfNeeded() {
|
||||
if (args?.downloadSources ?: false) {
|
||||
artifact.toSourcesArtifact().let { sourcesArtifact ->
|
||||
if (sourcesArtifact.file == null) {
|
||||
try {
|
||||
aether.resolve(sourcesArtifact)
|
||||
} catch(e: DependencyResolutionException) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
artifact.toJavaDocArtifact().let { javadocArtifact ->
|
||||
if (javadocArtifact.file == null) {
|
||||
try {
|
||||
aether.resolve(javadocArtifact)
|
||||
} catch(e: DependencyResolutionException) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun toMavenDependencies(scope: String?) : org.apache.maven.model.Dependency {
|
||||
val passedScope = scope
|
||||
val op = this.optional
|
||||
|
@ -69,4 +97,7 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
|
|||
override fun equals(other: Any?) = if (other is AetherDependency) other.id == id else false
|
||||
|
||||
override fun toString() = id
|
||||
|
||||
fun Artifact.toSourcesArtifact() = DefaultArtifact(groupId, artifactId, "sources", extension, version)
|
||||
fun Artifact.toJavaDocArtifact() = DefaultArtifact(groupId, artifactId, "javadoc", extension, version)
|
||||
}
|
||||
|
|
|
@ -40,15 +40,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
repos: List<String> = emptyList()): DependencyResult {
|
||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
||||
val result = system.resolveDependencies(session, dependencyRequest)
|
||||
if (args.downloadSources) {
|
||||
listOf("sources", "javadoc").forEach {
|
||||
val artifact = DefaultArtifact(id)
|
||||
val sourceArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, it, artifact.extension,
|
||||
artifact.version)
|
||||
system.resolveDependencies(session, DependencyRequest(createCollectRequest(sourceArtifact, scope), filter))
|
||||
}
|
||||
}
|
||||
|
||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
||||
return result
|
||||
|
@ -95,7 +86,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
/**
|
||||
* Create an IClasspathDependency from a Kobalt id.
|
||||
*/
|
||||
fun create(id: String, optional: Boolean) = AetherDependency(DefaultArtifact(id), optional)
|
||||
fun create(id: String, optional: Boolean) = AetherDependency(DefaultArtifact(id), optional, args)
|
||||
|
||||
private val system = Booter.newRepositorySystem()
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
||||
|
@ -122,10 +113,4 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
||||
repositories = kobaltRepositories + repos.map { createRepo(it) }
|
||||
}
|
||||
|
||||
private fun createCollectRequest( artifact: DefaultArtifact, scope: Scope? = null) = CollectRequest().apply {
|
||||
dependencies = listOf(Dependency(artifact, scope?.scope))
|
||||
root = Dependency(artifact, scope?.scope)
|
||||
repositories = kobaltRepositories
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue