From 3fdc7d8c5bd23b1efaa82c813428157a403dea59 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 13 Feb 2016 18:34:10 -0800 Subject: [PATCH] Better archetype error handling. --- .../com/beust/kobalt/app/ProjectGenerator.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt index 8686dea4..5b57d420 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt @@ -1,8 +1,10 @@ package com.beust.kobalt.app import com.beust.kobalt.Args +import com.beust.kobalt.api.IInitContributor import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.misc.log +import com.beust.kobalt.misc.warn import com.google.inject.Inject import java.io.File @@ -12,15 +14,17 @@ import java.io.File public class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){ fun run(args: Args) { File(args.buildFile).parentFile.mkdirs() - args.archetypes?.let { archetypes -> - val contributors = pluginInfo.initContributors.filter { archetypes.contains(it.archetypeName) } - if (contributors.size > 0) { - contributors.forEach { - log(2, "Running archetype ${it.archetypeName}") - it.generateArchetype(args) - } + val map = hashMapOf() + pluginInfo.initContributors.forEach { + map.put(it.archetypeName, it) + } + args.archetypes?.split(",")?.forEach { archetypeName -> + val contributor = map[archetypeName] + if (contributor != null) { + log(2, "Running archetype $archetypeName") + contributor.generateArchetype(args) } else { - log(1, "Couldn't find any archetype named ${args.archetypes}") + warn("Couldn't find any archetype named $archetypeName") } } }