Search in sources :

Example 6 with Increment

use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testIncrementComposition_combiningAllPossibleReferences.

/**
 * Tests the correct resolution of references of templates / templateScans / increments.
 */
@Test
public void testIncrementComposition_combiningAllPossibleReferences() {
    // given
    TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_increment_composition");
    Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    // when
    Map<String, Template> templates = target.loadTemplates(trigger);
    Map<String, Increment> increments = target.loadIncrements(templates, trigger);
    // validation
    assertThat(templates).containsOnlyKeys("templateDecl", "prefix_scanned", "scanned", "prefix_scanned2", "scanned2");
    assertThat(increments).containsOnlyKeys("0", "1", "2");
    assertThat(increments.values()).hasSize(3);
    assertThat(increments.get("0").getTemplates()).extracting("name").containsOnly("templateDecl");
    assertThat(increments.get("1").getTemplates()).extracting("name").containsOnly("templateDecl", "prefix_scanned", "scanned", "scanned2");
    assertThat(increments.get("2").getTemplates()).extracting("name").containsOnly("templateDecl", "prefix_scanned", "scanned", "prefix_scanned2");
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Increment(com.devonfw.cobigen.impl.config.entity.Increment) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 7 with Increment

use of com.devonfw.cobigen.impl.config.entity.Increment 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)

Example 8 with Increment

use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testIncrementRefOutsideCurrentFile.

/**
 * Tests the correct resolution of incrementsRef from outside the current templates file. (Issue #678)
 */
@Test
public void testIncrementRefOutsideCurrentFile() {
    // given
    Trigger trigger = new Trigger("testingTrigger", "asdf", "valid_external_incrementref", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    Path config = Paths.get(new File(testFileRootPath).toURI());
    ConfigurationHolder configurationHolder = new ConfigurationHolder(config.toUri());
    TemplatesConfiguration templatesConfiguration = configurationHolder.readTemplatesConfiguration(trigger);
    Map<String, Increment> increments = templatesConfiguration.getIncrements();
    // validation
    assertThat(templatesConfiguration.getTrigger().getId()).isEqualTo("testingTrigger");
    assertThat(increments).containsOnlyKeys("3", "4", "5");
    Increment incrementThree = increments.get("3").getDependentIncrements().get(0);
    assertThat(incrementThree.getName()).isEqualTo("0");
    assertThat(incrementThree.getTemplates().size()).isEqualTo(1);
    Increment incrementFour = increments.get("4").getDependentIncrements().get(0);
    assertThat(incrementFour.getName()).isEqualTo("1");
    assertThat(incrementFour.getTemplates().size()).isEqualTo(4);
    Increment incrementFive = increments.get("5").getDependentIncrements().get(0);
    assertThat(incrementFive.getName()).isEqualTo("2");
    assertThat(incrementFive.getTemplates().size()).isEqualTo(4);
}
Also used : Path(java.nio.file.Path) Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Increment(com.devonfw.cobigen.impl.config.entity.Increment) ConfigurationHolder(com.devonfw.cobigen.impl.config.ConfigurationHolder) File(java.io.File) TemplatesConfiguration(com.devonfw.cobigen.impl.config.TemplatesConfiguration) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 9 with Increment

use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testCorrectResolutionOfTemplateScanReferences.

/**
 * Tests the correct resolution of template scan references in increments.
 *
 * @throws InvalidConfigurationException test fails
 */
@Test
public void testCorrectResolutionOfTemplateScanReferences() throws InvalidConfigurationException {
    // given
    TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_template_scan_references");
    Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    // when
    Map<String, Template> templates = reader.loadTemplates(trigger);
    Map<String, Increment> increments = reader.loadIncrements(templates, trigger);
    // validation
    assertThat(templates).containsOnlyKeys("prefix_foo_BarClass.java", "prefix_bar_Foo2Class.java", "prefix_foo_FooClass.java");
    assertThat(increments).containsOnlyKeys("test");
    assertThat(increments.get("test").getTemplates()).extracting("name").containsOnly("prefix_foo_BarClass.java", "prefix_foo_FooClass.java");
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Increment(com.devonfw.cobigen.impl.config.entity.Increment) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Aggregations

Increment (com.devonfw.cobigen.impl.config.entity.Increment)9 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)5 Template (com.devonfw.cobigen.impl.config.entity.Template)5 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)5 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)4 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)4 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)4 File (java.io.File)4 Test (org.junit.Test)4 ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)3 Increments (com.devonfw.cobigen.impl.config.entity.io.Increments)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)2 TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)2 ConfigurationConstants (com.devonfw.cobigen.api.constants.ConfigurationConstants)1 UnknownExpressionException (com.devonfw.cobigen.api.exception.UnknownExpressionException)1 TextTemplateEngine (com.devonfw.cobigen.api.extension.TextTemplateEngine)1 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)1 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)1