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

Support for --download.

This commit is contained in:
Cedric Beust 2015-11-10 13:13:23 -08:00
parent 13b87527f6
commit ae7511be25
10 changed files with 264 additions and 282 deletions

View file

@ -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.

View file

@ -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

View file

@ -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,7 +47,9 @@ public class Main {
} }
} }
Path kobaltJarFile = installJarFile(); Path kobaltJarFile = installJarFile();
launchMain(kobaltJarFile, argv); if (! noLaunch) {
launchMain(kobaltJarFile, argv);
}
} }
private void readProperties(Properties properties, InputStream ins) throws IOException { private void readProperties(Properties properties, InputStream ins) throws IOException {
@ -106,66 +112,62 @@ 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()); }
}
// //
// Extract all the zip files // Extract all the zip files
// //
boolean success = false; boolean success = false;
int retries = 0; int retries = 0;
while (! success && retries < 2) { while (! success && retries < 2) {
try { try {
ZipFile zipFile = new ZipFile(localZipFile.toFile()); ZipFile zipFile = new ZipFile(localZipFile.toFile());
Enumeration<? extends ZipEntry> entries = zipFile.entries(); Enumeration<? extends ZipEntry> entries = zipFile.entries();
File outputDirectory = new File(DISTRIBUTIONS_DIR); File outputDirectory = new File(DISTRIBUTIONS_DIR);
outputDirectory.mkdirs(); outputDirectory.mkdirs();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement(); ZipEntry entry = entries.nextElement();
File entryFile = new File(entry.getName()); File entryFile = new File(entry.getName());
if (entry.isDirectory()) { if (entry.isDirectory()) {
entryFile.mkdirs(); entryFile.mkdirs();
} else { } else {
Path dest = Paths.get(zipOutputDir, entryFile.getPath()); Path dest = Paths.get(zipOutputDir, entryFile.getPath());
log(2, " Writing " + entry.getName() + " to " + dest); log(2, " Writing " + entry.getName() + " to " + dest);
Files.createDirectories(dest.getParent()); Files.createDirectories(dest.getParent());
Files.copy(zipFile.getInputStream(entry), dest, StandardCopyOption.REPLACE_EXISTING); Files.copy(zipFile.getInputStream(entry), dest, StandardCopyOption.REPLACE_EXISTING);
}
} }
success = true;
} catch (ZipException e) {
retries++;
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile);
download(localZipFile.toFile());
} }
success = true;
} catch (ZipException e) {
retries++;
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile);
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);
Path to = Paths.get(new File(".").getAbsolutePath(), file); Path to = Paths.get(new File(".").getAbsolutePath(), file);
try { try {
if (isWindows() && to.toFile().exists()) { if (isWindows() && to.toFile().exists()) {
log(1, "Windows detected, not overwriting " + to); log(1, "Windows detected, not overwriting " + to);
} else { } else {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException ex) {
log(1, "Couldn't copy " + from + " to " + to + ": " + ex.getMessage());
} }
} catch (IOException ex) {
log(1, "Couldn't copy " + from + " to " + to + ": " + ex.getMessage());
} }
new File(KOBALTW).setExecutable(true);
} else {
log(2, "Wrapper and current versions are identical");
} }
new File(KOBALTW).setExecutable(true);
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");

View file

@ -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

View file

@ -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,19 +58,18 @@ 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)
private fun addReposFromContributors(project: Project?) = private fun addReposFromContributors(project: Project?) =
pluginInfo.repoContributors.forEach { pluginInfo.repoContributors.forEach {
it.reposFor(project).forEach { it.reposFor(project).forEach {
Kobalt.addRepo(it.toString()) Kobalt.addRepo(it.toString())
}
} }
}
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"))

View file

@ -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)
// }
} }

View file

@ -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"))
} }
} }

View file

