mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Only check for the latest release version number on GitHub every 10 minutes.
This commit is contained in:
parent
6409e723cb
commit
c342573e55
1 changed files with 38 additions and 29 deletions
|
@ -1,8 +1,10 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.KobaltException
|
import com.beust.kobalt.KobaltException
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.internal.DocUrl
|
import com.beust.kobalt.internal.DocUrl
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
|
import com.beust.kobalt.internal.build.VersionCheckTimestampFile
|
||||||
import com.beust.kobalt.maven.Http
|
import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.maven.aether.Exceptions
|
import com.beust.kobalt.maven.aether.Exceptions
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
@ -16,6 +18,8 @@ import retrofit2.converter.gson.GsonConverterFactory
|
||||||
import retrofit2.http.*
|
import retrofit2.http.*
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
|
@ -110,38 +114,42 @@ class GithubApi2 @Inject constructor(
|
||||||
get() {
|
get() {
|
||||||
val callable = Callable<String> {
|
val callable = Callable<String> {
|
||||||
var result = "0"
|
var result = "0"
|
||||||
|
if (Duration.ofMinutes(10L) >
|
||||||
val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
|
Duration.between(VersionCheckTimestampFile.timestamp, Instant.now())) {
|
||||||
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
kobaltLog(2, "Skipping GitHub latest release check, too soon.")
|
||||||
try {
|
result = Kobalt.version
|
||||||
val req =
|
} else {
|
||||||
if (username != null && accessToken != null) {
|
val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
|
||||||
service.getReleases(username, "kobalt", accessToken)
|
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
||||||
} else {
|
try {
|
||||||
service.getReleasesNoAuth("cbeust", "kobalt")
|
val req =
|
||||||
}
|
if (username != null && accessToken != null) {
|
||||||
val ex = req.execute()
|
service.getReleases(username, "kobalt", accessToken)
|
||||||
val errorBody = ex.errorBody()
|
} else {
|
||||||
if (errorBody != null) {
|
service.getReleasesNoAuth("cbeust", "kobalt")
|
||||||
val jsonError = JsonParser().parse(errorBody.string())
|
|
||||||
warn("Couldn't call Github.getReleases(): $jsonError")
|
|
||||||
} else {
|
|
||||||
val releases = ex.body()
|
|
||||||
if (releases != null) {
|
|
||||||
releases.firstOrNull()?.let {
|
|
||||||
try {
|
|
||||||
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
|
||||||
} catch(ex: NoSuchElementException) {
|
|
||||||
throw KobaltException("Couldn't find the latest release")
|
|
||||||
}
|
}
|
||||||
}
|
val ex = req.execute()
|
||||||
|
val errorBody = ex.errorBody()
|
||||||
|
if (errorBody != null) {
|
||||||
|
val jsonError = JsonParser().parse(errorBody.string())
|
||||||
|
warn("Couldn't call Github.getReleases(): $jsonError")
|
||||||
} else {
|
} else {
|
||||||
warn("Didn't receive any body in the response to GitHub.getReleases()")
|
val releases = ex.body()
|
||||||
|
if (releases != null) {
|
||||||
|
releases.firstOrNull()?.let {
|
||||||
|
try {
|
||||||
|
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
||||||
|
} catch(ex: NoSuchElementException) {
|
||||||
|
throw KobaltException("Couldn't find the latest release")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn("Didn't receive any body in the response to GitHub.getReleases()")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch(e: Exception) {
|
||||||
} catch(e: Exception) {
|
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
|
||||||
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
|
Exceptions.printStackTrace(e)
|
||||||
Exceptions.printStackTrace(e)
|
|
||||||
// val error = parseRetrofitError(e)
|
// val error = parseRetrofitError(e)
|
||||||
// val details = if (error.errors != null) {
|
// val details = if (error.errors != null) {
|
||||||
// error.errors[0]
|
// error.errors[0]
|
||||||
|
@ -152,6 +160,7 @@ class GithubApi2 @Inject constructor(
|
||||||
// // using cbeust/kobalt, like above. Right now, just bailing.
|
// // using cbeust/kobalt, like above. Right now, just bailing.
|
||||||
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
|
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
|
||||||
// + details?.code + " field: " + details?.field)
|
// + details?.code + " field: " + details?.field)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue