mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Better version check.
This commit is contained in:
parent
6afeb7ba89
commit
a44b15d6d1
4 changed files with 38 additions and 27 deletions
|
@ -50,6 +50,7 @@ private class Main @Inject constructor(
|
||||||
data class RunInfo(val jc: JCommander, val args: Args)
|
data class RunInfo(val jc: JCommander, val args: Args)
|
||||||
|
|
||||||
public fun run(jc: JCommander, args: Args) {
|
public fun run(jc: JCommander, args: Args) {
|
||||||
|
val latestVersionFuture = github.latestKobaltVersion
|
||||||
benchmark("Build", {
|
benchmark("Build", {
|
||||||
println(Banner.get() + Kobalt.version + "\n")
|
println(Banner.get() + Kobalt.version + "\n")
|
||||||
// runTest()
|
// runTest()
|
||||||
|
@ -59,15 +60,14 @@ private class Main @Inject constructor(
|
||||||
})
|
})
|
||||||
|
|
||||||
// Check for new version
|
// Check for new version
|
||||||
// TODO(cbeust): Start the network call at the beginning of the build and
|
val latestVersionString = latestVersionFuture.get()
|
||||||
// get the future here, at the end of the build
|
val latestVersion = Versions.toLongVersion(latestVersionString)
|
||||||
val remote = Versions.toLongVersion(github.latestKobaltRelease)
|
|
||||||
val current = Versions.toLongVersion(Kobalt.version)
|
val current = Versions.toLongVersion(Kobalt.version)
|
||||||
if (remote > current) {
|
if (latestVersion > current) {
|
||||||
"***** ".let {
|
"***** ".let {
|
||||||
log(1, it)
|
log(1, it)
|
||||||
log(1, "$it New Kobalt version available: ${github.latestKobaltRelease}")
|
log(1, "$it New Kobalt version available: $latestVersionString")
|
||||||
log(1, "$it To update, run ./kobaltw --update")
|
log(1, "$it To update, run ./kobaltw --update")
|
||||||
log(1, it )
|
log(1, it )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,34 +4,43 @@ import com.beust.klaxon.JsonArray
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.beust.klaxon.Parser
|
import com.beust.klaxon.Parser
|
||||||
import com.beust.klaxon.string
|
import com.beust.klaxon.string
|
||||||
import com.beust.kobalt.maven.Http
|
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
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 {
|
companion object {
|
||||||
const val HOST = "https://api.github.com/"
|
const val HOST = "https://api.github.com/"
|
||||||
}
|
}
|
||||||
|
|
||||||
val latestKobaltRelease: String
|
val latestKobaltVersion: Future<String>
|
||||||
get() {
|
get() {
|
||||||
val url = HOST + "repos/cbeust/kobalt/releases"
|
val callable = Callable<String> {
|
||||||
try {
|
var result = "0"
|
||||||
val ins = URL(url).openConnection().inputStream
|
val url = HOST + "repos/cbeust/kobalt/releases"
|
||||||
val jo = Parser().parse(ins) as JsonArray<JsonObject>
|
try {
|
||||||
if (jo.size() > 0) {
|
val ins = URL(url).openConnection().inputStream
|
||||||
var result = jo.get(0).string("name")
|
@Suppress("UNCHECKED_CAST")
|
||||||
if (result == null) {
|
val jo = Parser().parse(ins) as JsonArray<JsonObject>
|
||||||
result = jo.get(0).string("tag_name")
|
if (jo.size() > 0) {
|
||||||
}
|
var versionName = jo.get(0).string("name")
|
||||||
if (result != null) {
|
if (versionName == null) {
|
||||||
return result
|
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) {
|
result
|
||||||
warn("Couldn't load the release URL: ${url}")
|
|
||||||
}
|
}
|
||||||
return "0"
|
return executors.miscExecutor.submit(callable)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,13 +48,15 @@ public class KobaltExecutors : KobaltLogger {
|
||||||
public fun newExecutor(name: String, threadCount: Int) : ExecutorService
|
public fun newExecutor(name: String, threadCount: Int) : ExecutorService
|
||||||
= KobaltExecutor(name, threadCount)
|
= 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()
|
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> {
|
maxMs: Long, tasks: List<Callable<T>>) : List<T> {
|
||||||
val result = arrayListOf<T>()
|
val result = arrayListOf<T>()
|
||||||
val executor = newExecutor(name, threadCount)
|
val executor = newExecutor(name, threadCount)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.io.File
|
||||||
*/
|
*/
|
||||||
public class UpdateKobalt @Inject constructor(val http: Http, val github: GithubApi) {
|
public class UpdateKobalt @Inject constructor(val http: Http, val github: GithubApi) {
|
||||||
fun updateKobalt() {
|
fun updateKobalt() {
|
||||||
val newVersion = github.latestKobaltRelease
|
val newVersion = github.latestKobaltVersion
|
||||||
KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=$newVersion")
|
KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=$newVersion")
|
||||||
com.beust.kobalt.wrapper.main(arrayOf())
|
com.beust.kobalt.wrapper.main(arrayOf())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue