mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Improve the archetype support.
This commit is contained in:
parent
3fdc7d8c5b
commit
f6fe0e086e
10 changed files with 75 additions and 19 deletions
|
@ -32,6 +32,9 @@ class Args {
|
||||||
@Parameter(names = arrayOf("-i", "--init"), description = "Invoke the archetypes named, separated by a comma")
|
@Parameter(names = arrayOf("-i", "--init"), description = "Invoke the archetypes named, separated by a comma")
|
||||||
var archetypes : String? = null
|
var archetypes : String? = null
|
||||||
|
|
||||||
|
@Parameter(names = arrayOf("--listArchetypes"), description = "List the available archetypes")
|
||||||
|
var listArchetypes: 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
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,26 @@ import com.beust.kobalt.Args
|
||||||
* a new project).
|
* a new project).
|
||||||
*/
|
*/
|
||||||
interface IInitContributor {
|
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
|
* The name of this archetype. This is the name that will be looked up when passed to the --init
|
||||||
* argument.
|
* argument.
|
||||||
*/
|
*/
|
||||||
val archetypeName: String
|
val archetypeName: String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of this archetype.
|
||||||
|
*/
|
||||||
|
val archetypeDescription: String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The plug-in this archetype belongs to.
|
||||||
|
*/
|
||||||
|
val pluginName: String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the files for this archetype. The parameter is the arguments that were passed to the kobaltw
|
* Generate the files for this archetype. The parameter is the arguments that were passed to the kobaltw
|
||||||
* command.
|
* command.
|
||||||
|
|
|
@ -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 as IInitContributor)
|
if (this is IInitContributor) 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)
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
import com.beust.jcommander.JCommander
|
import com.beust.jcommander.JCommander
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.app.*
|
||||||
import com.beust.kobalt.api.PluginTask
|
|
||||||
import com.beust.kobalt.api.Project
|
|
||||||
import com.beust.kobalt.app.BuildFileCompiler
|
|
||||||
import com.beust.kobalt.app.MainModule
|
|
||||||
import com.beust.kobalt.app.ProjectGenerator
|
|
||||||
import com.beust.kobalt.app.UpdateKobalt
|
|
||||||
import com.beust.kobalt.app.remote.KobaltClient
|
import com.beust.kobalt.app.remote.KobaltClient
|
||||||
import com.beust.kobalt.app.remote.KobaltServer
|
import com.beust.kobalt.app.remote.KobaltServer
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
|
@ -18,6 +12,7 @@ import com.beust.kobalt.internal.build.BuildFile
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
import com.beust.kobalt.maven.Http
|
import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.*
|
||||||
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import com.google.common.collect.HashMultimap
|
import com.google.common.collect.HashMultimap
|
||||||
import com.google.inject.Guice
|
import com.google.inject.Guice
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -82,6 +77,12 @@ private class Main @Inject constructor(
|
||||||
//
|
//
|
||||||
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
|
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
|
||||||
|
|
||||||
|
// --listArchetypes
|
||||||
|
if (args.listArchetypes) {
|
||||||
|
Archetypes().list(pluginInfo)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
if (args.client) {
|
if (args.client) {
|
||||||
client.run()
|
client.run()
|
||||||
return 0
|
return 0
|
||||||
|
|
30
src/main/kotlin/com/beust/kobalt/app/Archetypes.kt
Normal file
30
src/main/kotlin/com/beust/kobalt/app/Archetypes.kt
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.IArchetype
|
||||||
|
import com.beust.kobalt.api.IInitContributor
|
||||||
|
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())
|
||||||
|
|
||||||
|
fun list(pluginInfo: PluginInfo) {
|
||||||
|
val map = ArrayListMultimap.create<String, IArchetype>()
|
||||||
|
pluginInfo.initContributors.forEach {
|
||||||
|
it.archetypes.forEach {
|
||||||
|
map.put(it.pluginName, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log(1, "Available archetypes")
|
||||||
|
map.keySet().forEach {
|
||||||
|
log(1, " Plug-in: $it")
|
||||||
|
map[it].forEach {
|
||||||
|
log(1, " \"" + it.archetypeName + "\"\t\t" + it.archetypeDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
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.IInitContributor
|
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.github.mustachejava.DefaultMustacheFactory
|
import com.github.mustachejava.DefaultMustacheFactory
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -11,11 +13,12 @@ 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 : IInitContributor {
|
abstract class BuildGenerator : IArchetype {
|
||||||
|
override val pluginName = KobaltPlugin.PLUGIN_NAME
|
||||||
|
|
||||||
abstract val defaultSourceDirectories : HashSet<String>
|
abstract val defaultSourceDirectories : HashSet<String>
|
||||||
abstract val defaultTestDirectories : HashSet<String>
|
abstract val defaultTestDirectories : HashSet<String>
|
||||||
abstract val directive : String
|
abstract val directive : String
|
||||||
override abstract val archetypeName: String
|
|
||||||
abstract val fileMatch : (String) -> Boolean
|
abstract val fileMatch : (String) -> Boolean
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -1,6 +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.IInitContributor
|
import com.beust.kobalt.api.IInitContributor
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
|
@ -11,18 +12,21 @@ import java.io.File
|
||||||
/**
|
/**
|
||||||
* Invoked with --init. Generate a new project.
|
* Invoked with --init. Generate a new project.
|
||||||
*/
|
*/
|
||||||
public class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
||||||
fun run(args: Args) {
|
fun run(args: Args) {
|
||||||
File(args.buildFile).parentFile.mkdirs()
|
File(args.buildFile).parentFile.mkdirs()
|
||||||
val map = hashMapOf<String, IInitContributor>()
|
val map = hashMapOf<String, IArchetype>()
|
||||||
pluginInfo.initContributors.forEach {
|
pluginInfo.initContributors.forEach {
|
||||||
map.put(it.archetypeName, it)
|
it.archetypes.forEach {
|
||||||
|
map.put(it.archetypeName, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args.archetypes?.split(",")?.forEach { archetypeName ->
|
args.archetypes?.split(",")?.forEach { archetypeName ->
|
||||||
val contributor = map[archetypeName]
|
val archetype = map[archetypeName]
|
||||||
if (contributor != null) {
|
if (archetype != null) {
|
||||||
log(2, "Running archetype $archetypeName")
|
log(2, "Running archetype $archetypeName")
|
||||||
contributor.generateArchetype(args)
|
archetype.generateArchetype(args)
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any archetype named $archetypeName")
|
warn("Couldn't find any archetype named $archetypeName")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,6 @@ class JavaBuildGenerator: BuildGenerator() {
|
||||||
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 archetypeName = "java"
|
||||||
|
override val archetypeDescription = "Generates a simple Java project"
|
||||||
override val fileMatch = { f: String -> f.endsWith(".java") }
|
override val fileMatch = { f: String -> f.endsWith(".java") }
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ class KotlinBuildGenerator : BuildGenerator() {
|
||||||
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 archetypeName = "kotlin"
|
||||||
|
override val archetypeDescription = "Generates a simple Kotlin project"
|
||||||
override val fileMatch = { f: String -> f.endsWith(".kt") }
|
override val fileMatch = { f: String -> f.endsWith(".kt") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +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.java.JavaBuildGenerator</class-name>
|
<class-name>com.beust.kobalt.app.Archetypes</class-name>
|
||||||
<class-name>com.beust.kobalt.app.kotlin.KotlinBuildGenerator</class-name>
|
|
||||||
|
|
||||||
<!-- Test runners -->
|
<!-- Test runners -->
|
||||||
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>
|
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue