mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Rename archetype -> template.
This commit is contained in:
parent
d5e6a04b5d
commit
2b3aeabba2
14 changed files with 90 additions and 91 deletions
|
@ -29,11 +29,11 @@ class Args {
|
||||||
@Parameter(names = arrayOf("--help", "--usage"), description = "Display the help")
|
@Parameter(names = arrayOf("--help", "--usage"), description = "Display the help")
|
||||||
var usage: Boolean = false
|
var usage: Boolean = false
|
||||||
|
|
||||||
@Parameter(names = arrayOf("-i", "--init"), description = "Invoke the archetypes named, separated by a comma")
|
@Parameter(names = arrayOf("-i", "--init"), description = "Invoke the templates named, separated by a comma")
|
||||||
var archetypes : String? = null
|
var templates: String? = null
|
||||||
|
|
||||||
@Parameter(names = arrayOf("--listArchetypes"), description = "List the available archetypes")
|
@Parameter(names = arrayOf("--listTemplates"), description = "List the available templates")
|
||||||
var listArchetypes: Boolean = false
|
var listTemplates: Boolean = false
|
||||||
|
|
||||||
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
|
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
|
||||||
var log: Int = 1
|
var log: Int = 1
|
||||||
|
|
|
@ -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<IArchetype>
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -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<ITemplate>
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
val plugins = arrayListOf<IPlugin>()
|
val plugins = arrayListOf<IPlugin>()
|
||||||
val projectContributors = arrayListOf<IProjectContributor>()
|
val projectContributors = arrayListOf<IProjectContributor>()
|
||||||
val classpathContributors = arrayListOf<IClasspathContributor>()
|
val classpathContributors = arrayListOf<IClasspathContributor>()
|
||||||
val initContributors = arrayListOf<IInitContributor>()
|
val initContributors = arrayListOf<ITemplateContributor>()
|
||||||
val repoContributors = arrayListOf<IRepoContributor>()
|
val repoContributors = arrayListOf<IRepoContributor>()
|
||||||
val compilerFlagContributors = arrayListOf<ICompilerFlagContributor>()
|
val compilerFlagContributors = arrayListOf<ICompilerFlagContributor>()
|
||||||
val compilerInterceptors = arrayListOf<ICompilerInterceptor>()
|
val compilerInterceptors = arrayListOf<ICompilerInterceptor>()
|
||||||
|
@ -147,7 +147,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
if (this is ICompilerFlagContributor) compilerFlagContributors.add(this)
|
if (this is ICompilerFlagContributor) compilerFlagContributors.add(this)
|
||||||
if (this is ICompilerInterceptor) compilerInterceptors.add(this)
|
if (this is ICompilerInterceptor) compilerInterceptors.add(this)
|
||||||
if (this is IDocContributor) docContributors.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 IPlugin) plugins.add(this)
|
||||||
if (this is IProjectContributor) projectContributors.add(this)
|
if (this is IProjectContributor) projectContributors.add(this)
|
||||||
if (this is IRepoContributor) repoContributors.add(this)
|
if (this is IRepoContributor) repoContributors.add(this)
|
||||||
|
|
|
@ -100,9 +100,9 @@ private class Main @Inject constructor(
|
||||||
//
|
//
|
||||||
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
|
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
|
||||||
|
|
||||||
// --listArchetypes
|
// --listTemplates
|
||||||
if (args.listArchetypes) {
|
if (args.listTemplates) {
|
||||||
Archetypes().list(pluginInfo)
|
Templates().list(pluginInfo)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ private class Main @Inject constructor(
|
||||||
println(AsciiArt.banner + Kobalt.version + "\n")
|
println(AsciiArt.banner + Kobalt.version + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.archetypes != null) {
|
if (args.templates != null) {
|
||||||
//
|
//
|
||||||
// --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 --noLaunch
|
// Make sure the wrapper won't call us back with --noLaunch
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.IArchetype
|
import com.beust.kobalt.api.ITemplate
|
||||||
import com.beust.kobalt.api.IInitContributor
|
|
||||||
import com.beust.kobalt.maven.Pom
|
import com.beust.kobalt.maven.Pom
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.plugin.KobaltPlugin
|
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 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
|
override val pluginName = KobaltPlugin.PLUGIN_NAME
|
||||||
|
|
||||||
abstract val defaultSourceDirectories : HashSet<String>
|
abstract val defaultSourceDirectories : HashSet<String>
|
||||||
|
@ -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)
|
val file = File(args.buildFile)
|
||||||
if (! file.exists()) {
|
if (! file.exists()) {
|
||||||
PrintWriter(FileOutputStream(file)).use {
|
PrintWriter(FileOutputStream(file)).use {
|
||||||
|
@ -91,7 +90,7 @@ abstract class BuildGenerator : IArchetype {
|
||||||
put("directory", currentDir.absolutePath)
|
put("directory", currentDir.absolutePath)
|
||||||
put("sourceDirectories", defaultSourceDirectories)
|
put("sourceDirectories", defaultSourceDirectories)
|
||||||
put("sourceDirectoriesTest", defaultTestDirectories)
|
put("sourceDirectoriesTest", defaultTestDirectories)
|
||||||
put("imports", "import com.beust.kobalt.plugin.$archetypeName.*")
|
put("imports", "import com.beust.kobalt.plugin.$templateName.*")
|
||||||
put("directive", "project")
|
put("directive", "project")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.IArchetype
|
import com.beust.kobalt.api.ITemplate
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
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.
|
* 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 {
|
companion object {
|
||||||
fun extractFile(ins: JarInputStream, destDir: File) {
|
fun extractFile(ins: JarInputStream, destDir: File) {
|
||||||
var entry = ins.nextEntry
|
var entry = ins.nextEntry
|
||||||
|
@ -39,8 +39,8 @@ abstract class JarTemplate(val jarName: String) : IArchetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateArchetype(args: Args, classLoader: ClassLoader) {
|
override fun generateTemplate(args: Args, classLoader: ClassLoader) {
|
||||||
log(1, "Generating archetype for Android with class loader $classLoader")
|
log(2, "Generating template with class loader $classLoader")
|
||||||
val destDir = File(".")
|
val destDir = File(".")
|
||||||
val ins = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream)
|
val ins = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream)
|
||||||
extractFile(ins, destDir)
|
extractFile(ins, destDir)
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.api.IInitContributor
|
import com.beust.kobalt.api.ITemplateContributor
|
||||||
import com.beust.kobalt.plugin.KobaltPlugin
|
import com.beust.kobalt.plugin.KobaltPlugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template that generates a Kobalt plug-in project.
|
* Template that generates a Kobalt plug-in project.
|
||||||
*/
|
*/
|
||||||
class KobaltPluginTemplate : IInitContributor {
|
class KobaltPluginTemplate : ITemplateContributor {
|
||||||
val pluginArchetype = object: JarTemplate("templates/plugin.jar") {
|
val pluginTemplate = object: JarTemplate("templates/plugin.jar") {
|
||||||
override val archetypeDescription = "Generate a sample Kobalt plug-in project"
|
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 pluginName = KobaltPlugin.PLUGIN_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
override val archetypes = listOf(pluginArchetype)
|
override val templates = listOf(pluginTemplate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
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.internal.PluginInfo
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
|
@ -14,21 +14,21 @@ import java.io.File
|
||||||
class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
||||||
fun run(args: Args, classLoader: ClassLoader) {
|
fun run(args: Args, classLoader: ClassLoader) {
|
||||||
File(args.buildFile).parentFile.mkdirs()
|
File(args.buildFile).parentFile.mkdirs()
|
||||||
val map = hashMapOf<String, IArchetype>()
|
val map = hashMapOf<String, ITemplate>()
|
||||||
pluginInfo.initContributors.forEach {
|
pluginInfo.initContributors.forEach {
|
||||||
it.archetypes.forEach {
|
it.templates.forEach {
|
||||||
map.put(it.archetypeName, it)
|
map.put(it.templateName, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args.archetypes?.split(",")?.forEach { archetypeName ->
|
args.templates?.split(",")?.forEach { templateName ->
|
||||||
val archetype = map[archetypeName]
|
val template = map[templateName]
|
||||||
if (archetype != null) {
|
if (template != null) {
|
||||||
log(2, "Running archetype $archetypeName")
|
log(2, "Running template $templateName")
|
||||||
archetype.generateArchetype(args, classLoader)
|
template.generateTemplate(args, classLoader)
|
||||||
log(1, "\n\n" + archetype.instructions)
|
log(1, "\n\n" + template.instructions)
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any archetype named $archetypeName")
|
warn("Couldn't find any template named $templateName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.api.IArchetype
|
import com.beust.kobalt.api.ITemplate
|
||||||
import com.beust.kobalt.api.IInitContributor
|
import com.beust.kobalt.api.ITemplateContributor
|
||||||
import com.beust.kobalt.app.java.JavaBuildGenerator
|
import com.beust.kobalt.app.java.JavaBuildGenerator
|
||||||
import com.beust.kobalt.app.kotlin.KotlinBuildGenerator
|
import com.beust.kobalt.app.kotlin.KotlinBuildGenerator
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
|
|
||||||
class Archetypes : IInitContributor {
|
class Templates : ITemplateContributor {
|
||||||
override val archetypes = listOf(JavaBuildGenerator(), KotlinBuildGenerator())
|
override val templates = listOf(JavaBuildGenerator(), KotlinBuildGenerator())
|
||||||
|
|
||||||
fun list(pluginInfo: PluginInfo) {
|
fun list(pluginInfo: PluginInfo) {
|
||||||
val map = ArrayListMultimap.create<String, IArchetype>()
|
val map = ArrayListMultimap.create<String, ITemplate>()
|
||||||
pluginInfo.initContributors.forEach {
|
pluginInfo.initContributors.forEach {
|
||||||
it.archetypes.forEach {
|
it.templates.forEach {
|
||||||
map.put(it.pluginName, it)
|
map.put(it.pluginName, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log(1, "Available archetypes")
|
log(1, "Available templates")
|
||||||
map.keySet().forEach {
|
map.keySet().forEach {
|
||||||
log(1, " Plug-in: $it")
|
log(1, " Plug-in: $it")
|
||||||
map[it].forEach {
|
map[it].forEach {
|
||||||
log(1, " \"" + it.archetypeName + "\"\t\t" + it.archetypeDescription)
|
log(1, " \"" + it.templateName + "\"\t\t" + it.templateDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ class JavaBuildGenerator: BuildGenerator() {
|
||||||
override val defaultSourceDirectories = hashSetOf("src/main/java")
|
override val defaultSourceDirectories = hashSetOf("src/main/java")
|
||||||
override val defaultTestDirectories = hashSetOf("src/test/java")
|
override val defaultTestDirectories = hashSetOf("src/test/java")
|
||||||
override val directive = "project"
|
override val directive = "project"
|
||||||
override val archetypeName = "java"
|
override val templateName = "java"
|
||||||
override val archetypeDescription = "Generates a simple Java project"
|
override val templateDescription = "Generates a simple Java project"
|
||||||
override val fileMatch = { f: String -> f.endsWith(".java") }
|
override val fileMatch = { f: String -> f.endsWith(".java") }
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ class KotlinBuildGenerator : BuildGenerator() {
|
||||||
override val defaultSourceDirectories = hashSetOf("src/main/kotlin")
|
override val defaultSourceDirectories = hashSetOf("src/main/kotlin")
|
||||||
override val defaultTestDirectories = hashSetOf("src/test/kotlin")
|
override val defaultTestDirectories = hashSetOf("src/test/kotlin")
|
||||||
override val directive = "project"
|
override val directive = "project"
|
||||||
override val archetypeName = "kotlin"
|
override val templateName = "kotlin"
|
||||||
override val archetypeDescription = "Generates a simple Kotlin project"
|
override val templateDescription = "Generates a simple Kotlin project"
|
||||||
override val fileMatch = { f: String -> f.endsWith(".kt") }
|
override val fileMatch = { f: String -> f.endsWith(".kt") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<class-name>com.beust.kobalt.internal.JvmCompilerPlugin</class-name>
|
<class-name>com.beust.kobalt.internal.JvmCompilerPlugin</class-name>
|
||||||
|
|
||||||
<!-- These classes manage -init for Java and Kotlin -->
|
<!-- These classes manage -init for Java and Kotlin -->
|
||||||
<class-name>com.beust.kobalt.app.Archetypes</class-name>
|
<class-name>com.beust.kobalt.app.Templates</class-name>
|
||||||
|
|
||||||
<!-- Test runners -->
|
<!-- Test runners -->
|
||||||
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>
|
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>
|
||||||
|
|
|
@ -56,7 +56,7 @@ class PomTest @Inject constructor() : KobaltTest() {
|
||||||
file.deleteOnExit()
|
file.deleteOnExit()
|
||||||
val args = Args()
|
val args = Args()
|
||||||
args.buildFile = file.absolutePath
|
args.buildFile = file.absolutePath
|
||||||
args.archetypes = "java"
|
args.templates = "java"
|
||||||
|
|
||||||
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)
|
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue