From 6ad374006f4083d8e1210b23f8e0ffd9e219135a Mon Sep 17 00:00:00 2001 From: voddan Date: Fri, 29 Jan 2016 12:57:40 +0300 Subject: [PATCH] moved the waiting operation under the timeout check --- src/main/kotlin/com/beust/kobalt/Main.kt | 4 ++-- src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index b6908e66..5924f318 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -81,6 +81,7 @@ private class Main @Inject constructor( var result = 0 val latestVersionFuture = github.latestKobaltVersion + val seconds = benchmarkSeconds { try { result = runWithArgs(jc, args, argv) @@ -95,8 +96,7 @@ private class Main @Inject constructor( if (! args.update) { log(1, if (result != 0) "BUILD FAILED: $result" else "BUILD SUCCESSFUL ($seconds seconds)") - // Check for new version - updateKobalt.checkForNewVersion(latestVersionFuture.get()) + updateKobalt.checkForNewVersion(latestVersionFuture) } 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 c73433c7..f1670586 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.wrapper.Main import java.io.File import java.time.Duration import java.time.Instant +import java.util.concurrent.Future import java.util.concurrent.TimeoutException import javax.inject.Inject @@ -26,12 +27,16 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper Main.main(arrayOf("--download", "--no-launch")) } - fun checkForNewVersion(latestVersionString: String) { + /** + * Accepts Future as `latestVersionFuture` to allow getting `latestVersion` in the background + * */ + fun checkForNewVersion(latestVersionFuture: Future) { if(Kobalt.versionCheckTimeout > Duration.between(wrapperProperties.versionLastChecked, Instant.now())) return // waits `Kobalt.versionCheckTimeout` before the next check try { + val latestVersionString = latestVersionFuture.get() val latestVersion = Versions.toLongVersion(latestVersionString) val current = Versions.toLongVersion(Kobalt.version) val distFile = File(KFiles.joinDir(KFiles.distributionsDir, latestVersionString))