mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Update to github for releases.
This commit is contained in:
parent
07f9712e1b
commit
13b87527f6
9 changed files with 137 additions and 54 deletions
|
@ -59,7 +59,8 @@ private class Main @Inject constructor(
|
|||
val server: KobaltServer,
|
||||
val pluginInfo: PluginInfo,
|
||||
val projectGenerator: ProjectGenerator,
|
||||
val resolveDependency: ResolveDependency) {
|
||||
val resolveDependency: ResolveDependency,
|
||||
val wrapper: Wrapper) {
|
||||
|
||||
data class RunInfo(val jc: JCommander, val args: Args)
|
||||
|
||||
|
@ -137,7 +138,7 @@ private class Main @Inject constructor(
|
|||
//
|
||||
// --init: create a new build project and install the wrapper
|
||||
//
|
||||
Wrapper().install()
|
||||
wrapper.install()
|
||||
projectGenerator.run(args)
|
||||
} else if (args.usage) {
|
||||
jc.usage()
|
||||
|
|
|
@ -1,21 +1,64 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Manage kobalt-wrapper.properties.
|
||||
*/
|
||||
class KobaltWrapperProperties @Inject constructor() {
|
||||
private val WRAPPER_DIR = KFiles.KOBALT_DIR + "/wrapper"
|
||||
private val KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"
|
||||
private val PROPERTY_VERSION = "kobalt.version"
|
||||
private val PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl"
|
||||
|
||||
fun defaultUrlFor(version: String) =
|
||||
"bogushttps://github.com/cbeust/kobalt/releases/download/$version/kobalt-$version.zip"
|
||||
|
||||
val file: File
|
||||
get() = File("$WRAPPER_DIR/$KOBALT_WRAPPER_PROPERTIES")
|
||||
|
||||
fun create(version: String) {
|
||||
log(2, "Creating $file with $version and ${defaultUrlFor(version)}")
|
||||
KFiles.saveFile(file, listOf(
|
||||
"$PROPERTY_VERSION=$version",
|
||||
"$PROPERTY_DOWNLOAD_URL"
|
||||
"$PROPERTY_DOWNLOAD_URL=${defaultUrlFor(version)}"
|
||||
).joinToString("\n"))
|
||||
}
|
||||
|
||||
val properties : Properties
|
||||
get() {
|
||||
val config = file
|
||||
if (!config.exists()) {
|
||||
create(Kobalt.version)
|
||||
}
|
||||
|
||||
val result = Properties()
|
||||
result.load(FileReader(config))
|
||||
return result
|
||||
}
|
||||
|
||||
val version : String
|
||||
get() = properties.getProperty(PROPERTY_VERSION)
|
||||
|
||||
val downloadUrl : String
|
||||
get() {
|
||||
return properties.getProperty(PROPERTY_DOWNLOAD_URL)
|
||||
?: defaultUrlFor(version)
|
||||
}
|
||||
|
||||
fun maybeCreate(version: String) {
|
||||
if (! file.exists()) {
|
||||
create(version)
|
||||
}
|
||||
}
|
||||
|
||||
// fun urlFor(version: String) : String {
|
||||
// // val URL = "https://dl.bintray.com/cbeust/generic/"
|
||||
// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
|
||||
// return downloadUrl ?: defaultUrlFor(version)
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Update Kobalt to the latest version.
|
||||
*/
|
||||
public class UpdateKobalt @Inject constructor(val github: GithubApi) {
|
||||
public class UpdateKobalt @Inject constructor(val github: GithubApi, val kobaltWrapperProperties: KobaltWrapperProperties) {
|
||||
fun updateKobalt() {
|
||||
val newVersion = github.latestKobaltVersion
|
||||
KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=${newVersion.get()}")
|
||||
kobaltWrapperProperties.maybeCreate(newVersion.get())
|
||||
com.beust.kobalt.wrapper.main(arrayOf())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,34 @@
|
|||
package com.beust.kobalt.wrapper
|
||||
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.benchmark
|
||||
import com.beust.kobalt.JavaInfo
|
||||
import com.beust.kobalt.SystemProperties
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltWrapperProperties
|
||||
import com.beust.kobalt.misc.benchmark
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.Properties
|
||||
import java.util.*
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
public fun main(argv: Array<String>) {
|
||||
Wrapper().installAndLaunchMain(argv)
|
||||
Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv)
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and install a new wrapper if requested.
|
||||
*/
|
||||
public class Wrapper {
|
||||
public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){
|
||||
// kobalt.properties
|
||||
private val KOBALT_PROPERTIES = "kobalt.properties"
|
||||
private val KOBALTW = "kobaltw"
|
||||
private val WRAPPER_DIR = KFiles.KOBALT_DIR + "/wrapper"
|
||||
|
||||
private val KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"
|
||||
private val PROPERTY_VERSION = "kobalt.version"
|
||||
|
||||
val URL = "https://dl.bintray.com/cbeust/generic/"
|
||||
val FILE_NAME = "kobalt"
|
||||
|
||||
private val properties = Properties()
|
||||
|
@ -47,7 +44,10 @@ public class Wrapper {
|
|||
properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) }
|
||||
}
|
||||
|
||||
private fun maybeCreateProperties() : Properties {
|
||||
/**
|
||||
* Attemps to read kobalt.properties (which should always exist).
|
||||
*/
|
||||
private fun maybeCreateKobaltProperties() : Properties {
|
||||
val result = Properties()
|
||||
|
||||
// kobalt.properties is internal to Kobalt
|
||||
|
@ -61,18 +61,29 @@ public class Wrapper {
|
|||
return result
|
||||
}
|
||||
|
||||
private fun initWrapperFile(version: String) {
|
||||
val config = File(WRAPPER_DIR, KOBALT_WRAPPER_PROPERTIES)
|
||||
if (! config.exists()) {
|
||||
KFiles.saveFile(config, "$PROPERTY_VERSION=$version")
|
||||
}
|
||||
properties.load(FileReader(config))
|
||||
}
|
||||
|
||||
private val wrapperVersion : String
|
||||
get() {
|
||||
return properties.getProperty(PROPERTY_VERSION)
|
||||
}
|
||||
// private fun initWrapperFile(version: String) {
|
||||
// val config = wrapperProperties.file
|
||||
// if (! config.exists()) {
|
||||
// wrapperProperties.create(version)
|
||||
// }
|
||||
// properties.load(FileReader(config))
|
||||
// }
|
||||
//
|
||||
// private val wrapperVersion : String
|
||||
// get() {
|
||||
// return properties.getProperty(PROPERTY_VERSION)
|
||||
// }
|
||||
//
|
||||
// private val wrapperDownloadUrl : String
|
||||
// get() {
|
||||
// return properties.getProperty(PROPERTY_DOWNLOAD_URL)
|
||||
// }
|
||||
//
|
||||
// fun urlFor(version: String) : String {
|
||||
// // val URL = "https://dl.bintray.com/cbeust/generic/"
|
||||
// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
|
||||
// return wrapperDownloadUrl ?: defaultUrlFor(version)
|
||||
// }
|
||||
|
||||
/**
|
||||
* Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties
|
||||
|
@ -80,12 +91,12 @@ public class Wrapper {
|
|||
* @return the path to the Kobalt jar file
|
||||
*/
|
||||
public fun install() : Path {
|
||||
val properties = maybeCreateProperties()
|
||||
val version = properties.getProperty(PROPERTY_VERSION)
|
||||
initWrapperFile(version)
|
||||
|
||||
log(2, "Wrapper version: $wrapperVersion")
|
||||
val properties = maybeCreateKobaltProperties()
|
||||
val version = properties.getProperty("kobalt.version")
|
||||
wrapperProperties.maybeCreate(version)
|
||||
log(2, "Wrapper version: ${wrapperProperties.version}")
|
||||
|
||||
val wrapperVersion = wrapperProperties.version
|
||||
val fileName = "$FILE_NAME-$wrapperVersion.zip"
|
||||
File(KFiles.distributionsDir).mkdirs()
|
||||
val localZipFile = Paths.get(KFiles.distributionsDir, fileName)
|
||||
|
@ -93,7 +104,7 @@ public class Wrapper {
|
|||
val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar")
|
||||
if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) {
|
||||
log(1, "Downloading $fileName")
|
||||
val fullUrl = "$URL/$fileName"
|
||||
val fullUrl = wrapperProperties.downloadUrl
|
||||
val body = Http().get(fullUrl)
|
||||
if (body.code == 200) {
|
||||
if (!Files.exists(localZipFile)) {
|
||||
|
@ -133,7 +144,7 @@ public class Wrapper {
|
|||
}
|
||||
log(2, "$localZipFile extracted")
|
||||
} else {
|
||||
error("Couldn't download $URL")
|
||||
error("Couldn't download $fullUrl")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
kobalt.version=0.234
|
||||
kobalt.version=0.238
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue