Search in sources :

Example 6 with Trigger

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

the class TemplatesConfigurationReaderTest method testTemplatesSourceFolder.

@Test
public void testTemplatesSourceFolder() {
    // given
    TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_source_folder");
    Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    // when
    Map<String, Template> templates = target.loadTemplates(trigger);
    // then
    assertThat(templates).isNotNull().hasSize(6);
    String templateIdFooClass = "prefix_FooClass.java";
    Template templateFooClass = templates.get(templateIdFooClass);
    assertThat(templateFooClass).isNotNull();
    assertThat(templateFooClass.getName()).isEqualTo(templateIdFooClass);
    assertThat(templateFooClass.getRelativeTemplatePath()).isEqualTo("foo/FooClass.java.ftl");
    assertThat(templateFooClass.getUnresolvedTargetPath()).isEqualTo("src/main/java/foo/FooClass.java");
    assertThat(templateFooClass.getMergeStrategy()).isNull();
}
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) 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 Trigger

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

the class TemplatesConfigurationReaderTest method testRelocate_withTemplateFilenameEnding.

/**
 * Test relocate while the template is defined with the template file ending, which should be removed on destination
 * path resolution.
 */
@Test
public void testRelocate_withTemplateFilenameEnding() {
    // given
    String templatesConfigurationRoot = testFileRootPath + "valid_relocate_template_fileending/";
    TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_relocate_template_fileending/");
    Trigger trigger = new Trigger("id", "type", "valid_relocate", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    // when
    Map<String, Template> templates = target.loadTemplates(trigger);
    // validation
    assertThat(templates).hasSize(1);
    String staticRelocationPrefix = "../server/";
    String templateName = "$_Component_$Impl.java";
    Template template = templates.get(templateName);
    assertThat(template).isNotNull();
    String pathWithName = "$_rootpackage_$/$_component_$/logic/impl/" + templateName;
    assertThat(template.getRelativeTemplatePath()).isEqualTo("templates/" + pathWithName + ".ftl");
    assertThat(template.getAbsoluteTemplatePath().toString().replace('\\', '/')).isEqualTo(templatesConfigurationRoot + "templates/" + pathWithName + ".ftl");
    assertThat(template.getUnresolvedTemplatePath()).isEqualTo("src/main/java/" + pathWithName);
    assertThat(template.getUnresolvedTargetPath()).isEqualTo(staticRelocationPrefix + pathWithName);
}
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) 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 8 with Trigger

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

the class ConfigurationInterpreterImpl method getMatchingTriggerIds.

@Cached
@Override
public List<String> getMatchingTriggerIds(Object matcherInput) {
    LOG.debug("Matching trigger IDs requested.");
    List<String> matchingTriggerIds = Lists.newLinkedList();
    for (Trigger trigger : this.triggerMatchingEvaluator.getMatchingTriggers(matcherInput)) {
        matchingTriggerIds.add(trigger.getId());
    }
    LOG.debug("{} matching trigger IDs found.", matchingTriggerIds.size());
    return matchingTriggerIds;
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 9 with Trigger

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

the class HealthCheckImpl method upgradeAllConfigurations.

@Override
public HealthCheckReport upgradeAllConfigurations(Path contextConfigurationPath, BackupPolicy backupPolicy) {
    try {
        upgradeContextConfiguration(contextConfigurationPath, backupPolicy);
    } catch (BackupFailedException e) {
        upgradeContextConfiguration(contextConfigurationPath, BackupPolicy.NO_BACKUP);
    }
    ContextConfiguration contextConfiguration = new ContextConfiguration(contextConfigurationPath);
    List<String> expectedTemplatesConfigurations = new ArrayList<>();
    Set<String> hasConfiguration = Sets.newHashSet();
    Map<String, Path> upgradeableConfigurations = this.healthCheckReport.getUpgradeableConfigurations();
    for (Trigger t : contextConfiguration.getTriggers()) {
        expectedTemplatesConfigurations.add(t.getTemplateFolder());
        hasConfiguration.add(t.getTemplateFolder());
    }
    this.healthCheckReport.setHasConfiguration(hasConfiguration);
    upgradeableConfigurations.put("TempOne", contextConfigurationPath.resolve("TempOne"));
    this.healthCheckReport.setUpgradeableConfigurations(upgradeableConfigurations);
    if (expectedTemplatesConfigurations.containsAll(this.healthCheckReport.getHasConfiguration())) {
        for (final String key : expectedTemplatesConfigurations) {
            if (this.healthCheckReport.getUpgradeableConfigurations().containsKey(key)) {
                upgradeTemplatesConfiguration(this.healthCheckReport.getUpgradeableConfigurations().get(key), backupPolicy);
            }
        }
    } else {
        LOG.error("Expected template configuration does not equal the actual template configuration");
        throw new CobiGenRuntimeException("Update of the templates configuration was not successful, please retry");
    }
    return this.healthCheckReport;
}
Also used : Path(java.nio.file.Path) Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) CobiGenRuntimeException(com.devonfw.cobigen.api.exception.CobiGenRuntimeException) BackupFailedException(com.devonfw.cobigen.impl.exceptions.BackupFailedException) ArrayList(java.util.ArrayList) ContextConfiguration(com.devonfw.cobigen.impl.config.ContextConfiguration)

Example 10 with Trigger

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

the class TemplatesConfigurationReaderTest method testRelocate_propertiesResolution.

/**
 * Tests the correct property inheritance and resolution of cobigen.properties within a template set read by a
 * template scan.
 */
@Test
public void testRelocate_propertiesResolution() {
    // arrange
    TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_relocate_propertiesresolution/");
    Trigger trigger = new Trigger("id", "type", "valid_relocate", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    // act
    Map<String, Template> templates = target.loadTemplates(trigger);
    assertThat(templates).hasSize(2);
    // assert
    Template template = templates.get("$_Component_$.java");
    assertThat(template).isNotNull();
    assertThat(template.getVariables().asMap()).isNotNull().containsEntry("foo", "root").containsEntry("bar", "barValue");
    template = templates.get("$_EntityName_$Eto.java");
    assertThat(template).isNotNull();
    assertThat(template.getVariables().asMap()).isNotNull().containsEntry("relocate", "../api2/${cwd}").containsEntry("foo", "logic.api.to").containsEntry("bar", "barValue").containsEntry("local", "localValue");
}
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) 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

Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)30 File (java.io.File)20 Template (com.devonfw.cobigen.impl.config.entity.Template)19 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)18 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)17 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)17 Test (org.junit.Test)17 TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)15 Path (java.nio.file.Path)9 ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)5 Increment (com.devonfw.cobigen.impl.config.entity.Increment)5 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)4 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)4 Cached (com.devonfw.cobigen.api.annotation.Cached)3 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)2 TextTemplateEngine (com.devonfw.cobigen.api.extension.TextTemplateEngine)2 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)2