diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 06e43965..c7b6de8b 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -2,6 +2,7 @@ import com.beust.kobalt.api.License import com.beust.kobalt.api.Project import com.beust.kobalt.api.Scm +import com.beust.kobalt.file import com.beust.kobalt.homeDir import com.beust.kobalt.internal.TaskResult 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.kotlinProject import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.publish.jcenter import java.io.File import java.nio.file.Files import java.nio.file.Paths @@ -71,7 +73,8 @@ val kobalt = kotlinProject(wrapper) { "org.apache.maven:maven-model:3.3.3", "com.github.spullara.mustache.java:compiler:0.9.1", "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") } -// jcenter { -// publish = true -// file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") -// } + jcenter { + publish = true + file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") + } } fun readVersion() : String { diff --git a/kobalt/wrapper/kobalt-wrapper.jar b/kobalt/wrapper/kobalt-wrapper.jar index 5ae9002f..5542de57 100644 Binary files a/kobalt/wrapper/kobalt-wrapper.jar and b/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index fde79fa5..64f7a285 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1,2 +1 @@ -kobalt.version=0.238 -kobalt.downloadUrl=https://github.com/cbeust/kobalt/releases/download/0.238/kobalt-0.238.zip +kobalt.version=0.244 \ No newline at end of file diff --git a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java index e74ab74b..7bb703bd 100644 --- a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java +++ b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java @@ -34,8 +34,12 @@ public class Main { private static int logLevel = 1; private void installAndLaunchMain(String[] argv) throws IOException, InterruptedException { + boolean noLaunch = false; for (int i = 0; i < argv.length; i++) { switch(argv[i]) { + case "--no-launch": + noLaunch = true; + break; case "--log": logLevel = Integer.parseInt(argv[i + 1]); i++; @@ -43,7 +47,9 @@ public class Main { } } Path kobaltJarFile = installJarFile(); - launchMain(kobaltJarFile, argv); + if (! noLaunch) { + launchMain(kobaltJarFile, argv); + } } private void readProperties(Properties properties, InputStream ins) throws IOException { @@ -106,66 +112,62 @@ public class Main { Path kobaltJarFile = Paths.get(zipOutputDir, getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar"); if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) { - if (!Files.exists(localZipFile)) { - download(localZipFile.toFile()); - } + download(localZipFile.toFile()); + } - // - // Extract all the zip files - // - boolean success = false; - int retries = 0; - while (! success && retries < 2) { - try { - ZipFile zipFile = new ZipFile(localZipFile.toFile()); - Enumeration entries = zipFile.entries(); - File outputDirectory = new File(DISTRIBUTIONS_DIR); - outputDirectory.mkdirs(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - File entryFile = new File(entry.getName()); - if (entry.isDirectory()) { - entryFile.mkdirs(); - } else { - Path dest = Paths.get(zipOutputDir, entryFile.getPath()); - log(2, " Writing " + entry.getName() + " to " + dest); - Files.createDirectories(dest.getParent()); - Files.copy(zipFile.getInputStream(entry), dest, StandardCopyOption.REPLACE_EXISTING); - } + // + // Extract all the zip files + // + boolean success = false; + int retries = 0; + while (! success && retries < 2) { + try { + ZipFile zipFile = new ZipFile(localZipFile.toFile()); + Enumeration entries = zipFile.entries(); + File outputDirectory = new File(DISTRIBUTIONS_DIR); + outputDirectory.mkdirs(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + File entryFile = new File(entry.getName()); + if (entry.isDirectory()) { + entryFile.mkdirs(); + } else { + Path dest = Paths.get(zipOutputDir, entryFile.getPath()); + log(2, " Writing " + entry.getName() + " to " + dest); + Files.createDirectories(dest.getParent()); + 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 // - if (! version.equals(getWrapperVersion())) { - log(2, "Copying the wrapper files"); - for (String file : FILES) { - Path from = Paths.get(zipOutputDir, file); - Path to = Paths.get(new File(".").getAbsolutePath(), file); - try { - if (isWindows() && to.toFile().exists()) { - log(1, "Windows detected, not overwriting " + to); - } else { - Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); - } - } catch (IOException ex) { - log(1, "Couldn't copy " + from + " to " + to + ": " + ex.getMessage()); + boolean sameVersion = equals(getWrapperVersion()); + log(2, "Copying the wrapper files"); + for (String file : FILES) { + Path from = Paths.get(zipOutputDir, file); + Path to = Paths.get(new File(".").getAbsolutePath(), file); + try { + if (isWindows() && to.toFile().exists()) { + log(1, "Windows detected, not overwriting " + to); + } else { + Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); } + } 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; } @@ -267,8 +269,6 @@ public class Main { 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 { List args = new ArrayList<>(); args.add("java"); diff --git a/src/main/kotlin/com/beust/kobalt/Args.kt b/src/main/kotlin/com/beust/kobalt/Args.kt index d910349f..cb058639 100644 --- a/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/src/main/kotlin/com/beust/kobalt/Args.kt @@ -19,6 +19,9 @@ class Args { @Parameter(names = arrayOf("--dev"), description = "Turn of dev mode, resulting in a more verbose log output") 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 " + "actually running them") var dryRun: Boolean = false diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index a16867dc..8706a767 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -14,7 +14,6 @@ import com.beust.kobalt.maven.Http import com.beust.kobalt.maven.KobaltException import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.* -import com.beust.kobalt.wrapper.Wrapper import com.google.inject.Guice import java.io.File import java.nio.file.Paths @@ -37,10 +36,10 @@ private fun parseArgs(argv: Array): Main.RunInfo { } -public fun mainNoExit(argv: Array) : Int { +public fun mainNoExit(argv: Array): Int { val (jc, args) = parseArgs(argv) 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( @@ -59,19 +58,18 @@ private class Main @Inject constructor( val server: KobaltServer, val pluginInfo: PluginInfo, val projectGenerator: ProjectGenerator, - val resolveDependency: ResolveDependency, - val wrapper: Wrapper) { + val resolveDependency: ResolveDependency) { data class RunInfo(val jc: JCommander, val args: Args) private fun addReposFromContributors(project: Project?) = - pluginInfo.repoContributors.forEach { - it.reposFor(project).forEach { - Kobalt.addRepo(it.toString()) + pluginInfo.repoContributors.forEach { + it.reposFor(project).forEach { + Kobalt.addRepo(it.toString()) + } } - } - public fun run(jc: JCommander, args: Args) : Int { + public fun run(jc: JCommander, args: Args, argv: Array): Int { // // 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 val latestVersionFuture = github.latestKobaltVersion val seconds = benchmark("build", { -// runTest() + // runTest() try { - result = runWithArgs(jc, args) + result = runWithArgs(jc, args, argv) } catch(ex: KobaltException) { error(ex.message ?: "", ex) result = 1 @@ -120,32 +118,33 @@ private class Main @Inject constructor( } -// public fun runTest() { -// val file = File("src\\main\\resources\\META-INF\\plugin.ml") -// } + // public fun runTest() { + // 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): Int { var result = 0 val p = if (args.buildFile != null) File(args.buildFile) else findBuildFile() args.buildFile = p.absolutePath val buildFile = BuildFile(Paths.get(p.absolutePath), p.name) - if (! args.update) { + if (!args.update) { println(AsciiArt.banner + Kobalt.version + "\n") } if (args.init) { // // --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) } else if (args.usage) { jc.usage() } else if (args.serverMode) { server.run() } else { - if (! buildFile.exists()) { + if (!buildFile.exists()) { error(buildFile.path.toFile().path + " does not exist") } else { val allProjects = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo) @@ -177,6 +176,8 @@ private class Main @Inject constructor( println(sb.toString()) } else if (args.checkVersions) { checkVersions.run(allProjects) + } else if (args.download) { + updateKobalt.downloadKobalt() } else if (args.update) { updateKobalt.updateKobalt() } else { @@ -192,6 +193,7 @@ private class Main @Inject constructor( } return result } + private fun findBuildFile(): File { val files = arrayListOf("Build.kt", "build.kobalt", KFiles.src("build.kobalt"), KFiles.src("Build.kt")) diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt b/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt index f18ecece..80fcc72a 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt @@ -15,12 +15,6 @@ class KobaltWrapperProperties @Inject constructor() { 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( @@ -29,7 +23,13 @@ class KobaltWrapperProperties @Inject constructor() { ).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() { val config = file if (!config.exists()) { @@ -45,20 +45,5 @@ class KobaltWrapperProperties @Inject constructor() { 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) -// } + get() = properties.getProperty(PROPERTY_DOWNLOAD_URL) } diff --git a/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt index 5040d86b..08dba92a 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt @@ -5,10 +5,17 @@ import javax.inject.Inject /** * 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() { val newVersion = github.latestKobaltVersion - kobaltWrapperProperties.maybeCreate(newVersion.get()) - com.beust.kobalt.wrapper.main(arrayOf()) + wrapperProperties.create(newVersion.get()) + 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")) } } diff --git a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt b/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt index 743ea432..a2e9e25e 100644 --- a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt +++ b/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt @@ -1,187 +1,170 @@ package com.beust.kobalt.wrapper -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.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) { - Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv) -} +//public fun main(argv: Array) { +// Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv) +//} /** * Download and install a new wrapper if requested. */ -public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){ - // kobalt.properties - private val KOBALT_PROPERTIES = "kobalt.properties" - private val KOBALTW = "kobaltw" - - val FILE_NAME = "kobalt" - - private val properties = Properties() - - public fun installAndLaunchMain(argv: Array) { - val kobaltJarFile = install() - 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)) +//public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){ +// // kobalt.properties +// private val KOBALT_PROPERTIES = "kobalt.properties" +// private val KOBALTW = "kobaltw" +// +// val FILE_NAME = "kobalt" +// +// private val properties = Properties() +// +// public fun installAndLaunchMain(argv: Array) { +// val kobaltJarFile = install() +// launchMain(kobaltJarFile, argv) // } // -// 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) +// private fun readProperties(properties: Properties, ins: InputStream) { +// properties.load(ins) +// ins.close() +// properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) } // } - - /** - * Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties - * - * @return the path to the Kobalt jar file - */ - public fun install() : Path { - 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) - val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion - val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar") - if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) { - log(1, "Downloading $fileName") - val fullUrl = wrapperProperties.downloadUrl - val body = Http().get(fullUrl) - if (body.code == 200) { - if (!Files.exists(localZipFile)) { - val target = localZipFile.toAbsolutePath() - val ins = body.getAsStream() - benchmark("Download .zip file") { - // 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 - // the BufferedSource returned in the ResponseBody - Files.copy(ins, target) - } - log(2, "$localZipFile downloaded, extracting it") - } else { - log(2, "$localZipFile already exists, extracting it") - } - - // - // Extract all the zip files - // - val zipFile = ZipFile(localZipFile.toFile()) - val entries = zipFile.entries() - val outputDirectory = File(KFiles.distributionsDir) - outputDirectory.mkdirs() - while (entries.hasMoreElements()) { - val entry = entries.nextElement() - val entryFile = File(entry.name) - if (entry.isDirectory) { - entryFile.mkdirs() - } else { - val dest = Paths.get(zipOutputDir, entryFile.path) - log(2, " Writing ${entry.name} to $dest") - Files.createDirectories(dest.parent) - Files.copy(zipFile.getInputStream(entry), - dest, - java.nio.file.StandardCopyOption.REPLACE_EXISTING) - } - } - 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) { - 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() - } -} +// +// /** +// * 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 +//// 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 +// * +// * @return the path to the Kobalt jar file +// */ +// public fun install() : Path { +// 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) +// val zipOutputDir = KFiles.distributionsDir + "/" + wrapperVersion +// val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar") +// if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) { +// log(1, "Downloading $fileName") +// val fullUrl = wrapperProperties.downloadUrl +// val body = Http().get(fullUrl) +// if (body.code == 200) { +// if (!Files.exists(localZipFile)) { +// val target = localZipFile.toAbsolutePath() +// val ins = body.getAsStream() +// benchmark("Download .zip file") { +// // 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 +// // the BufferedSource returned in the ResponseBody +// Files.copy(ins, target) +// } +// log(2, "$localZipFile downloaded, extracting it") +// } else { +// log(2, "$localZipFile already exists, extracting it") +// } +// +// // +// // Extract all the zip files +// // +// val zipFile = ZipFile(localZipFile.toFile()) +// val entries = zipFile.entries() +// val outputDirectory = File(KFiles.distributionsDir) +// outputDirectory.mkdirs() +// while (entries.hasMoreElements()) { +// val entry = entries.nextElement() +// val entryFile = File(entry.name) +// if (entry.isDirectory) { +// entryFile.mkdirs() +// } else { +// val dest = Paths.get(zipOutputDir, entryFile.path) +// log(2, " Writing ${entry.name} to $dest") +// Files.createDirectories(dest.parent) +// Files.copy(zipFile.getInputStream(entry), +// dest, +// java.nio.file.StandardCopyOption.REPLACE_EXISTING) +// } +// } +// 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) { +// 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() +// } +//} diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index b27d957c..b28a10ab 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1,2 +1,2 @@ -kobalt.version=0.238 +kobalt.version=0.244