1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Better version check.

This commit is contained in:
Cedric Beust 2015-10-07 02:09:11 -07:00
parent 6afeb7ba89
commit a44b15d6d1
4 changed files with 38 additions and 27 deletions

View file

@ -50,6 +50,7 @@ private class Main @Inject constructor(
data class RunInfo(val jc: JCommander, val args: Args)
public fun run(jc: JCommander, args: Args) {
val latestVersionFuture = github.latestKobaltVersion
benchmark("Build", {
println(Banner.get() + Kobalt.version + "\n")
// runTest()
@ -59,15 +60,14 @@ private class Main @Inject constructor(
})
// Check for new version
// TODO(cbeust): Start the network call at the beginning of the build and
// get the future here, at the end of the build
val remote = Versions.toLongVersion(github.latestKobaltRelease)
val latestVersionString = latestVersionFuture.get()
val latestVersion = Versions.toLongVersion(latestVersionString)
val current = Versions.toLongVersion(Kobalt.version)
if (remote > current) {
if (latestVersion > current) {
"***** ".let {
log(1, it)
log(1, "$it New Kobalt version available: ${github.latestKobaltRelease}")
log(1, "$it To update, run ./kobaltw --update")
log(1, "$it New Kobalt version available: $latestVersionString")
log(1, "$it To update, run ./kobaltw --update")
log(1, it )
}
}

View file

@ -4,34 +4,43 @@ import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import com.beust.klaxon.Parser
import com.beust.klaxon.string
import com.beust.kobalt.maven.Http
import com.google.inject.Inject
import java.io.IOException
import java.net.URL
import java.util.concurrent.Callable
import java.util.concurrent.Future
public class GithubApi @Inject constructor(val http: Http) : KobaltLogger {
/**
* Retrieve Kobalt's latest release version from github.
*/
public class GithubApi @Inject constructor(val executors: KobaltExecutors) : KobaltLogger {
companion object {
const val HOST = "https://api.github.com/"
}
val latestKobaltRelease: String
val latestKobaltVersion: Future<String>
get() {
val url = HOST + "repos/cbeust/kobalt/releases"
try {
val ins = URL(url).openConnection().inputStream
val jo = Parser().parse(ins) as JsonArray<JsonObject>
if (jo.size() > 0) {
var result = jo.get(0).string("name")
if (result == null) {
result = jo.get(0).string("tag_name")
}
if (result != null) {
return result
val callable = Callable<String> {
var result = "0"
val url = HOST + "repos/cbeust/kobalt/releases"
try {
val ins = URL(url).openConnection().inputStream
@Suppress("UNCHECKED_CAST")
val jo = Parser().parse(ins) as JsonArray<JsonObject>
if (jo.size() > 0) {
var versionName = jo.get(0).string("name")
if (versionName == null) {
versionName = jo.get(0).string("tag_name")
}
if (versionName != null) {
result = versionName
}
}
} catch(ex: IOException) {
warn("Couldn't load the release URL: $url")
}
} catch(ex: IOException) {
warn("Couldn't load the release URL: ${url}")
result
}
return "0"
return executors.miscExecutor.submit(callable)
}
}

View file

@ -48,13 +48,15 @@ public class KobaltExecutors : KobaltLogger {
public fun newExecutor(name: String, threadCount: Int) : ExecutorService
= KobaltExecutor(name, threadCount)
var dependencyExecutor = newExecutor("Dependency", 5)
val dependencyExecutor = newExecutor("Dependency", 5)
val miscExecutor = newExecutor("Misc", 2)
public fun shutdown() {
fun shutdown() {
dependencyExecutor.shutdown()
miscExecutor.shutdown()
}
public fun <T> completionService(name: String, threadCount: Int,
fun <T> completionService(name: String, threadCount: Int,
maxMs: Long, tasks: List<Callable<T>>) : List<T> {
val result = arrayListOf<T>()
val executor = newExecutor(name, threadCount)

View file

@ -9,7 +9,7 @@ import java.io.File
*/
public class UpdateKobalt @Inject constructor(val http: Http, val github: GithubApi) {
fun updateKobalt() {
val newVersion = github.latestKobaltRelease
val newVersion = github.latestKobaltVersion
KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=$newVersion")
com.beust.kobalt.wrapper.main(arrayOf())
}