Search in sources :

Example 41 with TemplateTo

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

the class ConfigurationInterpreterImpl method convertIncrements.

/**
 * Converts a {@link List} of {@link Increment}s with their parent {@link Trigger} to a {@link List} of
 * {@link IncrementTo}s
 *
 * @param increments the {@link List} of {@link Increment}s
 * @param trigger the parent {@link Trigger}
 * @param matchingTriggerIds the {@link List} of matching trigger Id
 * @return the {@link List} of {@link IncrementTo}s
 */
// TODO create ToConverter
private List<IncrementTo> convertIncrements(List<Increment> increments, Trigger trigger, List<String> matchingTriggerIds) {
    List<IncrementTo> incrementTos = Lists.newLinkedList();
    for (Increment increment : increments) {
        String triggerId = increment.getTrigger().getId();
        if (!triggerId.equals(trigger.getId())) {
            // Check if the external trigger also matches
            if (!matchingTriggerIds.contains(triggerId)) {
                // Abort generation
                throw new InvalidConfigurationException("An external incrementRef to " + increment.getTrigger().getId() + "::" + increment.getName() + " is referenced from " + trigger.getId() + " but its trigger does not match");
            }
        }
        List<TemplateTo> templates = Lists.newLinkedList();
        for (Template template : increment.getTemplates()) {
            templates.add(new TemplateTo(template.getName(), template.getMergeStrategy(), triggerId));
        }
        incrementTos.add(new IncrementTo(increment.getName(), increment.getDescription(), triggerId, templates, convertIncrements(increment.getDependentIncrements(), trigger, matchingTriggerIds)));
    }
    return incrementTos;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) Increment(com.devonfw.cobigen.impl.config.entity.Increment) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException) Template(com.devonfw.cobigen.impl.config.entity.Template)

Aggregations

TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)41 CobiGen (com.devonfw.cobigen.api.CobiGen)30 File (java.io.File)28 Test (org.junit.Test)27 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)25 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)12 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)9 Path (java.nio.file.Path)9 List (java.util.List)9 AssertionFailedError (junit.framework.AssertionFailedError)9 Paths (java.nio.file.Paths)6 Set (java.util.Set)6 HashSet (java.util.HashSet)5 Collectors (java.util.stream.Collectors)5 CobiGenAsserts.assertThat (com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat)4 GenerationReportToAssert (com.devonfw.cobigen.api.assertj.GenerationReportToAssert)4 ComparableIncrement (com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement)4 CobiGenFactory (com.devonfw.cobigen.impl.CobiGenFactory)4 AbstractIntegrationTest (com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)4 StandardCharsets (java.nio.charset.StandardCharsets)4