diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index 5654e57e..24e74a83 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -29,11 +29,11 @@ class Args { @Parameter(names = arrayOf("--help", "--usage"), description = "Display the help") var usage: Boolean = false - @Parameter(names = arrayOf("-i", "--init"), description = "Invoke the archetypes named, separated by a comma") - var archetypes : String? = null + @Parameter(names = arrayOf("-i", "--init"), description = "Invoke the templates named, separated by a comma") + var templates: String? = null - @Parameter(names = arrayOf("--listArchetypes"), description = "List the available archetypes") - var listArchetypes: Boolean = false + @Parameter(names = arrayOf("--listTemplates"), description = "List the available templates") + var listTemplates: Boolean = false @Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)") var log: Int = 1 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt deleted file mode 100644 index 0645f5aa..00000000 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.beust.kobalt.api - -import com.beust.kobalt.Args - -/** - * Plugins that want to participate in the --init process (they can generate files to initialize - * a new project). - */ -interface IInitContributor { - val archetypes: List -} - -interface IArchetype { - /** - * The name of this archetype. This is the name that will be looked up when passed to the --init - * argument. - */ - val archetypeName: String - - /** - * Description of this archetype. - */ - val archetypeDescription: String - - /** - * The plug-in this archetype belongs to. - */ - val pluginName: String - - /** - * Instructions to display to the user after a template has been generated. - */ - val instructions : String get() = "Build this project with `./kobaltw assemble`" - - /** - * Generate the files for this archetype. The parameter is the arguments that were passed to the kobaltw - * command. - */ - fun generateArchetype(args: Args, classLoader: ClassLoader) -} - diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITemplateContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITemplateContributor.kt new file mode 100644 index 00000000..38938ee3 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITemplateContributor.kt @@ -0,0 +1,41 @@ +package com.beust.kobalt.api + +import com.beust.kobalt.Args + +/** + * Plugins that want to participate in the --init process (they can generate files to initialize + * a new project). + */ +interface ITemplateContributor { + val templates: List +} + +interface ITemplate { + /** + * The name of this template. This is the name that will be looked up when passed to the --init + * argument. + */ + val templateName: String + + /** + * Description of this template. + */ + val templateDescription: String + + /** + * The plug-in this template belongs to. + */ + val pluginName: String + + /** + * Instructions to display to the user after a template has been generated. + */ + val instructions : String get() = "Build this project with `./kobaltw assemble`" + + /** + * Generate the files for this template. The parameter is the arguments that were passed to the kobaltw + * command. + */ + fun generateTemplate(args: Args, classLoader: ClassLoader) +} + diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index 8437c4b7..34c00333 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -59,7 +59,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val plugins = arrayListOf() val projectContributors = arrayListOf() val classpathContributors = arrayListOf() - val initContributors = arrayListOf() + val initContributors = arrayListOf() val repoContributors = arrayListOf() val compilerFlagContributors = arrayListOf() val compilerInterceptors = arrayListOf() @@ -147,7 +147,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { if (this is ICompilerFlagContributor) compilerFlagContributors.add(this) if (this is ICompilerInterceptor) compilerInterceptors.add(this) if (this is IDocContributor) docContributors.add(this) - if (this is IInitContributor) initContributors.add(this) + if (this is ITemplateContributor) initContributors.add(this) if (this is IPlugin) plugins.add(this) if (this is IProjectContributor) projectContributors.add(this) if (this is IRepoContributor) repoContributors.add(this) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 93e0760b..071e5d83 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -100,9 +100,9 @@ private class Main @Inject constructor( // pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) } - // --listArchetypes - if (args.listArchetypes) { - Archetypes().list(pluginInfo) + // --listTemplates + if (args.listTemplates) { + Templates().list(pluginInfo) return 0 } @@ -148,7 +148,7 @@ private class Main @Inject constructor( println(AsciiArt.banner + Kobalt.version + "\n") } - if (args.archetypes != null) { + if (args.templates != null) { // // --init: create a new build project and install the wrapper // Make sure the wrapper won't call us back with --noLaunch diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt index 364652eb..d9795f71 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt @@ -1,8 +1,7 @@ package com.beust.kobalt.app import com.beust.kobalt.Args -import com.beust.kobalt.api.IArchetype -import com.beust.kobalt.api.IInitContributor +import com.beust.kobalt.api.ITemplate import com.beust.kobalt.maven.Pom import com.beust.kobalt.misc.log import com.beust.kobalt.plugin.KobaltPlugin @@ -13,7 +12,7 @@ import java.util.* /** * Abstract base class for the build generators that use build-template.mustache. */ -abstract class BuildGenerator : IArchetype { +abstract class BuildGenerator : ITemplate { override val pluginName = KobaltPlugin.PLUGIN_NAME abstract val defaultSourceDirectories : HashSet @@ -33,7 +32,7 @@ abstract class BuildGenerator : IArchetype { } } - override fun generateArchetype(args: Args, classLoader: ClassLoader) { + override fun generateTemplate(args: Args, classLoader: ClassLoader) { val file = File(args.buildFile) if (! file.exists()) { PrintWriter(FileOutputStream(file)).use { @@ -91,7 +90,7 @@ abstract class BuildGenerator : IArchetype { put("directory", currentDir.absolutePath) put("sourceDirectories", defaultSourceDirectories) put("sourceDirectoriesTest", defaultTestDirectories) - put("imports", "import com.beust.kobalt.plugin.$archetypeName.*") + put("imports", "import com.beust.kobalt.plugin.$templateName.*") put("directive", "project") } diff --git a/src/main/kotlin/com/beust/kobalt/app/JarTemplate.kt b/src/main/kotlin/com/beust/kobalt/app/JarTemplate.kt index 6dc3b0b2..922b6526 100644 --- a/src/main/kotlin/com/beust/kobalt/app/JarTemplate.kt +++ b/src/main/kotlin/com/beust/kobalt/app/JarTemplate.kt @@ -1,7 +1,7 @@ package com.beust.kobalt.app import com.beust.kobalt.Args -import com.beust.kobalt.api.IArchetype +import com.beust.kobalt.api.ITemplate import com.beust.kobalt.misc.log import java.io.File import java.io.FileOutputStream @@ -10,7 +10,7 @@ import java.util.jar.JarInputStream /** * Base class for templates that simply decompress a jar file to generate their project. */ -abstract class JarTemplate(val jarName: String) : IArchetype { +abstract class JarTemplate(val jarName: String) : ITemplate { companion object { fun extractFile(ins: JarInputStream, destDir: File) { var entry = ins.nextEntry @@ -39,8 +39,8 @@ abstract class JarTemplate(val jarName: String) : IArchetype { } } - override fun generateArchetype(args: Args, classLoader: ClassLoader) { - log(1, "Generating archetype for Android with class loader $classLoader") + override fun generateTemplate(args: Args, classLoader: ClassLoader) { + log(2, "Generating template with class loader $classLoader") val destDir = File(".") val ins = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream) extractFile(ins, destDir) diff --git a/src/main/kotlin/com/beust/kobalt/app/KobaltPluginTemplate.kt b/src/main/kotlin/com/beust/kobalt/app/KobaltPluginTemplate.kt index 548ff11c..d193d829 100644 --- a/src/main/kotlin/com/beust/kobalt/app/KobaltPluginTemplate.kt +++ b/src/main/kotlin/com/beust/kobalt/app/KobaltPluginTemplate.kt @@ -1,19 +1,19 @@ package com.beust.kobalt.app -import com.beust.kobalt.api.IInitContributor +import com.beust.kobalt.api.ITemplateContributor import com.beust.kobalt.plugin.KobaltPlugin /** * Template that generates a Kobalt plug-in project. */ -class KobaltPluginTemplate : IInitContributor { - val pluginArchetype = object: JarTemplate("templates/plugin.jar") { - override val archetypeDescription = "Generate a sample Kobalt plug-in project" +class KobaltPluginTemplate : ITemplateContributor { + val pluginTemplate = object: JarTemplate("templates/plugin.jar") { + override val templateDescription = "Generate a sample Kobalt plug-in project" - override val archetypeName = "kobalt-plugin" + override val templateName = "kobalt-plugin" override val pluginName = KobaltPlugin.PLUGIN_NAME } - override val archetypes = listOf(pluginArchetype) + override val templates = listOf(pluginTemplate) } diff --git a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt index a8bd9e48..0976822a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt @@ -1,7 +1,7 @@ package com.beust.kobalt.app import com.beust.kobalt.Args -import com.beust.kobalt.api.IArchetype +import com.beust.kobalt.api.ITemplate import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.misc.log import com.beust.kobalt.misc.warn @@ -14,21 +14,21 @@ import java.io.File class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){ fun run(args: Args, classLoader: ClassLoader) { File(args.buildFile).parentFile.mkdirs() - val map = hashMapOf() + val map = hashMapOf() pluginInfo.initContributors.forEach { - it.archetypes.forEach { - map.put(it.archetypeName, it) + it.templates.forEach { + map.put(it.templateName, it) } } - args.archetypes?.split(",")?.forEach { archetypeName -> - val archetype = map[archetypeName] - if (archetype != null) { - log(2, "Running archetype $archetypeName") - archetype.generateArchetype(args, classLoader) - log(1, "\n\n" + archetype.instructions) + args.templates?.split(",")?.forEach { templateName -> + val template = map[templateName] + if (template != null) { + log(2, "Running template $templateName") + template.generateTemplate(args, classLoader) + log(1, "\n\n" + template.instructions) } else { - warn("Couldn't find any archetype named $archetypeName") + warn("Couldn't find any template named $templateName") } } } diff --git a/src/main/kotlin/com/beust/kobalt/app/Archetypes.kt b/src/main/kotlin/com/beust/kobalt/app/Templates.kt similarity index 55% rename from src/main/kotlin/com/beust/kobalt/app/Archetypes.kt rename to src/main/kotlin/com/beust/kobalt/app/Templates.kt index e8aa3a1d..6d09d882 100644 --- a/src/main/kotlin/com/beust/kobalt/app/Archetypes.kt +++ b/src/main/kotlin/com/beust/kobalt/app/Templates.kt @@ -1,29 +1,29 @@ package com.beust.kobalt.app -import com.beust.kobalt.api.IArchetype -import com.beust.kobalt.api.IInitContributor +import com.beust.kobalt.api.ITemplate +import com.beust.kobalt.api.ITemplateContributor import com.beust.kobalt.app.java.JavaBuildGenerator import com.beust.kobalt.app.kotlin.KotlinBuildGenerator import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.misc.log import com.google.common.collect.ArrayListMultimap -class Archetypes : IInitContributor { - override val archetypes = listOf(JavaBuildGenerator(), KotlinBuildGenerator()) +class Templates : ITemplateContributor { + override val templates = listOf(JavaBuildGenerator(), KotlinBuildGenerator()) fun list(pluginInfo: PluginInfo) { - val map = ArrayListMultimap.create() + val map = ArrayListMultimap.create() pluginInfo.initContributors.forEach { - it.archetypes.forEach { + it.templates.forEach { map.put(it.pluginName, it) } } - log(1, "Available archetypes") + log(1, "Available templates") map.keySet().forEach { log(1, " Plug-in: $it") map[it].forEach { - log(1, " \"" + it.archetypeName + "\"\t\t" + it.archetypeDescription) + log(1, " \"" + it.templateName + "\"\t\t" + it.templateDescription) } } } diff --git a/src/main/kotlin/com/beust/kobalt/app/java/JavaBuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/java/JavaBuildGenerator.kt index ca8651c4..7de2964a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/java/JavaBuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/java/JavaBuildGenerator.kt @@ -6,7 +6,7 @@ class JavaBuildGenerator: BuildGenerator() { override val defaultSourceDirectories = hashSetOf("src/main/java") override val defaultTestDirectories = hashSetOf("src/test/java") override val directive = "project" - override val archetypeName = "java" - override val archetypeDescription = "Generates a simple Java project" + override val templateName = "java" + override val templateDescription = "Generates a simple Java project" override val fileMatch = { f: String -> f.endsWith(".java") } } diff --git a/src/main/kotlin/com/beust/kobalt/app/kotlin/KotlinBuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/kotlin/KotlinBuildGenerator.kt index 517ac880..837f1793 100644 --- a/src/main/kotlin/com/beust/kobalt/app/kotlin/KotlinBuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/kotlin/KotlinBuildGenerator.kt @@ -6,8 +6,8 @@ class KotlinBuildGenerator : BuildGenerator() { override val defaultSourceDirectories = hashSetOf("src/main/kotlin") override val defaultTestDirectories = hashSetOf("src/test/kotlin") override val directive = "project" - override val archetypeName = "kotlin" - override val archetypeDescription = "Generates a simple Kotlin project" + override val templateName = "kotlin" + override val templateDescription = "Generates a simple Kotlin project" override val fileMatch = { f: String -> f.endsWith(".kt") } } diff --git a/src/main/resources/META-INF/kobalt-core-plugin.xml b/src/main/resources/META-INF/kobalt-core-plugin.xml index 9ff1bd10..e353de29 100644 --- a/src/main/resources/META-INF/kobalt-core-plugin.xml +++ b/src/main/resources/META-INF/kobalt-core-plugin.xml @@ -14,7 +14,7 @@ com.beust.kobalt.internal.JvmCompilerPlugin - com.beust.kobalt.app.Archetypes + com.beust.kobalt.app.Templates com.beust.kobalt.internal.JUnitRunner diff --git a/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt b/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt index f56dab30..aa1eba96 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/PomTest.kt @@ -56,7 +56,7 @@ class PomTest @Inject constructor() : KobaltTest() { file.deleteOnExit() val args = Args() args.buildFile = file.absolutePath - args.archetypes = "java" + args.templates = "java" ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)