Search in sources :

Example 6 with GenerableArtifact

use of com.devonfw.cobigen.api.to.GenerableArtifact in project cobigen by devonfw.

the class GenerateMojo method collectTemplates.

/**
 * Generates all templates for each input.
 *
 * @param cobiGen generator instance to be used for generation
 * @param inputs to be used for generation
 * @return the collected templates to be generated
 * @throws MojoFailureException if any problem occurred while generation
 */
private List<GenerableArtifact> collectTemplates(CobiGen cobiGen, List<Object> inputs) throws MojoFailureException {
    List<GenerableArtifact> generableArtifacts = new ArrayList<>();
    if (this.templates != null && !this.templates.isEmpty()) {
        if (this.templates.contains(ALL)) {
            if (this.templates.size() > 1) {
                throw new MojoFailureException("You specified the 'ALL' template to generate all available templates next to another template, which was most probably not intended.");
            }
            for (Object input : inputs) {
                generableArtifacts.addAll(cobiGen.getMatchingTemplates(input));
            }
        } else {
            for (Object input : inputs) {
                List<TemplateTo> matchingTemplates = cobiGen.getMatchingTemplates(input);
                List<String> configuredTemplates = new LinkedList<>(this.templates);
                for (TemplateTo template : matchingTemplates) {
                    if (this.templates.contains(template.getId())) {
                        generableArtifacts.add(template);
                        configuredTemplates.remove(template.getId());
                    }
                }
                // error handling for increments not found
                if (!configuredTemplates.isEmpty()) {
                    throw new MojoFailureException("Templates with ids '" + configuredTemplates + "' did not match package in folder '" + getStringRepresentation(input) + "'.");
                }
            }
        }
    }
    return generableArtifacts;
}
Also used : GenerableArtifact(com.devonfw.cobigen.api.to.GenerableArtifact) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo) LinkedList(java.util.LinkedList)

Aggregations

GenerableArtifact (com.devonfw.cobigen.api.to.GenerableArtifact)6 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)4 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)4 ArrayList (java.util.ArrayList)4 CobiGen (com.devonfw.cobigen.api.CobiGen)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 InputReaderException (com.devonfw.cobigen.api.exception.InputReaderException)2 MavenUtil (com.devonfw.cobigen.api.util.MavenUtil)2 Tuple (com.devonfw.cobigen.api.util.Tuple)2 CobiGenCLI (com.devonfw.cobigen.cli.CobiGenCLI)2 MessagesConstants (com.devonfw.cobigen.cli.constants.MessagesConstants)2 UserAbortException (com.devonfw.cobigen.cli.exceptions.UserAbortException)2 CobiGenUtils (com.devonfw.cobigen.cli.utils.CobiGenUtils)2 ParsingUtils (com.devonfw.cobigen.cli.utils.ParsingUtils)2 ValidationUtils (com.devonfw.cobigen.cli.utils.ValidationUtils)2 ConfigurationFinder (com.devonfw.cobigen.impl.util.ConfigurationFinder)2 FileSystemUtil (com.devonfw.cobigen.impl.util.FileSystemUtil)2 FormatterException (com.google.googlejavaformat.java.FormatterException)2 IOException (java.io.IOException)2