1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-27 00:38:11 -07:00

Improve the archetype support.

This commit is contained in:
Cedric Beust 2016-02-14 05:49:19 -08:00
parent 3fdc7d8c5b
commit f6fe0e086e
10 changed files with 75 additions and 19 deletions

View file

@ -1,14 +1,8 @@
package com.beust.kobalt
import com.beust.jcommander.JCommander
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.Kobalt
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.api.*
import com.beust.kobalt.app.*
import com.beust.kobalt.app.remote.KobaltClient
import com.beust.kobalt.app.remote.KobaltServer
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.Http
import com.beust.kobalt.misc.*
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.HashMultimap
import com.google.inject.Guice
import java.io.File
@ -82,6 +77,12 @@ private class Main @Inject constructor(
//
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
// --listArchetypes
if (args.listArchetypes) {
Archetypes().list(pluginInfo)
return 0
}
if (args.client) {
client.run()
return 0

View 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)
}
}
}
}

View file

@ -1,9 +1,11 @@
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.maven.Pom
import com.beust.kobalt.misc.log
import com.beust.kobalt.plugin.KobaltPlugin
import com.github.mustachejava.DefaultMustacheFactory
import java.io.*
import java.util.*
@ -11,11 +13,12 @@ import java.util.*
/**
* 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 defaultTestDirectories : HashSet<String>
abstract val directive : String
override abstract val archetypeName: String
abstract val fileMatch : (String) -> Boolean
companion object {

View file

@ -1,6 +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.internal.PluginInfo
import com.beust.kobalt.misc.log
@ -11,18 +12,21 @@ import java.io.File
/**
* 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) {
File(args.buildFile).parentFile.mkdirs()
val map = hashMapOf<String, IInitContributor>()
val map = hashMapOf<String, IArchetype>()
pluginInfo.initContributors.forEach {
map.put(it.archetypeName, it)
it.archetypes.forEach {
map.put(it.archetypeName, it)
}
}
args.archetypes?.split(",")?.forEach { archetypeName ->
val contributor = map[archetypeName]
if (contributor != null) {
val archetype = map[archetypeName]
if (archetype != null) {
log(2, "Running archetype $archetypeName")
contributor.generateArchetype(args)
archetype.generateArchetype(args)
} else {
warn("Couldn't find any archetype named $archetypeName")
}

View file

@ -7,5 +7,6 @@ class JavaBuildGenerator: BuildGenerator() {
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 fileMatch = { f: String -> f.endsWith(".java") }
}

View file

@ -7,6 +7,7 @@ class KotlinBuildGenerator : BuildGenerator() {
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 fileMatch = { f: String -> f.endsWith(".kt") }
}

View file

@ -14,8 +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.java.JavaBuildGenerator</class-name>
<class-name>com.beust.kobalt.app.kotlin.KotlinBuildGenerator</class-name>
<class-name>com.beust.kobalt.app.Archetypes</class-name>
<!-- Test runners -->
<class-name>com.beust.kobalt.internal.JUnitRunner</class-name>