From bb2eb19876c89973efdf45a9713cdb94212ac53d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 3 Apr 2017 09:54:26 -0700 Subject: [PATCH] Refactor some downloadSources code. --- .../kobalt/maven/aether/AetherDependency.kt | 35 +++++++------------ .../app/remote/GetDependencyGraphHandler.kt | 3 +- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt index cc9631da..825a8ae8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt @@ -26,33 +26,24 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean = private fun toId(a: Artifact) = a.toString() override val jarFile: Future - get() = - if (artifact.file != null) { - resolveSourcesIfNeeded() - CompletedFuture(artifact.file) - } else { - resolveSourcesIfNeeded() - val td = aether.resolve(artifact) - CompletedFuture(td.root.artifact.file) - } + get() { + resolveSourcesIfNeeded() + return if (artifact.file != null) { + CompletedFuture(artifact.file) + } else { + 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) { + listOf(artifact.toSourcesArtifact(), artifact.toJavaDocArtifact()).forEach { artifact -> + if (artifact.file == null) { try { - aether.resolve(sourcesArtifact) + aether.resolve(artifact) } catch(e: DependencyResolutionException) { - //do nothing - } - } - } - artifact.toJavaDocArtifact().let { javadocArtifact -> - if (javadocArtifact.file == null) { - try { - aether.resolve(javadocArtifact) - } catch(e: DependencyResolutionException) { - //do nothing + // Ignore } } } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt index 3ac7c256..484a50fd 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt @@ -47,7 +47,8 @@ class GetDependencyGraphHandler : WebSocketListener { } private fun findProfiles(map: Map>) = map[PARAMETER_PROFILES]?.getOrNull(0) - private fun findDownloadSources(map: Map>) = map[PARAMETER_DOWNLOAD_SOURCES]?.getOrNull(0)?.toBoolean() ?: false + private fun findDownloadSources(map: Map>) = map[PARAMETER_DOWNLOAD_SOURCES] + ?.getOrNull(0)?.toBoolean() ?: false private fun findBuildFile(map: Map>) : BuildSources? { val projectRoot = map[PARAMETER_PROJECT_ROOT]