1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Refactor some downloadSources code.

This commit is contained in:
Cedric Beust 2017-04-03 09:54:26 -07:00
parent 1c27b9f1e4
commit bb2eb19876
2 changed files with 15 additions and 23 deletions

View file

@ -26,33 +26,24 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
private fun toId(a: Artifact) = a.toString() private fun toId(a: Artifact) = a.toString()
override val jarFile: Future<File> override val jarFile: Future<File>
get() = get() {
if (artifact.file != null) {
resolveSourcesIfNeeded() resolveSourcesIfNeeded()
return if (artifact.file != null) {
CompletedFuture(artifact.file) CompletedFuture(artifact.file)
} else { } else {
resolveSourcesIfNeeded()
val td = aether.resolve(artifact) val td = aether.resolve(artifact)
CompletedFuture(td.root.artifact.file) CompletedFuture(td.root.artifact.file)
} }
}
private fun resolveSourcesIfNeeded() { private fun resolveSourcesIfNeeded() {
if (args?.downloadSources ?: false) { if (args?.downloadSources ?: false) {
artifact.toSourcesArtifact().let { sourcesArtifact -> listOf(artifact.toSourcesArtifact(), artifact.toJavaDocArtifact()).forEach { artifact ->
if (sourcesArtifact.file == null) { if (artifact.file == null) {
try { try {
aether.resolve(sourcesArtifact) aether.resolve(artifact)
} catch(e: DependencyResolutionException) { } catch(e: DependencyResolutionException) {
//do nothing // Ignore
}
}
}
artifact.toJavaDocArtifact().let { javadocArtifact ->
if (javadocArtifact.file == null) {
try {
aether.resolve(javadocArtifact)
} catch(e: DependencyResolutionException) {
//do nothing
} }
} }
} }

View file

@ -47,7 +47,8 @@ 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 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]