mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Rename archetype -> template.
This commit is contained in:
parent
d5e6a04b5d
commit
2b3aeabba2
14 changed files with 90 additions and 91 deletions
|
@ -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
|
||||
|
|
|
@ -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<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)
|
||||
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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<String, IArchetype>()
|
||||
val map = hashMapOf<String, ITemplate>()
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, IArchetype>()
|
||||
val map = ArrayListMultimap.create<String, ITemplate>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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") }
|
||||
}
|
||||
|
|
|
@ -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") }
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<class-name>com.beust.kobalt.internal.JvmCompilerPlugin</class-name>
|
||||
|
||||
<!-- 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 -->
|
||||
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue