diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index a64ecaef..8a48f2b4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -37,7 +37,7 @@ public class Kobalt { private val KOBALT_PROPERTIES = "kobalt.properties" private val PROPERTY_KOBALT_VERSION = "kobalt.version" - private val PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT = "kobalt.version.check_timeout" // ISO-8601 + private val PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT = "kobalt.version.checkTimeout" // ISO-8601 /** kobalt.properties */ private val kobaltProperties: Properties by lazy { readProperties() } @@ -75,7 +75,8 @@ public class Kobalt { } val version = kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION) - val versionCheckTimeout = Duration.parse(kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT)) + val versionCheckTimeout = Duration.parse( + kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT) ?: "P1D2H") fun findPlugin(name: String) = Plugins.findPlugin(name) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionCheckTimestampFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionCheckTimestampFile.kt index ecb23bd6..ea0ff924 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionCheckTimestampFile.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionCheckTimestampFile.kt @@ -7,17 +7,16 @@ import java.time.Instant class VersionCheckTimestampFile { companion object { private val KOBALT_VERSION_CHECK_TIMESTAMP_FILE = "versionCheckTimestamp.txt" - private val checkTimestampFile = File(KFiles.KOBALT_DOT_DIR, KOBALT_VERSION_CHECK_TIMESTAMP_FILE) + private val CHECK_TIMESTAMP_FILE = File(KFiles.KOBALT_DOT_DIR, KOBALT_VERSION_CHECK_TIMESTAMP_FILE) - fun updateTimestamp(timestamp: Instant) = KFiles.saveFile(checkTimestampFile, timestamp.toString()) + fun updateTimestamp(timestamp: Instant) = KFiles.saveFile(CHECK_TIMESTAMP_FILE, timestamp.toString()) - fun getTimestamp(): Instant { - return if(checkTimestampFile.exists()) - Instant.parse(checkTimestampFile.readText()) - else { + val timestamp : Instant + get() = if (CHECK_TIMESTAMP_FILE.exists()) { + Instant.parse(CHECK_TIMESTAMP_FILE.readText()) + } else { updateTimestamp(Instant.MIN) Instant.MIN } - } } } \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 488c0d30..5bc0d72c 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -33,9 +33,9 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper * Accepts Future as `latestVersionFuture` to allow getting `latestVersion` in the background * */ fun checkForNewVersion(latestVersionFuture: Future) { - if(Kobalt.versionCheckTimeout - > Duration.between(VersionCheckTimestampFile.getTimestamp(), Instant.now())) + if (Kobalt.versionCheckTimeout > Duration.between(VersionCheckTimestampFile.timestamp, Instant.now())) { return // waits `Kobalt.versionCheckTimeout` before the next check + } try { val latestVersionString = latestVersionFuture.get() diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 182ef21c..0f994c0b 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1,2 +1 @@ kobalt.version=0.401 -kobalt.version.check_timeout=P1DT2H