From b3efc12569534f0cd63177d5550d75efec4337d7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 30 Mar 2017 10:13:41 -0700 Subject: [PATCH] autoUpdate setting. --- .../com/beust/kobalt/internal/KobaltSettingsXml.kt | 8 ++++++++ src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt index 387c8a59..5f82b3dc 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt @@ -42,6 +42,9 @@ class KobaltSettingsXml { @XmlElement(name = "kobaltCompilerSeparateProcess") @JvmField var kobaltCompilerSeparateProcess: Boolean = false + + @XmlElement(name = "autoUpdate") @JvmField + var autoUpdate: Boolean = false } class ProxiesXml { @@ -85,6 +88,11 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) { */ val localMavenRepo = KFiles.makeDir(xmlFile.localMavenRepo) + /** + * If true, Kobalt will automatically update itself if a new version is found. + */ + val autoUpdate = xmlFile.autoUpdate + /** * If true, the Kotlin compiler will always be launched in a separate JVM, even if the requested * version is the same as the internal version. diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index b4528270..dbe43523 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -1,6 +1,7 @@ package com.beust.kobalt.app import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.build.VersionCheckTimestampFile import com.beust.kobalt.misc.* import com.beust.kobalt.wrapper.Main @@ -14,7 +15,8 @@ import javax.inject.Inject /** * Update Kobalt to the latest version. */ -class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProperties: KobaltWrapperProperties) { +class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProperties: KobaltWrapperProperties, + val settings: KobaltSettings, val updateKobalt: UpdateKobalt) { fun updateKobalt() { val newVersion = github.latestKobaltVersion wrapperProperties.create(newVersion.get()) @@ -43,7 +45,10 @@ class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProper val current = StringVersion(Kobalt.version) val distFile = File(KFiles.distributionsDir) if (latestVersion > current) { - if (distFile.exists()) { + if (settings.autoUpdate) { + kobaltLog(1, "**** Automatically updating to $latestVersionString") + updateKobalt.updateKobalt() + } else if (distFile.exists()) { kobaltLog(1, "**** Version $latestVersionString is installed, you can switch to it with " + "./kobaltw --update") } else {