@ -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() {
// 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 // * Attemps to read kobalt.properties (which should always exist).
* // */
* @return the path to the Kobalt jar file // private fun maybeCreateKobaltProperties() : Properties {
*/ // val result = Properties()
public fun install() : Path { //
val properties = maybeCreateKobaltProperties() // // kobalt.properties is internal to Kobalt
val version = properties.getProperty("kobalt.version") // val url = javaClass.classLoader.getResource(KOBALT_PROPERTIES)
wrapperProperties.maybeCreate(version) // if (url != null) {
log(2, "Wrapper version: ${wrapperProperties.version}") // readProperties(result, url.openConnection().inputStream)
// } else {
val wrapperVersion = wrapperProperties.version // throw IllegalArgumentException("Couldn't find $KOBALT_PROPERTIES")
val fileName = "$FILE_NAME-$wrapperVersion.zip" // }
File(KFiles.distributionsDir).mkdirs() //
val localZipFile = Paths.get(KFiles.distributionsDir, fileName) // return result
val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion // }
val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar") //
if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) { //// private fun initWrapperFile(version: String) {
log(1, "Downloading $fileName") //// val config = wrapperProperties.file
val fullUrl = wrapperProperties.downloadUrl //// if (! config.exists()) {
val body = Http().get(fullUrl) //// wrapperProperties.create(version)
if (body.code == 200) { //// }
if (!Files.exists(localZipFile)) { //// properties.load(FileReader(config))
val target = localZipFile.toAbsolutePath() //// }
val ins = body.getAsStream() ////
benchmark("Download .zip file") { //// private val wrapperVersion : String
// This takes about eight seconds for a 21M file because of the extra copying, not good. //// get() {
// Should use Okio.sink(file) to create a Sink and then call readAll(fileSink) on //// return properties.getProperty(PROPERTY_VERSION)
// the BufferedSource returned in the ResponseBody //// }
Files.copy(ins, target) ////
} //// private val wrapperDownloadUrl : String
log(2, "$localZipFile downloaded, extracting it") //// get() {
} else { //// return properties.getProperty(PROPERTY_DOWNLOAD_URL)
log(2, "$localZipFile already exists, extracting it") //// }
} ////
//// fun urlFor(version: String) : String {
// //// // val URL = "https://dl.bintray.com/cbeust/generic/"
// Extract all the zip files //// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
// //// return wrapperDownloadUrl ?: defaultUrlFor(version)
val zipFile = ZipFile(localZipFile.toFile()) //// }
val entries = zipFile.entries() //
val outputDirectory = File(KFiles.distributionsDir) // /**
outputDirectory.mkdirs() // * Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties
while (entries.hasMoreElements()) { // *
val entry = entries.nextElement() // * @return the path to the Kobalt jar file
val entryFile = File(entry.name) // */
if (entry.isDirectory) { // public fun install() : Path {
entryFile.mkdirs() // val properties = maybeCreateKobaltProperties()
} else { // val version = properties.getProperty("kobalt.version")
val dest = Paths.get(zipOutputDir, entryFile.path) // wrapperProperties.maybeCreate(version)
log(2, " Writing ${entry.name} to $dest") // log(2, "Wrapper version: ${wrapperProperties.version}")
Files.createDirectories(dest.parent) //
Files.copy(zipFile.getInputStream(entry), // val wrapperVersion = wrapperProperties.version
dest, // val fileName = "$FILE_NAME-$wrapperVersion.zip"
java.nio.file.StandardCopyOption.REPLACE_EXISTING) // File(KFiles.distributionsDir).mkdirs()
} // val localZipFile = Paths.get(KFiles.distributionsDir, fileName)
} // val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion
log(2, "$localZipFile extracted") // val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar")
} else { // if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) {
error("Couldn't download $fullUrl") // log(1, "Downloading $fileName")
} // val fullUrl = wrapperProperties.downloadUrl
} // val body = Http().get(fullUrl)
// if (body.code == 200) {
// // if (!Files.exists(localZipFile)) {
// Copy the wrapper files in the current kobalt/wrapper directory // val target = localZipFile.toAbsolutePath()
// // val ins = body.getAsStream()
log(2, "Copying the wrapper files...") // benchmark("Download .zip file") {
arrayListOf(KOBALTW, "kobalt/wrapper/$FILE_NAME-wrapper.jar").forEach { // // This takes about eight seconds for a 21M file because of the extra copying, not good.
val from = Paths.get(zipOutputDir, it) // // Should use Okio.sink(file) to create a Sink and then call readAll(fileSink) on
val to = Paths.get(File(".").absolutePath, it) // // the BufferedSource returned in the ResponseBody
KFiles.copy(from, to, java.nio.file.StandardCopyOption.REPLACE_EXISTING) // Files.copy(ins, target)
} // }
File(KOBALTW).setExecutable(true) // log(2, "$localZipFile downloaded, extracting it")
// } else {
return kobaltJarFile // log(2, "$localZipFile already exists, extracting it")
} // }
//
/** // //
* Launch kobalt-xxx.jar // // Extract all the zip files
* // //
* Note: currently launching it in a separate VM because both this jar file and the wrapper contain // val zipFile = ZipFile(localZipFile.toFile())
* the same classes, so the old classes will be run. Once wrapper.jar contains only the // val entries = zipFile.entries()
* wrapper class and nothing else from the Kobalt distribution, we can just invoke main from the same JVM here, // val outputDirectory = File(KFiles.distributionsDir)
* which will speed up the start up // outputDirectory.mkdirs()
*/ // while (entries.hasMoreElements()) {
private fun launchMain(kobaltJarFile: Path, argv: Array<String>) { // val entry = entries.nextElement()
val jvm = JavaInfo.create(File(SystemProperties.javaBase)) // val entryFile = File(entry.name)
val java = jvm.javaExecutable // if (entry.isDirectory) {
// entryFile.mkdirs()
val args = arrayListOf( // } else {
java!!.absolutePath, // val dest = Paths.get(zipOutputDir, entryFile.path)
"-jar", kobaltJarFile.toFile().absolutePath) // log(2, " Writing ${entry.name} to $dest")
args.addAll(argv) // Files.createDirectories(dest.parent)
val pb = ProcessBuilder(args) // Files.copy(zipFile.getInputStream(entry),
pb.inheritIO() // dest,
log(2, "Launching\n ${args.joinToString(" ")}") // java.nio.file.StandardCopyOption.REPLACE_EXISTING)
val process = pb.start() // }
process.waitFor() // }
} // log(2, "$localZipFile extracted")
} // } else {
// error("Couldn't download $fullUrl")
// }
// }
//
// //
// // Copy the wrapper files in the current kobalt/wrapper directory
// //
// log(2, "Copying the wrapper files...")
// arrayListOf(KOBALTW, "kobalt/wrapper/$FILE_NAME-wrapper.jar").forEach {
// val from = Paths.get(zipOutputDir, it)
// val to = Paths.get(File(".").absolutePath, it)
// KFiles.copy(from, to, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
// }
// File(KOBALTW).setExecutable(true)
//
// 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()
// }
//}

View file

@ -1,2 +1,2 @@
kobalt.version=0.238 kobalt.version=0.244