mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Support for --download.
This commit is contained in:
parent
13b87527f6
commit
ae7511be25
10 changed files with 264 additions and 282 deletions
|
@ -2,6 +2,7 @@
|
||||||
import com.beust.kobalt.api.License
|
import com.beust.kobalt.api.License
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.Scm
|
import com.beust.kobalt.api.Scm
|
||||||
|
import com.beust.kobalt.file
|
||||||
import com.beust.kobalt.homeDir
|
import com.beust.kobalt.homeDir
|
||||||
import com.beust.kobalt.internal.TaskResult
|
import com.beust.kobalt.internal.TaskResult
|
||||||
import com.beust.kobalt.internal.test
|
import com.beust.kobalt.internal.test
|
||||||
|
@ -11,6 +12,7 @@ import com.beust.kobalt.plugin.java.javaProject
|
||||||
import com.beust.kobalt.plugin.kotlin.kotlinCompiler
|
import com.beust.kobalt.plugin.kotlin.kotlinCompiler
|
||||||
import com.beust.kobalt.plugin.kotlin.kotlinProject
|
import com.beust.kobalt.plugin.kotlin.kotlinProject
|
||||||
import com.beust.kobalt.plugin.packaging.assemble
|
import com.beust.kobalt.plugin.packaging.assemble
|
||||||
|
import com.beust.kobalt.plugin.publish.jcenter
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
@ -71,7 +73,8 @@ val kobalt = kotlinProject(wrapper) {
|
||||||
"org.apache.maven:maven-model:3.3.3",
|
"org.apache.maven:maven-model:3.3.3",
|
||||||
"com.github.spullara.mustache.java:compiler:0.9.1",
|
"com.github.spullara.mustache.java:compiler:0.9.1",
|
||||||
"io.reactivex:rxjava:1.0.14",
|
"io.reactivex:rxjava:1.0.14",
|
||||||
"com.google.code.gson:gson:2.4"
|
"com.google.code.gson:gson:2.4",
|
||||||
|
file("modules/wrapper/kobaltBuild/libs/kobalt-wrapper.jar")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +106,10 @@ val kobalt = kotlinProject(wrapper) {
|
||||||
args("-nowarn")
|
args("-nowarn")
|
||||||
}
|
}
|
||||||
|
|
||||||
// jcenter {
|
jcenter {
|
||||||
// publish = true
|
publish = true
|
||||||
// file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip")
|
file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip")
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readVersion() : String {
|
fun readVersion() : String {
|
||||||
|
|
Binary file not shown.
|
@ -1,2 +1 @@
|
||||||
kobalt.version=0.238
|
kobalt.version=0.244
|
||||||
kobalt.downloadUrl=https://github.com/cbeust/kobalt/releases/download/0.238/kobalt-0.238.zip
|
|
|
@ -34,8 +34,12 @@ public class Main {
|
||||||
private static int logLevel = 1;
|
private static int logLevel = 1;
|
||||||
|
|
||||||
private void installAndLaunchMain(String[] argv) throws IOException, InterruptedException {
|
private void installAndLaunchMain(String[] argv) throws IOException, InterruptedException {
|
||||||
|
boolean noLaunch = false;
|
||||||
for (int i = 0; i < argv.length; i++) {
|
for (int i = 0; i < argv.length; i++) {
|
||||||
switch(argv[i]) {
|
switch(argv[i]) {
|
||||||
|
case "--no-launch":
|
||||||
|
noLaunch = true;
|
||||||
|
break;
|
||||||
case "--log":
|
case "--log":
|
||||||
logLevel = Integer.parseInt(argv[i + 1]);
|
logLevel = Integer.parseInt(argv[i + 1]);
|
||||||
i++;
|
i++;
|
||||||
|
@ -43,8 +47,10 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Path kobaltJarFile = installJarFile();
|
Path kobaltJarFile = installJarFile();
|
||||||
|
if (! noLaunch) {
|
||||||
launchMain(kobaltJarFile, argv);
|
launchMain(kobaltJarFile, argv);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void readProperties(Properties properties, InputStream ins) throws IOException {
|
private void readProperties(Properties properties, InputStream ins) throws IOException {
|
||||||
properties.load(ins);
|
properties.load(ins);
|
||||||
|
@ -106,7 +112,6 @@ public class Main {
|
||||||
Path kobaltJarFile = Paths.get(zipOutputDir,
|
Path kobaltJarFile = Paths.get(zipOutputDir,
|
||||||
getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar");
|
getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar");
|
||||||
if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) {
|
if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) {
|
||||||
if (!Files.exists(localZipFile)) {
|
|
||||||
download(localZipFile.toFile());
|
download(localZipFile.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,12 +147,11 @@ public class Main {
|
||||||
download(localZipFile.toFile());
|
download(localZipFile.toFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy the wrapper files in the current kobalt/wrapper directory
|
// Copy the wrapper files in the current kobalt/wrapper directory
|
||||||
//
|
//
|
||||||
if (! version.equals(getWrapperVersion())) {
|
boolean sameVersion = equals(getWrapperVersion());
|
||||||
log(2, "Copying the wrapper files");
|
log(2, "Copying the wrapper files");
|
||||||
for (String file : FILES) {
|
for (String file : FILES) {
|
||||||
Path from = Paths.get(zipOutputDir, file);
|
Path from = Paths.get(zipOutputDir, file);
|
||||||
|
@ -163,9 +167,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new File(KOBALTW).setExecutable(true);
|
new File(KOBALTW).setExecutable(true);
|
||||||
} else {
|
|
||||||
log(2, "Wrapper and current versions are identical");
|
|
||||||
}
|
|
||||||
return kobaltJarFile;
|
return kobaltJarFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +269,6 @@ public class Main {
|
||||||
System.out.println("[Wrapper error] *** " + s);
|
System.out.println("[Wrapper error] *** " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String KOBALT_MAIN_CLASS = "com.beust.kobalt.KobaltPackage";
|
|
||||||
|
|
||||||
private void launchMain(Path kobaltJarFile, String[] argv) throws IOException, InterruptedException {
|
private void launchMain(Path kobaltJarFile, String[] argv) throws IOException, InterruptedException {
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("java");
|
args.add("java");
|
||||||
|
|
|
@ -19,6 +19,9 @@ class Args {
|
||||||
@Parameter(names = arrayOf("--dev"), description = "Turn of dev mode, resulting in a more verbose log output")
|
@Parameter(names = arrayOf("--dev"), description = "Turn of dev mode, resulting in a more verbose log output")
|
||||||
var dev: Boolean = false
|
var dev: Boolean = false
|
||||||
|
|
||||||
|
@Parameter(names = arrayOf("--download"), description = "Force a download from the downloadUrl in the wrapper")
|
||||||
|
var download: Boolean = false
|
||||||
|
|
||||||
@Parameter(names = arrayOf("--dryRun"), description = "Display all the tasks that will get run without " +
|
@Parameter(names = arrayOf("--dryRun"), description = "Display all the tasks that will get run without " +
|
||||||
"actually running them")
|
"actually running them")
|
||||||
var dryRun: Boolean = false
|
var dryRun: Boolean = false
|
||||||
|
|
|
@ -14,7 +14,6 @@ import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.maven.KobaltException
|
import com.beust.kobalt.maven.KobaltException
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.*
|
||||||
import com.beust.kobalt.wrapper.Wrapper
|
|
||||||
import com.google.inject.Guice
|
import com.google.inject.Guice
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
@ -37,10 +36,10 @@ private fun parseArgs(argv: Array<String>): Main.RunInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public fun mainNoExit(argv: Array<String>) : Int {
|
public fun mainNoExit(argv: Array<String>): Int {
|
||||||
val (jc, args) = parseArgs(argv)
|
val (jc, args) = parseArgs(argv)
|
||||||
Kobalt.INJECTOR = Guice.createInjector(MainModule(args))
|
Kobalt.INJECTOR = Guice.createInjector(MainModule(args))
|
||||||
return Kobalt.INJECTOR.getInstance(Main::class.java).run(jc, args)
|
return Kobalt.INJECTOR.getInstance(Main::class.java).run(jc, args, argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Main @Inject constructor(
|
private class Main @Inject constructor(
|
||||||
|
@ -59,8 +58,7 @@ private class Main @Inject constructor(
|
||||||
val server: KobaltServer,
|
val server: KobaltServer,
|
||||||
val pluginInfo: PluginInfo,
|
val pluginInfo: PluginInfo,
|
||||||
val projectGenerator: ProjectGenerator,
|
val projectGenerator: ProjectGenerator,
|
||||||
val resolveDependency: ResolveDependency,
|
val resolveDependency: ResolveDependency) {
|
||||||
val wrapper: Wrapper) {
|
|
||||||
|
|
||||||
data class RunInfo(val jc: JCommander, val args: Args)
|
data class RunInfo(val jc: JCommander, val args: Args)
|
||||||
|
|
||||||
|
@ -71,7 +69,7 @@ private class Main @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun run(jc: JCommander, args: Args) : Int {
|
public fun run(jc: JCommander, args: Args, argv: Array<String>): Int {
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add all the repos from repo contributors (at least those that return values without a Project)
|
// Add all the repos from repo contributors (at least those that return values without a Project)
|
||||||
|
@ -93,9 +91,9 @@ private class Main @Inject constructor(
|
||||||
var result = 0
|
var result = 0
|
||||||
val latestVersionFuture = github.latestKobaltVersion
|
val latestVersionFuture = github.latestKobaltVersion
|
||||||
val seconds = benchmark("build", {
|
val seconds = benchmark("build", {
|
||||||
// runTest()
|
// runTest()
|
||||||
try {
|
try {
|
||||||
result = runWithArgs(jc, args)
|
result = runWithArgs(jc, args, argv)
|
||||||
} catch(ex: KobaltException) {
|
} catch(ex: KobaltException) {
|
||||||
error(ex.message ?: "", ex)
|
error(ex.message ?: "", ex)
|
||||||
result = 1
|
result = 1
|
||||||
|
@ -120,32 +118,33 @@ private class Main @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public fun runTest() {
|
// public fun runTest() {
|
||||||
// val file = File("src\\main\\resources\\META-INF\\plugin.ml")
|
// val file = File("src\\main\\resources\\META-INF\\plugin.ml")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private fun runWithArgs(jc: JCommander, args: Args) : Int {
|
private fun runWithArgs(jc: JCommander, args: Args, argv: Array<String>): Int {
|
||||||
var result = 0
|
var result = 0
|
||||||
val p = if (args.buildFile != null) File(args.buildFile) else findBuildFile()
|
val p = if (args.buildFile != null) File(args.buildFile) else findBuildFile()
|
||||||
args.buildFile = p.absolutePath
|
args.buildFile = p.absolutePath
|
||||||
val buildFile = BuildFile(Paths.get(p.absolutePath), p.name)
|
val buildFile = BuildFile(Paths.get(p.absolutePath), p.name)
|
||||||
|
|
||||||
if (! args.update) {
|
if (!args.update) {
|
||||||
println(AsciiArt.banner + Kobalt.version + "\n")
|
println(AsciiArt.banner + Kobalt.version + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.init) {
|
if (args.init) {
|
||||||
//
|
//
|
||||||
// --init: create a new build project and install the wrapper
|
// --init: create a new build project and install the wrapper
|
||||||
|
// Make sure the wrapper won't call us back with --no-launch
|
||||||
//
|
//
|
||||||
wrapper.install()
|
com.beust.kobalt.wrapper.Main.main(arrayOf("--no-launch") + argv)
|
||||||
projectGenerator.run(args)
|
projectGenerator.run(args)
|
||||||
} else if (args.usage) {
|
} else if (args.usage) {
|
||||||
jc.usage()
|
jc.usage()
|
||||||
} else if (args.serverMode) {
|
} else if (args.serverMode) {
|
||||||
server.run()
|
server.run()
|
||||||
} else {
|
} else {
|
||||||
if (! buildFile.exists()) {
|
if (!buildFile.exists()) {
|
||||||
error(buildFile.path.toFile().path + " does not exist")
|
error(buildFile.path.toFile().path + " does not exist")
|
||||||
} else {
|
} else {
|
||||||
val allProjects = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
val allProjects = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
||||||
|
@ -177,6 +176,8 @@ private class Main @Inject constructor(
|
||||||
println(sb.toString())
|
println(sb.toString())
|
||||||
} else if (args.checkVersions) {
|
} else if (args.checkVersions) {
|
||||||
checkVersions.run(allProjects)
|
checkVersions.run(allProjects)
|
||||||
|
} else if (args.download) {
|
||||||
|
updateKobalt.downloadKobalt()
|
||||||
} else if (args.update) {
|
} else if (args.update) {
|
||||||
updateKobalt.updateKobalt()
|
updateKobalt.updateKobalt()
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,6 +193,7 @@ private class Main @Inject constructor(
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findBuildFile(): File {
|
private fun findBuildFile(): File {
|
||||||
val files = arrayListOf("Build.kt", "build.kobalt", KFiles.src("build.kobalt"),
|
val files = arrayListOf("Build.kt", "build.kobalt", KFiles.src("build.kobalt"),
|
||||||
KFiles.src("Build.kt"))
|
KFiles.src("Build.kt"))
|
||||||
|
|
|
@ -15,12 +15,6 @@ class KobaltWrapperProperties @Inject constructor() {
|
||||||
private val PROPERTY_VERSION = "kobalt.version"
|
private val PROPERTY_VERSION = "kobalt.version"
|
||||||
private val PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl"
|
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) {
|
fun create(version: String) {
|
||||||
log(2, "Creating $file with $version and ${defaultUrlFor(version)}")
|
log(2, "Creating $file with $version and ${defaultUrlFor(version)}")
|
||||||
KFiles.saveFile(file, listOf(
|
KFiles.saveFile(file, listOf(
|
||||||
|
@ -29,7 +23,13 @@ class KobaltWrapperProperties @Inject constructor() {
|
||||||
).joinToString("\n"))
|
).joinToString("\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
val properties : Properties
|
private fun defaultUrlFor(version: String) =
|
||||||
|
"https://github.com/cbeust/kobalt/releases/download/$version/kobalt-$version.zip"
|
||||||
|
|
||||||
|
private val file: File
|
||||||
|
get() = File("$WRAPPER_DIR/$KOBALT_WRAPPER_PROPERTIES")
|
||||||
|
|
||||||
|
private val properties : Properties
|
||||||
get() {
|
get() {
|
||||||
val config = file
|
val config = file
|
||||||
if (!config.exists()) {
|
if (!config.exists()) {
|
||||||
|
@ -45,20 +45,5 @@ class KobaltWrapperProperties @Inject constructor() {
|
||||||
get() = properties.getProperty(PROPERTY_VERSION)
|
get() = properties.getProperty(PROPERTY_VERSION)
|
||||||
|
|
||||||
val downloadUrl : String
|
val downloadUrl : String
|
||||||
get() {
|
get() = properties.getProperty(PROPERTY_DOWNLOAD_URL)
|
||||||
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)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,17 @@ import javax.inject.Inject
|
||||||
/**
|
/**
|
||||||
* Update Kobalt to the latest version.
|
* Update Kobalt to the latest version.
|
||||||
*/
|
*/
|
||||||
public class UpdateKobalt @Inject constructor(val github: GithubApi, val kobaltWrapperProperties: KobaltWrapperProperties) {
|
public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapperProperties: KobaltWrapperProperties) {
|
||||||
fun updateKobalt() {
|
fun updateKobalt() {
|
||||||
val newVersion = github.latestKobaltVersion
|
val newVersion = github.latestKobaltVersion
|
||||||
kobaltWrapperProperties.maybeCreate(newVersion.get())
|
wrapperProperties.create(newVersion.get())
|
||||||
com.beust.kobalt.wrapper.main(arrayOf())
|
com.beust.kobalt.wrapper.Main.main(arrayOf())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download from the URL found in the kobalt-wrapper.properties regardless of what the latest version is
|
||||||
|
*/
|
||||||
|
fun downloadKobalt() {
|
||||||
|
com.beust.kobalt.wrapper.Main.main(arrayOf("--download"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,187 +1,170 @@
|
||||||
package com.beust.kobalt.wrapper
|
package com.beust.kobalt.wrapper
|
||||||
|
|
||||||
import com.beust.kobalt.JavaInfo
|
//public fun main(argv: Array<String>) {
|
||||||
import com.beust.kobalt.SystemProperties
|
// Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv)
|
||||||
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.InputStream
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.Paths
|
|
||||||
import java.util.*
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
|
|
||||||
public fun main(argv: Array<String>) {
|
|
||||||
Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download and install a new wrapper if requested.
|
* Download and install a new wrapper if requested.
|
||||||
*/
|
*/
|
||||||
public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){
|
//public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){
|
||||||
// kobalt.properties
|
// // kobalt.properties
|
||||||
private val KOBALT_PROPERTIES = "kobalt.properties"
|
// private val KOBALT_PROPERTIES = "kobalt.properties"
|
||||||
private val KOBALTW = "kobaltw"
|
// private val KOBALTW = "kobaltw"
|
||||||
|
//
|
||||||
val FILE_NAME = "kobalt"
|
// val FILE_NAME = "kobalt"
|
||||||
|
//
|
||||||
private val properties = Properties()
|
// private val properties = Properties()
|
||||||
|
//
|
||||||
public fun installAndLaunchMain(argv: Array<String>) {
|
// public fun installAndLaunchMain(argv: Array<String>) {
|
||||||
val kobaltJarFile = install()
|
// val kobaltJarFile = install()
|
||||||
launchMain(kobaltJarFile, argv)
|
// launchMain(kobaltJarFile, argv)
|
||||||
}
|
|
||||||
|
|
||||||
private fun readProperties(properties: Properties, ins: InputStream) {
|
|
||||||
properties.load(ins)
|
|
||||||
ins.close()
|
|
||||||
properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attemps to read kobalt.properties (which should always exist).
|
|
||||||
*/
|
|
||||||
private fun maybeCreateKobaltProperties() : Properties {
|
|
||||||
val result = Properties()
|
|
||||||
|
|
||||||
// kobalt.properties is internal to Kobalt
|
|
||||||
val url = javaClass.classLoader.getResource(KOBALT_PROPERTIES)
|
|
||||||
if (url != null) {
|
|
||||||
readProperties(result, url.openConnection().inputStream)
|
|
||||||
} else {
|
|
||||||
throw IllegalArgumentException("Couldn't find $KOBALT_PROPERTIES")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// private fun initWrapperFile(version: String) {
|
|
||||||
// val config = wrapperProperties.file
|
|
||||||
// if (! config.exists()) {
|
|
||||||
// wrapperProperties.create(version)
|
|
||||||
// }
|
|
||||||
// properties.load(FileReader(config))
|
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// private val wrapperVersion : String
|
// private fun readProperties(properties: Properties, ins: InputStream) {
|
||||||
// get() {
|
// properties.load(ins)
|
||||||
// return properties.getProperty(PROPERTY_VERSION)
|
// ins.close()
|
||||||
|
// properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// private val wrapperDownloadUrl : String
|
// /**
|
||||||
// get() {
|
// * Attemps to read kobalt.properties (which should always exist).
|
||||||
// return properties.getProperty(PROPERTY_DOWNLOAD_URL)
|
// */
|
||||||
|
// private fun maybeCreateKobaltProperties() : Properties {
|
||||||
|
// val result = Properties()
|
||||||
|
//
|
||||||
|
// // kobalt.properties is internal to Kobalt
|
||||||
|
// val url = javaClass.classLoader.getResource(KOBALT_PROPERTIES)
|
||||||
|
// if (url != null) {
|
||||||
|
// readProperties(result, url.openConnection().inputStream)
|
||||||
|
// } else {
|
||||||
|
// throw IllegalArgumentException("Couldn't find $KOBALT_PROPERTIES")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// fun urlFor(version: String) : String {
|
// return result
|
||||||
// // val URL = "https://dl.bintray.com/cbeust/generic/"
|
|
||||||
// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
|
|
||||||
// return wrapperDownloadUrl ?: defaultUrlFor(version)
|
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
/**
|
//// private fun initWrapperFile(version: String) {
|
||||||
* Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties
|
//// val config = wrapperProperties.file
|
||||||
*
|
//// if (! config.exists()) {
|
||||||
* @return the path to the Kobalt jar file
|
//// wrapperProperties.create(version)
|
||||||
*/
|
//// }
|
||||||
public fun install() : Path {
|
//// properties.load(FileReader(config))
|
||||||
val properties = maybeCreateKobaltProperties()
|
//// }
|
||||||
val version = properties.getProperty("kobalt.version")
|
////
|
||||||
wrapperProperties.maybeCreate(version)
|
//// private val wrapperVersion : String
|
||||||
log(2, "Wrapper version: ${wrapperProperties.version}")
|
//// get() {
|
||||||
|
//// return properties.getProperty(PROPERTY_VERSION)
|
||||||
val wrapperVersion = wrapperProperties.version
|
//// }
|
||||||
val fileName = "$FILE_NAME-$wrapperVersion.zip"
|
////
|
||||||
File(KFiles.distributionsDir).mkdirs()
|
//// private val wrapperDownloadUrl : String
|
||||||
val localZipFile = Paths.get(KFiles.distributionsDir, fileName)
|
//// get() {
|
||||||
val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion
|
//// return properties.getProperty(PROPERTY_DOWNLOAD_URL)
|
||||||
val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar")
|
//// }
|
||||||
if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) {
|
////
|
||||||
log(1, "Downloading $fileName")
|
//// fun urlFor(version: String) : String {
|
||||||
val fullUrl = wrapperProperties.downloadUrl
|
//// // val URL = "https://dl.bintray.com/cbeust/generic/"
|
||||||
val body = Http().get(fullUrl)
|
//// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
|
||||||
if (body.code == 200) {
|
//// return wrapperDownloadUrl ?: defaultUrlFor(version)
|
||||||
if (!Files.exists(localZipFile)) {
|
//// }
|
||||||
val target = localZipFile.toAbsolutePath()
|
//
|
||||||
val ins = body.getAsStream()
|
// /**
|
||||||
benchmark("Download .zip file") {
|
// * Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties
|
||||||
// This takes about eight seconds for a 21M file because of the extra copying, not good.
|
// *
|
||||||
// Should use Okio.sink(file) to create a Sink and then call readAll(fileSink) on
|
// * @return the path to the Kobalt jar file
|
||||||
// the BufferedSource returned in the ResponseBody
|
// */
|
||||||
Files.copy(ins, target)
|
// public fun install() : Path {
|
||||||
}
|
// val properties = maybeCreateKobaltProperties()
|
||||||
log(2, "$localZipFile downloaded, extracting it")
|
// val version = properties.getProperty("kobalt.version")
|
||||||
} else {
|
// wrapperProperties.maybeCreate(version)
|
||||||
log(2, "$localZipFile already exists, extracting it")
|
// log(2, "Wrapper version: ${wrapperProperties.version}")
|
||||||
}
|
//
|
||||||
|
// val wrapperVersion = wrapperProperties.version
|
||||||
//
|
// val fileName = "$FILE_NAME-$wrapperVersion.zip"
|
||||||
// Extract all the zip files
|
// File(KFiles.distributionsDir).mkdirs()
|
||||||
//
|
// val localZipFile = Paths.get(KFiles.distributionsDir, fileName)
|
||||||
val zipFile = ZipFile(localZipFile.toFile())
|
// val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion
|
||||||
val entries = zipFile.entries()
|
// val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar")
|
||||||
val outputDirectory = File(KFiles.distributionsDir)
|
// if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) {
|
||||||
outputDirectory.mkdirs()
|
// log(1, "Downloading $fileName")
|
||||||
while (entries.hasMoreElements()) {
|
// val fullUrl = wrapperProperties.downloadUrl
|
||||||
val entry = entries.nextElement()
|
// val body = Http().get(fullUrl)
|
||||||
val entryFile = File(entry.name)
|
// if (body.code == 200) {
|
||||||
if (entry.isDirectory) {
|
// if (!Files.exists(localZipFile)) {
|
||||||
entryFile.mkdirs()
|
// val target = localZipFile.toAbsolutePath()
|
||||||
} else {
|
// val ins = body.getAsStream()
|
||||||
val dest = Paths.get(zipOutputDir, entryFile.path)
|
// benchmark("Download .zip file") {
|
||||||
log(2, " Writing ${entry.name} to $dest")
|
// // This takes about eight seconds for a 21M file because of the extra copying, not good.
|
||||||
Files.createDirectories(dest.parent)
|
// // Should use Okio.sink(file) to create a Sink and then call readAll(fileSink) on
|
||||||
Files.copy(zipFile.getInputStream(entry),
|
// // the BufferedSource returned in the ResponseBody
|
||||||
dest,
|
// Files.copy(ins, target)
|
||||||
java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
// }
|
||||||
}
|
// log(2, "$localZipFile downloaded, extracting it")
|
||||||
}
|
// } else {
|
||||||
log(2, "$localZipFile extracted")
|
// log(2, "$localZipFile already exists, extracting it")
|
||||||
} else {
|
// }
|
||||||
error("Couldn't download $fullUrl")
|
//
|
||||||
}
|
// //
|
||||||
}
|
// // Extract all the zip files
|
||||||
|
// //
|
||||||
//
|
// val zipFile = ZipFile(localZipFile.toFile())
|
||||||
// Copy the wrapper files in the current kobalt/wrapper directory
|
// val entries = zipFile.entries()
|
||||||
//
|
// val outputDirectory = File(KFiles.distributionsDir)
|
||||||
log(2, "Copying the wrapper files...")
|
// outputDirectory.mkdirs()
|
||||||
arrayListOf(KOBALTW, "kobalt/wrapper/$FILE_NAME-wrapper.jar").forEach {
|
// while (entries.hasMoreElements()) {
|
||||||
val from = Paths.get(zipOutputDir, it)
|
// val entry = entries.nextElement()
|
||||||
val to = Paths.get(File(".").absolutePath, it)
|
// val entryFile = File(entry.name)
|
||||||
KFiles.copy(from, to, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
// if (entry.isDirectory) {
|
||||||
}
|
// entryFile.mkdirs()
|
||||||
File(KOBALTW).setExecutable(true)
|
// } else {
|
||||||
|
// val dest = Paths.get(zipOutputDir, entryFile.path)
|
||||||
return kobaltJarFile
|
// log(2, " Writing ${entry.name} to $dest")
|
||||||
}
|
// Files.createDirectories(dest.parent)
|
||||||
|
// Files.copy(zipFile.getInputStream(entry),
|
||||||
/**
|
// dest,
|
||||||
* Launch kobalt-xxx.jar
|
// java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||||
*
|
// }
|
||||||
* Note: currently launching it in a separate VM because both this jar file and the wrapper contain
|
// }
|
||||||
* the same classes, so the old classes will be run. Once wrapper.jar contains only the
|
// log(2, "$localZipFile extracted")
|
||||||
* wrapper class and nothing else from the Kobalt distribution, we can just invoke main from the same JVM here,
|
// } else {
|
||||||
* which will speed up the start up
|
// error("Couldn't download $fullUrl")
|
||||||
*/
|
// }
|
||||||
private fun launchMain(kobaltJarFile: Path, argv: Array<String>) {
|
// }
|
||||||
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
|
//
|
||||||
val java = jvm.javaExecutable
|
// //
|
||||||
|
// // Copy the wrapper files in the current kobalt/wrapper directory
|
||||||
val args = arrayListOf(
|
// //
|
||||||
java!!.absolutePath,
|
// log(2, "Copying the wrapper files...")
|
||||||
"-jar", kobaltJarFile.toFile().absolutePath)
|
// arrayListOf(KOBALTW, "kobalt/wrapper/$FILE_NAME-wrapper.jar").forEach {
|
||||||
args.addAll(argv)
|
// val from = Paths.get(zipOutputDir, it)
|
||||||
val pb = ProcessBuilder(args)
|
// val to = Paths.get(File(".").absolutePath, it)
|
||||||
pb.inheritIO()
|
// KFiles.copy(from, to, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||||
log(2, "Launching\n ${args.joinToString(" ")}")
|
// }
|
||||||
val process = pb.start()
|
// File(KOBALTW).setExecutable(true)
|
||||||
process.waitFor()
|
//
|
||||||
}
|
// return kobaltJarFile
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Launch kobalt-xxx.jar
|
||||||
|
// *
|
||||||
|
// * Note: currently launching it in a separate VM because both this jar file and the wrapper contain
|
||||||
|
// * the same classes, so the old classes will be run. Once wrapper.jar contains only the
|
||||||
|
// * wrapper class and nothing else from the Kobalt distribution, we can just invoke main from the same JVM here,
|
||||||
|
// * which will speed up the start up
|
||||||
|
// */
|
||||||
|
// private fun launchMain(kobaltJarFile: Path, argv: Array<String>) {
|
||||||
|
// val jvm = JavaInfo.create(File(SystemProperties.javaBase))
|
||||||
|
// val java = jvm.javaExecutable
|
||||||
|
//
|
||||||
|
// val args = arrayListOf(
|
||||||
|
// java!!.absolutePath,
|
||||||
|
// "-jar", kobaltJarFile.toFile().absolutePath)
|
||||||
|
// args.addAll(argv)
|
||||||
|
// val pb = ProcessBuilder(args)
|
||||||
|
// pb.inheritIO()
|
||||||
|
// log(2, "Launching\n ${args.joinToString(" ")}")
|
||||||
|
// val process = pb.start()
|
||||||
|
// process.waitFor()
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
kobalt.version=0.238
|
kobalt.version=0.244
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue