From 73b751f43fb8670fbfdc8cbc6494143bc5d029f4 Mon Sep 17 00:00:00 2001 From: voddan Date: Fri, 29 Jan 2016 11:04:12 +0300 Subject: [PATCH] extracted checking for a new version into UpdateKobalt; semantics did not change --- src/main/kotlin/com/beust/kobalt/Main.kt | 21 +-------------- .../com/beust/kobalt/app/UpdateKobalt.kt | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 1b6aace6..b6908e66 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -22,8 +22,6 @@ import com.google.inject.Guice import java.io.File import java.nio.file.Paths import java.util.* -import java.util.concurrent.TimeUnit -import java.util.concurrent.TimeoutException import javax.inject.Inject public fun main(argv: Array) { @@ -98,24 +96,7 @@ private class Main @Inject constructor( log(1, if (result != 0) "BUILD FAILED: $result" else "BUILD SUCCESSFUL ($seconds seconds)") // Check for new version - try { - val latestVersionString = latestVersionFuture.get(1, TimeUnit.SECONDS) - val latestVersion = Versions.toLongVersion(latestVersionString) - val current = Versions.toLongVersion(Kobalt.version) - val distFile = File(KFiles.joinDir(KFiles.distributionsDir, latestVersionString)) - if (latestVersion > current) { - if (distFile.exists()) { - log(1, "**** Version $latestVersionString is installed") - } else { - listOf("", "New Kobalt version available: $latestVersionString", - "To update, run ./kobaltw --update", "").forEach { - log(1, "**** $it") - } - } - } - } catch(ex: TimeoutException) { - log(2, "Didn't get the new version in time, skipping it") - } + updateKobalt.checkForNewVersion(latestVersionFuture.get()) } return result } diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 73d1a6d0..342741b1 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -1,8 +1,10 @@ package com.beust.kobalt.app -import com.beust.kobalt.misc.GithubApi -import com.beust.kobalt.misc.KobaltWrapperProperties +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.misc.* import com.beust.kobalt.wrapper.Main +import java.io.File +import java.util.concurrent.TimeoutException import javax.inject.Inject /** @@ -21,4 +23,24 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper fun downloadKobalt() { Main.main(arrayOf("--download", "--no-launch")) } + + fun checkForNewVersion(latestVersionString: String) { + try { + val latestVersion = Versions.toLongVersion(latestVersionString) + val current = Versions.toLongVersion(Kobalt.version) + val distFile = File(KFiles.joinDir(KFiles.distributionsDir, latestVersionString)) + if (latestVersion > current) { + if (distFile.exists()) { + log(1, "**** Version $latestVersionString is installed") + } else { + listOf("", "New Kobalt version available: $latestVersionString", + "To update, run ./kobaltw --update", "").forEach { + log(1, "**** $it") + } + } + } + } catch(ex: TimeoutException) { + log(2, "Didn't get the new version in time, skipping it") + } + } }