From 5990e4baa8779e31b47092ca7cf602c458f97bba Mon Sep 17 00:00:00 2001 From: Dmitry Zhuravlev Date: Thu, 26 May 2016 13:52:32 +0300 Subject: [PATCH] #208 removing idea template --- .../kobalt-plugin-api/kobalt-plugin-api.iml | 843 +++++++++--------- modules/wrapper/kobalt-wrapper.iml | 2 +- .../com/beust/kobalt/app/IdeaFilesTemplate.kt | 230 ----- .../kotlin/com/beust/kobalt/app/Templates.kt | 2 +- 4 files changed, 419 insertions(+), 658 deletions(-) delete mode 100644 src/main/kotlin/com/beust/kobalt/app/IdeaFilesTemplate.kt diff --git a/modules/kobalt-plugin-api/kobalt-plugin-api.iml b/modules/kobalt-plugin-api/kobalt-plugin-api.iml index 54fa2296..7e463927 100644 --- a/modules/kobalt-plugin-api/kobalt-plugin-api.iml +++ b/modules/kobalt-plugin-api/kobalt-plugin-api.iml @@ -1,5 +1,5 @@ - + @@ -11,433 +11,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -446,7 +23,421 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/wrapper/kobalt-wrapper.iml b/modules/wrapper/kobalt-wrapper.iml index 1a90945d..edb06d17 100644 --- a/modules/wrapper/kobalt-wrapper.iml +++ b/modules/wrapper/kobalt-wrapper.iml @@ -1,5 +1,5 @@ - + diff --git a/src/main/kotlin/com/beust/kobalt/app/IdeaFilesTemplate.kt b/src/main/kotlin/com/beust/kobalt/app/IdeaFilesTemplate.kt deleted file mode 100644 index 884b1188..00000000 --- a/src/main/kotlin/com/beust/kobalt/app/IdeaFilesTemplate.kt +++ /dev/null @@ -1,230 +0,0 @@ -package com.beust.kobalt.app - -import com.beust.kobalt.Args -import com.beust.kobalt.Constants -import com.beust.kobalt.api.ITemplate -import com.beust.kobalt.api.ITemplateContributor -import com.beust.kobalt.api.Kobalt -import com.beust.kobalt.app.remote.DependencyData -import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.log -import com.beust.kobalt.plugin.KobaltPlugin -import com.google.inject.Inject -import java.io.File -import java.io.FileOutputStream -import java.nio.file.Paths - -/** - * A template that generates IDEA files. - */ -class IdeaFilesTemplate @Inject constructor() : ITemplate { - override val templateName = "idea" - override val templateDescription = "Generate files required by IDEA to build the project" - override val pluginName = KobaltPlugin.PLUGIN_NAME - - override val instructions = "IDEA files generated" - - companion object { - val IDEA_DIR = File(".idea").apply { mkdirs() } - val KOTLIN_JAVA_RUNTIME = "KotlinJavaRuntime" - } - - override fun generateTemplate(args: Args, classLoader: ClassLoader) { - val dependencyData = Kobalt.INJECTOR.getInstance(DependencyData::class.java) - val data = dependencyData.dependenciesDataFor(Constants.BUILD_FILE_PATH, args) - val outputDir = File(".")// KFiles.makeDir(".")//KFiles.makeDir(homeDir("t/idea")) - generateLibraries(classLoader, data, outputDir) - generateModulesXml(data, outputDir) - generateImlFiles(classLoader, data, outputDir) - generateMiscXml(classLoader, outputDir) - } - - private fun templatePath(fileName: String) = - KFiles.joinDir(ITemplateContributor.DIRECTORY_NAME, templateName, fileName) - - private fun writeTemplate(classLoader: ClassLoader, outputDir: File, fileName: String) { - val ins = classLoader.getResource(templatePath(fileName)).openConnection().inputStream - val outputFile = File(KFiles.joinDir(outputDir.absolutePath, fileName)) - outputFile.parentFile.mkdir() - FileOutputStream(outputFile).use { fos -> - KFiles.copy(ins, fos) - } - log(2, "Created " + outputFile.path) - } - - private fun generateMiscXml(classLoader: ClassLoader, outputDir: File) - = writeTemplate(classLoader, Paths.get(outputDir.path, IDEA_DIR.path).normalize().toFile(), "misc.xml") - - private fun generateImlFiles(classLoader: ClassLoader, data: DependencyData.GetDependenciesData, outputDir: File) { - // - // Build.kt.iml - // - writeTemplate(classLoader, File(KFiles.joinDir(outputDir.absolutePath, "kobalt")), "Build.kt.iml") - - // - // iml files for each individual project - // - data.projects.forEach { project -> - val file = File(outputDir.absolutePath, imlName(project)) - file.parentFile.mkdirs() - with(arrayListOf()) { - add("""""") - add("""""") - add(""" """) - - add("""""") - - add(" ") - - // - // Source directories - // - fun sourceDir(dir: String, isTest: Boolean) - = " " - - project.sourceDirs.filter { File(it).exists() }.forEach { sourceDir -> - add(sourceDir(sourceDir, false)) - } - project.testDirs.filter { File(it).exists() }.forEach { sourceDir -> - add(sourceDir(sourceDir, true)) - } - - add(""" """) - - // - // Libraries - // - add(""" """) - - (project.name + COMPILE_SUFFIX).let { - add(" ") - } - (project.name + TEST_SUFFIX).let { - add(" ") - } - val isKotlin = true - if (isKotlin) { - add(" ") - add(" ") - } - - // - // Dependent projects - // - project.dependentProjects.forEach { dp -> - add(""" """) - } - - add(" ") - add("") - - writeFile(this, file) - - } - } - } - - private fun imlName(project: DependencyData.ProjectData) = - Paths.get(KFiles.joinDir(project.directory, project.name + ".iml")).normalize().toString() - - private fun generateModulesXml(data: DependencyData.GetDependenciesData, outputDir: File) { - val modulesXmlFile = File(KFiles.joinDir(IDEA_DIR.path, outputDir.path, "modules.xml")) - with(arrayListOf()) { - add("""""") - add("""""") - add(""" """) - add(" ") - - fun moduleLine(iml: String) - = " " - - add(moduleLine("kobalt/Build.kt.iml")) - data.projects.forEach { - add(moduleLine(imlName(it))) - } - - add(" ") - add(" ") - add("") - writeFile(this, modulesXmlFile) - } - } - - private val COMPILE_SUFFIX = " (Compile)" - private val TEST_SUFFIX = " (Test)" - - private fun generateLibraries(classLoader: ClassLoader, data: DependencyData.GetDependenciesData, outputDir: File) { - data.projects.forEach { - generateLibrary(classLoader, it.name, it.compileDependencies, COMPILE_SUFFIX, outputDir) - generateLibrary(classLoader, it.name, it.testDependencies, TEST_SUFFIX, outputDir) - } - val kobaltDd = DependencyData.DependencyData("kobalt", "compile", - KFiles.joinDir(KFiles.distributionsDir, Kobalt.version, "kobalt", "wrapper", - "kobalt-${Kobalt.version}.jar")) - generateLibrary(classLoader, "kobalt.jar", listOf(kobaltDd), "", outputDir) - } - - private fun generateLibrary(classLoader: ClassLoader, name: String, - compileDependencies: List, - suffix: String, outputDir: File) { - val libraryName = name + suffix - val librariesOutputDir = KFiles.joinAndMakeDir(IDEA_DIR.path, outputDir.path, "libraries") - with(arrayListOf()) { - add("""""") - add(""" """) - addAll(generateList(compileDependencies, "CLASSES")) - addAll(generateList(emptyList(), "JAVADOC")) - addAll(generateList(emptyList(), "SOURCES")) - add(" ") - add("") - val fileName = libraryName.replace(" ", "_").replace("-", "_").replace("(", "_").replace(")", "_") - .replace(".", "_") - writeFile(this, File(librariesOutputDir, fileName + ".xml")) - } - - if (compileDependencies.any { it.id.contains("kotlin") }) { - generateKotlinJavaRuntime(classLoader, outputDir) - } - } - - private fun generateList(libraries: List, tag: String) : List { - if (libraries.isEmpty()){ - return listOf(" <$tag />") - } else { - val result = arrayListOf() - result.add(" <$tag>") - libraries.forEach { - val path = - if (it.path.contains(".kobalt")) { - val ind = it.path.indexOf(".kobalt") - "\$USER_HOME$/" + it.path.substring(ind) - } else { - it.path - } - result.add(" ") - } - - result.add(" ") - - return result - } - } - - private fun generateKotlinJavaRuntime(classLoader: ClassLoader, outputDir: File) { - writeTemplate(classLoader, - File(KFiles.joinDir(outputDir.path, IDEA_DIR.path, "libraries")), "KotlinJavaRuntime.xml") - with(File(outputDir.path, "lib")) { - mkdirs() - listOf("reflect", "runtime-sources", "runtime").forEach { - writeTemplate(classLoader, File(outputDir, path), "kotlin-$it.jar") - } - } - } - - private fun writeFile(lines: List, file: File) { - file.writeText(lines.joinToString("\n")) - log(2, "Created ${file.absolutePath}") - } -} diff --git a/src/main/kotlin/com/beust/kobalt/app/Templates.kt b/src/main/kotlin/com/beust/kobalt/app/Templates.kt index 20a1da1e..c034504d 100644 --- a/src/main/kotlin/com/beust/kobalt/app/Templates.kt +++ b/src/main/kotlin/com/beust/kobalt/app/Templates.kt @@ -10,7 +10,7 @@ import com.google.common.collect.ArrayListMultimap import com.google.common.collect.ListMultimap class Templates : ITemplateContributor { - override val templates = listOf(JavaTemplateGenerator(), KotlinTemplateGenerator(), IdeaFilesTemplate()) + override val templates = listOf(JavaTemplateGenerator(), KotlinTemplateGenerator()) fun getTemplates(pluginInfo: PluginInfo): ListMultimap { val map = ArrayListMultimap.create()