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

Check new version.

This commit is contained in:
Cedric Beust 2015-10-05 22:46:37 -07:00
parent c45bf49c7d
commit 1af54ec0eb
4 changed files with 64 additions and 16 deletions

View file

@ -34,25 +34,13 @@ private class Main @Inject constructor(
val localRepo: LocalRepo,
val depFactory: DepFactory,
val checkVersions: CheckVersions,
val jcenter: UnauthenticatedJCenterApi)
val jcenter: UnauthenticatedJCenterApi,
val github: GithubApi)
: KobaltLogger {
data class RunInfo(val jc: JCommander, val args: Args)
public fun run(argv: Array<String>) {
// Check for new version
// Commented out until I can find a way to get the latest available download
// from bintray. Right now, it always returns all the versions uploaded, not
// just the one I mark
// val p = jcenter.kobaltPackage
// val current = Versions.toLongVersion(Kobalt.version)
// val remote = Versions.toLongVersion(p.latestPublishedVersion)
// if (remote > current) {
// log(1, "*****")
// log(1, "***** New Kobalt version available: ${p.latestPublishedVersion}")
// log(1, "*****")
// }
benchmark("Build", {
println(Banner.get() + Kobalt.version + "\n")
// runTest()
@ -61,6 +49,17 @@ private class Main @Inject constructor(
executors.shutdown()
debug("All done")
})
// 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 current = Versions.toLongVersion(Kobalt.version)
if (remote > current) {
log(1, "*****")
log(1, "***** New Kobalt version available: ${github.latestKobaltRelease}")
log(1, "*****")
}
}
public class Worker<T>(val runNodes: ArrayList<T>, val n: T) : IWorker<T>, KobaltLogger {

View file

@ -3,6 +3,7 @@ package com.beust.kobalt.api
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.MavenDependency
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.misc.KFiles
import com.google.common.base.Preconditions
import java.util.ArrayList
@ -10,7 +11,7 @@ open public class Project(
open var name: String? = null,
open var version: String? = null,
open var directory: String = ".",
open var buildDirectory: String? = "kobaltBuild",
open var buildDirectory: String? = KFiles.KOBALT_BUILD_DIR,
open var group: String? = null,
open var artifactId: String? = null,
open var dependencies: Dependencies? = null,

View file

@ -0,0 +1,37 @@
package com.beust.kobalt.misc
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
public class GithubApi @Inject constructor(val http: Http) : KobaltLogger {
companion object {
const val HOST = "https://api.github.com/"
}
val latestKobaltRelease: 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
}
}
} catch(ex: IOException) {
warn("Couldn't load the release URL: ${url}")
}
return "0"
}
}

View file

@ -15,7 +15,17 @@ import java.nio.file.StandardCopyOption
public class KFiles {
val kobaltJar : String
get() = joinDir(distributionsDir, Kobalt.version, "kobalt/wrapper/kobalt-" + Kobalt.version + ".jar")
get() {
val jar = joinDir(distributionsDir, Kobalt.version, "kobalt/wrapper/kobalt-" + Kobalt.version + ".jar")
val jarFile = File(jar)
if (! jarFile.exists()) {
// Will only happen when building kobalt itself: the jar file might not be in the dist/ directory
// yet since we're currently building it. Instead, use the classes directly
return File(joinDir("build", "classes", "main")).absolutePath
} else {
return jar
}
}
init {
File(KOBALT_DOT_DIR).mkdirs()
@ -24,6 +34,7 @@ public class KFiles {
companion object {
private const val KOBALT_DOT_DIR : String = ".kobalt"
const val KOBALT_DIR : String = "kobalt"
const val KOBALT_BUILD_DIR = "kobaltBuild"
// Directories under ~/.kobalt
public val localRepo = homeDir(KOBALT_DOT_DIR, "repository")