From 259d4a3cbaad6bf95ade23c4ea28a7c948614606 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 15 Dec 2015 03:10:11 +0400 Subject: [PATCH] Move classes to the app package. --- src/main/kotlin/com/beust/kobalt/Main.kt | 3 + .../{wrapper => app}/ParentLastClassLoader.kt | 4 +- .../kobalt/{ => app}/ProjectGenerator.kt | 3 +- .../kobalt/{misc => app}/UpdateKobalt.kt | 9 +- .../beust/kobalt/internal/BuildGenerator.kt | 2 +- .../com/beust/kobalt/internal/TaskManager.kt | 1 + .../kobalt/plugin/kotlin/KotlinCompiler.kt | 2 +- .../com/beust/kobalt/wrapper/Wrapper.kt | 170 ------------------ .../kotlin/com/beust/kobalt/TestModule.kt | 1 + .../kotlin/com/beust/kobalt/maven/PomTest.kt | 2 +- 10 files changed, 18 insertions(+), 179 deletions(-) rename src/main/kotlin/com/beust/kobalt/{wrapper => app}/ParentLastClassLoader.kt (97%) rename src/main/kotlin/com/beust/kobalt/{ => app}/ProjectGenerator.kt (95%) rename src/main/kotlin/com/beust/kobalt/{misc => app}/UpdateKobalt.kt (66%) delete mode 100644 src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index a0367cd9..f5eec45e 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -5,6 +5,9 @@ import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.Project +import com.beust.kobalt.Args +import com.beust.kobalt.app.ProjectGenerator +import com.beust.kobalt.app.UpdateKobalt import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.TaskManager import com.beust.kobalt.internal.build.BuildFile diff --git a/src/main/kotlin/com/beust/kobalt/wrapper/ParentLastClassLoader.kt b/src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt similarity index 97% rename from src/main/kotlin/com/beust/kobalt/wrapper/ParentLastClassLoader.kt rename to src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt index 6c25abb8..22bed44b 100644 --- a/src/main/kotlin/com/beust/kobalt/wrapper/ParentLastClassLoader.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt @@ -1,4 +1,4 @@ -package com.beust.kobalt.wrapper +package com.beust.kobalt.app import java.net.URL import java.net.URLClassLoader @@ -15,7 +15,7 @@ public class ParentLastClassLoader(val classpath: List) init { val urls : Array = classpath.toTypedArray() - childClassLoader = ChildURLClassLoader(urls, FindClassClassLoader(this.parent) ) + childClassLoader = ChildURLClassLoader(urls, FindClassClassLoader(this.parent)) } /** diff --git a/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt similarity index 95% rename from src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt rename to src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt index 1b97f97f..31717c81 100644 --- a/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt @@ -1,5 +1,6 @@ -package com.beust.kobalt +package com.beust.kobalt.app +import com.beust.kobalt.Args import com.beust.kobalt.internal.ActorUtils import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.misc.log diff --git a/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt similarity index 66% rename from src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt rename to src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 6b8a7cde..73d1a6d0 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -1,5 +1,8 @@ -package com.beust.kobalt.misc +package com.beust.kobalt.app +import com.beust.kobalt.misc.GithubApi +import com.beust.kobalt.misc.KobaltWrapperProperties +import com.beust.kobalt.wrapper.Main import javax.inject.Inject /** @@ -9,13 +12,13 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper fun updateKobalt() { val newVersion = github.latestKobaltVersion wrapperProperties.create(newVersion.get()) - com.beust.kobalt.wrapper.Main.main(arrayOf()) + 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", "--no-launch")) + Main.main(arrayOf("--download", "--no-launch")) } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt index 3df705af..a8dc7743 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.internal -import com.beust.kobalt.ProjectGenerator +import com.beust.kobalt.app.ProjectGenerator import com.beust.kobalt.api.IInitContributor import com.beust.kobalt.maven.Pom import com.beust.kobalt.misc.KFiles diff --git a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index bf3eb960..1ece86e3 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.api.IPlugin import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.Project import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.Args import com.beust.kobalt.misc.log import com.google.common.collect.ArrayListMultimap import com.google.common.collect.Multimap diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 59804a25..ac0f5a8a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -11,7 +11,7 @@ import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.log -import com.beust.kobalt.wrapper.ParentLastClassLoader +import com.beust.kobalt.app.ParentLastClassLoader import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler diff --git a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt b/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt deleted file mode 100644 index a2e9e25e..00000000 --- a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.beust.kobalt.wrapper - -//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)) -//// } -//// -//// 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/test/kotlin/com/beust/kobalt/TestModule.kt b/src/test/kotlin/com/beust/kobalt/TestModule.kt index 3f281e2d..b5775d27 100644 --- a/src/test/kotlin/com/beust/kobalt/TestModule.kt +++ b/src/test/kotlin/com/beust/kobalt/TestModule.kt @@ -1,5 +1,6 @@ package com.beust.kobalt +import com.beust.kobalt.Args import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.MainModule import com.google.inject.Scopes diff --git a/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt b/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt index 4c54de83..0484d4fb 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt @@ -2,7 +2,7 @@ package com.beust.kobalt.maven import com.beust.kobalt.Args import com.beust.kobalt.KobaltTest -import com.beust.kobalt.ProjectGenerator +import com.beust.kobalt.app.ProjectGenerator import com.beust.kobalt.internal.PluginInfo import com.google.inject.Inject import org.testng.Assert