From 1730e8de697165fd035bb39a6ac13be220585865 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 30 Mar 2017 13:29:25 -0700 Subject: [PATCH] Add -downloadSources. --- .../src/main/kotlin/com/beust/kobalt/Args.kt | 4 ++++ .../kobalt/maven/aether/KobaltMavenResolver.kt | 15 ++++++++++++++- src/test/kotlin/com/beust/kobalt/TestModule.kt | 6 ++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index b13f0bd3..b8cdc2fe 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -22,6 +22,10 @@ class Args { @Parameter(names = arrayOf("--download"), description = "Force a download from the downloadUrl in the wrapper") var download: Boolean = false + @Parameter(names = arrayOf("--downloadSources"), + description = "Force a download of sources and javadocs when resolving dependencies") + var downloadSources: Boolean = false + @Parameter(names = arrayOf("--dryRun"), description = "Display all the tasks that will get run without " + "actually running them") var dryRun: Boolean = false diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 4e8cfae2..50731443 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.maven.aether +import com.beust.kobalt.Args import com.beust.kobalt.api.Kobalt import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.getProxy @@ -21,6 +22,7 @@ import org.eclipse.aether.resolution.VersionRangeRequest import org.eclipse.aether.resolution.VersionRangeResult class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, + val args: Args, localRepo: LocalRepo, eventBus: EventBus) { companion object { @@ -101,7 +103,18 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, } private fun createCollectRequest(id: String, scope: Scope? = null) = CollectRequest().apply { - root = Dependency(DefaultArtifact(MavenId.toKobaltId(id)), scope?.scope) + val allIds = arrayListOf(MavenId.toMavenId(id)) + if (args.downloadSources) { + listOf("sources", "javadoc").forEach { + val artifact = DefaultArtifact(id) + val sourceArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, it, artifact.extension, + artifact.version) + allIds.add(sourceArtifact.toString()) + } + } + dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) } + + root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope) repositories = kobaltRepositories } } diff --git a/src/test/kotlin/com/beust/kobalt/TestModule.kt b/src/test/kotlin/com/beust/kobalt/TestModule.kt index c8fa2ce8..e42fb5d9 100644 --- a/src/test/kotlin/com/beust/kobalt/TestModule.kt +++ b/src/test/kotlin/com/beust/kobalt/TestModule.kt @@ -2,7 +2,9 @@ package com.beust.kobalt import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.app.MainModule -import com.beust.kobalt.internal.* +import com.beust.kobalt.internal.ILogger +import com.beust.kobalt.internal.KobaltSettings +import com.beust.kobalt.internal.KobaltSettingsXml import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.misc.kobaltLog @@ -24,7 +26,7 @@ class TestModule : MainModule(Args(), TEST_KOBALT_SETTINGS) { val localRepo = TestLocalRepo() bind(LocalRepo::class.java).toInstance(localRepo) // val localAether = Aether(LOCAL_CACHE, TEST_KOBALT_SETTINGS, EventBus()) - val testResolver = KobaltMavenResolver(KobaltSettings(KobaltSettingsXml()), TestLocalRepo(), EventBus()) + val testResolver = KobaltMavenResolver(KobaltSettings(KobaltSettingsXml()), Args(), TestLocalRepo(), EventBus()) bind(KobaltMavenResolver::class.java).to(testResolver) bind(KobaltContext::class.java).toProvider(Provider { KobaltContext(args).apply {