mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Merge pull request #374 from dmitry-zhuravlev/master
* download sources property propagation. relates to #372
This commit is contained in:
commit
1c27b9f1e4
4 changed files with 43 additions and 12 deletions
|
@ -117,6 +117,7 @@ val kobaltPluginApi = project {
|
||||||
"org.testng:testng:${Versions.testng}"
|
"org.testng:testng:${Versions.testng}"
|
||||||
)
|
)
|
||||||
exclude(*aether("impl", "spi", "util", "api"))
|
exclude(*aether("impl", "spi", "util", "api"))
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,6 +181,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
||||||
// "org.wasabi:wasabi:0.1.182"
|
// "org.wasabi:wasabi:0.1.182"
|
||||||
)
|
)
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +190,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
"org.assertj:assertj-core:3.4.1",
|
"org.assertj:assertj-core:3.4.1",
|
||||||
*mavenResolver("util")
|
*mavenResolver("util")
|
||||||
)
|
)
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-test:1.1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
assemble {
|
assemble {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.beust.kobalt.maven.aether
|
package com.beust.kobalt.maven.aether
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.Dependencies
|
import com.beust.kobalt.api.Dependencies
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Kobalt
|
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.StringVersion
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import org.eclipse.aether.artifact.Artifact
|
import org.eclipse.aether.artifact.Artifact
|
||||||
|
import org.eclipse.aether.artifact.DefaultArtifact
|
||||||
|
import org.eclipse.aether.resolution.DependencyResolutionException
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.Future
|
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> {
|
: IClasspathDependency, Comparable<AetherDependency> {
|
||||||
val aether: KobaltMavenResolver get() = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java)
|
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>
|
override val jarFile: Future<File>
|
||||||
get() =
|
get() =
|
||||||
if (artifact.file != null) {
|
if (artifact.file != null) {
|
||||||
|
resolveSourcesIfNeeded()
|
||||||
CompletedFuture(artifact.file)
|
CompletedFuture(artifact.file)
|
||||||
} else {
|
} else {
|
||||||
val td = aether.resolve(artifact, null)
|
resolveSourcesIfNeeded()
|
||||||
|
val td = aether.resolve(artifact)
|
||||||
CompletedFuture(td.root.artifact.file)
|
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 {
|
override fun toMavenDependencies(scope: String?) : org.apache.maven.model.Dependency {
|
||||||
val passedScope = scope
|
val passedScope = scope
|
||||||
val op = this.optional
|
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 equals(other: Any?) = if (other is AetherDependency) other.id == id else false
|
||||||
|
|
||||||
override fun toString() = id
|
override fun toString() = id
|
||||||
|
|
||||||
|
fun Artifact.toSourcesArtifact() = DefaultArtifact(groupId, artifactId, "sources", extension, version)
|
||||||
|
fun Artifact.toJavaDocArtifact() = DefaultArtifact(groupId, artifactId, "javadoc", extension, version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
repos: List<String> = emptyList()): DependencyResult {
|
repos: List<String> = emptyList()): DependencyResult {
|
||||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
||||||
val result = system.resolveDependencies(session, dependencyRequest)
|
val result = system.resolveDependencies(session, dependencyRequest)
|
||||||
|
|
||||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||||
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
||||||
return result
|
return result
|
||||||
|
@ -88,7 +87,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
/**
|
/**
|
||||||
* Create an IClasspathDependency from a Kobalt id.
|
* 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 system = Booter.newRepositorySystem()
|
||||||
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
||||||
|
@ -109,14 +108,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
|
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
|
||||||
= CollectRequest().apply {
|
= CollectRequest().apply {
|
||||||
val allIds = arrayListOf(MavenId.toMavenId(id))
|
val allIds = arrayListOf(MavenId.toMavenId(id))
|
||||||
if (args.downloadSources) {
|
|
||||||
listOf("sources", "javadoc").forEach {
|
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
||||||
val artifact = DefaultArtifact(id)
|
|
||||||
val sourceArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, it, artifact.extension,
|
|
||||||
artifact.version)
|
|
||||||
allIds.add(sourceArtifact.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
||||||
repositories = kobaltRepositories + repos.map { createRepo(HostConfig(it)) }
|
repositories = kobaltRepositories + repos.map { createRepo(HostConfig(it)) }
|
||||||
|
|
|
@ -26,6 +26,7 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
||||||
val PARAMETER_BUILD_FILE = "buildFile" // Deprecated
|
val PARAMETER_BUILD_FILE = "buildFile" // Deprecated
|
||||||
val PARAMETER_PROFILES = "profiles"
|
val PARAMETER_PROFILES = "profiles"
|
||||||
|
val PARAMETER_DOWNLOAD_SOURCES = "downloadSources"
|
||||||
|
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findProfiles(map: Map<String, List<String>>) = map[PARAMETER_PROFILES]?.getOrNull(0)
|
private fun findProfiles(map: Map<String, List<String>>) = map[PARAMETER_PROFILES]?.getOrNull(0)
|
||||||
|
private fun findDownloadSources(map: Map<String, List<String>>) = map[PARAMETER_DOWNLOAD_SOURCES]?.getOrNull(0)?.toBoolean() ?: false
|
||||||
|
|
||||||
private fun findBuildFile(map: Map<String, List<String>>) : BuildSources? {
|
private fun findBuildFile(map: Map<String, List<String>>) : BuildSources? {
|
||||||
val projectRoot = map[PARAMETER_PROJECT_ROOT]
|
val projectRoot = map[PARAMETER_PROJECT_ROOT]
|
||||||
|
@ -66,6 +68,7 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
val parameterMap = s.upgradeRequest.parameterMap
|
val parameterMap = s.upgradeRequest.parameterMap
|
||||||
val buildSources = findBuildFile(parameterMap)
|
val buildSources = findBuildFile(parameterMap)
|
||||||
val profiles = findProfiles(parameterMap)
|
val profiles = findProfiles(parameterMap)
|
||||||
|
val downloadSources = findDownloadSources(s.upgradeRequest.parameterMap)
|
||||||
|
|
||||||
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
val args = getInstance(Args::class.java)
|
val args = getInstance(Args::class.java)
|
||||||
args.buildFile = buildSources.root.absolutePath
|
args.buildFile = buildSources.root.absolutePath
|
||||||
args.profiles = profiles
|
args.profiles = profiles
|
||||||
|
args.downloadSources = downloadSources
|
||||||
|
|
||||||
val projectResults = projectFinder.initForBuildFile(buildSources, args)
|
val projectResults = projectFinder.initForBuildFile(buildSources, args)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue