From 34c630883c55a384a5f30cb1f182c6bcaade5f64 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 7 Oct 2015 00:40:47 -0700 Subject: [PATCH] --update --- src/main/kotlin/com/beust/kobalt/Args.kt | 2 ++ src/main/kotlin/com/beust/kobalt/Main.kt | 14 ++++++++++---- .../kotlin/com/beust/kobalt/misc/UpdateKobalt.kt | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt diff --git a/src/main/kotlin/com/beust/kobalt/Args.kt b/src/main/kotlin/com/beust/kobalt/Args.kt index bf5d7ce6..55633bbc 100644 --- a/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/src/main/kotlin/com/beust/kobalt/Args.kt @@ -26,5 +26,7 @@ class Args { @Parameter(names = arrayOf("--tasks"), description = "Display the tasks available for this build") var tasks: Boolean = false + @Parameter(names = arrayOf("--update"), description = "Update to the latest version of Kobalt") + var update: Boolean = false } diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index c9d378be..5687b4e8 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -43,7 +43,8 @@ private class Main @Inject constructor( val localRepo: LocalRepo, val depFactory: DepFactory, val checkVersions: CheckVersions, - val github: GithubApi) + val github: GithubApi, + val updateKobalt: UpdateKobalt) : KobaltLogger { data class RunInfo(val jc: JCommander, val args: Args) @@ -63,9 +64,12 @@ private class Main @Inject constructor( val remote = Versions.toLongVersion(github.latestKobaltRelease) val current = Versions.toLongVersion(Kobalt.version) if (remote > current) { - log(1, "*****") - log(1, "***** New Kobalt version available: ${github.latestKobaltRelease}") - log(1, "*****") + "***** ".let { + log(1, it) + log(1, "$it New Kobalt version available: ${github.latestKobaltRelease}") + log(1, "$it To update, run ./kobaltw --update") + log(1, it ) + } } } @@ -152,6 +156,8 @@ private class Main @Inject constructor( println(sb.toString()) } else if (args.checkVersions) { checkVersions.run(output.projects) + } else if (args.update) { + updateKobalt.updateKobalt() } else { // // Launch the build diff --git a/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt new file mode 100644 index 00000000..300f8fe4 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt @@ -0,0 +1,16 @@ +package com.beust.kobalt.misc + +import com.beust.kobalt.maven.Http +import com.google.inject.Inject +import java.io.File + +/** + * Update Kobalt to the latest version. + */ +public class UpdateKobalt @Inject constructor(val http: Http, val github: GithubApi) { + fun updateKobalt() { + val newVersion = github.latestKobaltRelease + KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=$newVersion") + com.beust.kobalt.wrapper.main(arrayOf()) + } +}