mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Expand —init to files and URL’s.
This commit is contained in:
parent
d583eb0066
commit
832c602563
4 changed files with 89 additions and 49 deletions
|
@ -1,7 +1,7 @@
|
|||
package com.beust.kobalt.app
|
||||
|
||||
import com.beust.kobalt.api.ITemplateContributor
|
||||
import com.beust.kobalt.api.JarTemplate
|
||||
import com.beust.kobalt.api.ResourceJarTemplate
|
||||
import com.beust.kobalt.plugin.KobaltPlugin
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,9 @@ class KobaltPluginTemplate : ITemplateContributor {
|
|||
val NAME = "kobaltPlugin"
|
||||
}
|
||||
|
||||
val pluginTemplate = object: JarTemplate(ITemplateContributor.DIRECTORY_NAME + "/$NAME/$NAME.jar") {
|
||||
val pluginTemplate = object: ResourceJarTemplate(
|
||||
ITemplateContributor.DIRECTORY_NAME + "/$NAME/$NAME.jar",
|
||||
this::class.java.classLoader) {
|
||||
override val templateDescription = "Generate a sample Kobalt plug-in project"
|
||||
|
||||
override val templateName = NAME
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.beust.kobalt.app
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.api.FileJarTemplate
|
||||
import com.beust.kobalt.api.HttpJarTemplate
|
||||
import com.beust.kobalt.api.ITemplate
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
|
@ -22,14 +24,31 @@ class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
|||
}
|
||||
|
||||
args.templates?.split(',')?.forEach { templateName ->
|
||||
val template = map[templateName]
|
||||
if (template != null) {
|
||||
|
||||
val finalTemplate: ITemplate? = map[templateName]
|
||||
?: if (File(templateName).exists()) {
|
||||
kobaltLog(2, "Found a template jar file at $templateName, extracting it")
|
||||
object : FileJarTemplate(templateName, classLoader) {
|
||||
override val templateDescription = "Extract jar template from file"
|
||||
override val templateName = "File template"
|
||||
override val pluginName = ""
|
||||
}
|
||||
} else if (templateName.startsWith("http://") || templateName.startsWith("https://")) {
|
||||
object : HttpJarTemplate(templateName, classLoader) {
|
||||
override val templateDescription = "Extract jar template from HTTP"
|
||||
override val templateName = "HTTP template"
|
||||
override val pluginName = ""
|
||||
}
|
||||
} else {
|
||||
warn("Couldn't find any template named $templateName")
|
||||
null
|
||||
}
|
||||
|
||||
finalTemplate?.let {
|
||||
kobaltLog(2, "Running template $templateName")
|
||||
template.generateTemplate(args, classLoader)
|
||||
it.generateTemplate(args, classLoader)
|
||||
kobaltLog(1, "\n\nTemplate \"$templateName\" installed")
|
||||
kobaltLog(1, template.instructions)
|
||||
} else {
|
||||
warn("Couldn't find any template named $templateName")
|
||||
kobaltLog(1, finalTemplate.instructions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue