From f4f5e8c05ef42dad85f99412820185a4328656f6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 31 Jan 2016 08:24:50 -0800 Subject: [PATCH] Comments. --- TODO.md | 2 +- .../kotlin/com/beust/kobalt/api/Project.kt | 29 +++++++++++-------- .../com/beust/kobalt/app/UpdateKobalt.kt | 4 +-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/TODO.md b/TODO.md index 3298de2e..f5eabf5c 100644 --- a/TODO.md +++ b/TODO.md @@ -15,7 +15,7 @@ General - [ ] Fetch .pom with DynamicGraph - [ ] Centralize all the executors - [ ] Archetypes (e.g. "--initWith kobalt-plug-in") -- [ ] Compile TestNG (including generating Version.java and OSGi headers) +- [ ] Compile TestNG (last piece missing: OSGi headers) - [ ] Support additional .kt files in ~/.kobalt/src - [ ] --init: import dependencies from build.gradle - [ ] --init: also extract kobalt.bat (or generate it along with kobaltw) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 17dca103..62c273e4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -5,6 +5,7 @@ import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.internal.IProjectInfo import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.KFiles +import java.io.File import java.util.* open class Project( @@ -133,25 +134,29 @@ class Dependencies(val project: Project, val dependencies: ArrayList, val runtimeDependencies: ArrayList, val excludedDependencies: ArrayList) { - @Directive - fun compile(vararg dep: String) { - dep.forEach { dependencies.add(MavenDependency.create(it)) } + + /** + * Add the dependencies to the given ArrayList and return a list of jar files corresponding to + * these dependencies. + */ + private fun addToDependencies(dependencies: ArrayList, dep: Array) + : List + = with(dep.map { MavenDependency.create(it)}) { + dependencies.addAll(this) + this.map { it.jarFile.get() } } @Directive - fun provided(vararg dep: String) { - dep.forEach { providedDependencies.add(MavenDependency.create(it))} - } + fun compile(vararg dep: String) = addToDependencies(dependencies, dep) @Directive - fun runtime(vararg dep: String) { - dep.forEach { runtimeDependencies.add(MavenDependency.create(it))} - } + fun provided(vararg dep: String) = addToDependencies(providedDependencies, dep) @Directive - fun exclude(vararg dep: String) { - dep.forEach { excludedDependencies.add(MavenDependency.create(it))} - } + fun runtime(vararg dep: String) = addToDependencies(runtimeDependencies, dep) + + @Directive + fun exclude(vararg dep: String) = addToDependencies(excludedDependencies, dep) } class Scm(val connection: String, val developerConnection: String, val url: String) diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 5bc0d72c..2c8a0dbc 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -30,8 +30,8 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper } /** - * Accepts Future as `latestVersionFuture` to allow getting `latestVersion` in the background - * */ + * Accepts Future as `latestVersionFuture` to allow getting `latestVersion` in the background. + */ fun checkForNewVersion(latestVersionFuture: Future) { if (Kobalt.versionCheckTimeout > Duration.between(VersionCheckTimestampFile.timestamp, Instant.now())) { return // waits `Kobalt.versionCheckTimeout` before the next check