From 5422cad0d2ed48d1c2daa3b45163d7545c04289a Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Wed, 13 Nov 2019 11:28:30 +0100 Subject: [PATCH 1/9] #1059 Set next development version --- cobigen/cobigen-core-parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen/cobigen-core-parent/pom.xml b/cobigen/cobigen-core-parent/pom.xml index deeb74a347..715b76f716 100644 --- a/cobigen/cobigen-core-parent/pom.xml +++ b/cobigen/cobigen-core-parent/pom.xml @@ -12,7 +12,7 @@ - 6.0.0-SNAPSHOT + 6.1.0-SNAPSHOT From bc0d91d73b20559b22d32a3d2899faa154aee1a1 Mon Sep 17 00:00:00 2001 From: LarsReinken Date: Wed, 29 Jan 2020 09:32:14 +0100 Subject: [PATCH 2/9] make the update bar show Progress and make the generation cancelable (#1057) * make the update bar show Progress and make the generation cancelable * change the message on cancellation * #1059 set release snapshot version * #1059 Set next development version * #867 move try into for-loop * #867 add cancellationException documentation Co-authored-by: Malte Brunnlieb --- .../java/com/devonfw/cobigen/api/CobiGen.java | 29 +++++++++ .../CobiGenCancellationException.java | 15 +++++ .../cobigen/api/to/GenerationReportTo.java | 23 ++++++++ .../cobigen/impl/generator/CobiGenImpl.java | 16 ++++- .../generator/GenerationProcessorImpl.java | 59 ++++++++++++------- .../generator/api/GenerationProcessor.java | 4 +- 6 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/CobiGenCancellationException.java diff --git a/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/CobiGen.java b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/CobiGen.java index 56319c917e..2f359c7096 100644 --- a/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/CobiGen.java +++ b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/CobiGen.java @@ -3,6 +3,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; import com.devonfw.cobigen.api.annotation.ExceptionFacade; import com.devonfw.cobigen.api.extension.ModelBuilder; @@ -74,6 +75,34 @@ public GenerationReportTo generate(Object input, List generableArtifacts, Path targetRootPath, boolean forceOverride, List> logicClasses); + /** + * Generates code by processing the {@link List} of {@link GenerableArtifact}s for the given input. + * + * @param input + * generator input object + * @param generableArtifacts + * a {@link List} of artifacts to be generated + * @param targetRootPath + * target root path to generate to (to be used to resolve the dependent template destination + * paths) + * @param forceOverride + * if true and the destination path is already existent, the contents will be + * overwritten by the generated ones iff there is no merge strategy defined by the templates + * configuration. (default: {@code false}) + * @param logicClasses + * a {@link List} of java class files, which will be included as accessible beans in the + * template model. Such classes can be used to implement more complex template logic. + * @param rawModel + * externally adapted model to be used for generation. + * @param progressCallback + * expects the progress in percent as Integer + * @return The {@link GenerationReportTo generation report} covering the actual status of success, a list + * of warnings, as well as a list of error messages. + */ + public GenerationReportTo generate(Object input, List generableArtifacts, + Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel, + BiConsumer progressCallback); + /** * Generates code by processing the {@link List} of {@link GenerableArtifact}s for the given input. * diff --git a/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/CobiGenCancellationException.java b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/CobiGenCancellationException.java new file mode 100644 index 0000000000..31e150a1aa --- /dev/null +++ b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/CobiGenCancellationException.java @@ -0,0 +1,15 @@ +package com.devonfw.cobigen.api.exception; + +import java.util.concurrent.CancellationException; + +/** + * Exception is thrown if the generation Process is Cancelled + */ +public class CobiGenCancellationException extends CancellationException { + + /** + * Default serial version UID. + */ + private static final long serialVersionUID = 1L; + +} diff --git a/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/to/GenerationReportTo.java b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/to/GenerationReportTo.java index 2c908b7450..0a1deb8129 100644 --- a/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/to/GenerationReportTo.java +++ b/cobigen/cobigen-core-parent/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/to/GenerationReportTo.java @@ -26,6 +26,11 @@ public class GenerationReportTo { /** @see #getGeneratedFiles() */ private Set generatedFiles = new TreeSet<>(); + /** + * @see #isCancelled() + */ + private boolean cancelled = false; + /** * @see #getGeneratedFiles() * @param file @@ -165,4 +170,22 @@ public boolean hasErrors() { public boolean isSuccessful() { return errors.isEmpty(); } + + /** + * Return whether the generation got cancelled by the user + * @return true if it got cancelled, false otherwise + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * set's whether the generation got cancelled or not + * @param cancelled + * if generation got cancelled + */ + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + } diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/CobiGenImpl.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/CobiGenImpl.java index e93bea3942..84ad7e810d 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/CobiGenImpl.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/CobiGenImpl.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.BiConsumer; import javax.inject.Inject; @@ -70,6 +71,15 @@ public GenerationReportTo generate(Object input, List generableArtifacts, Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel) { + return generate(input, generableArtifacts, targetRootPath, forceOverride, logicClasses, null, + (String taskName, Integer progress) -> { + }); + } + + @Override + public GenerationReportTo generate(Object input, List generableArtifacts, + Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel, + BiConsumer progressCallback) { Objects.requireNonNull(input, "Input"); Objects.requireNonNull(generableArtifacts, "List of Artifacts to be generated"); if (generableArtifacts.contains(null)) { @@ -80,7 +90,7 @@ public GenerationReportTo generate(Object input, List { + }); } @Override diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/GenerationProcessorImpl.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/GenerationProcessorImpl.java index 6306e2852a..d65a801e03 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/GenerationProcessorImpl.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/GenerationProcessorImpl.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeSet; +import java.util.function.BiConsumer; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -23,6 +24,7 @@ import org.slf4j.LoggerFactory; import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.api.exception.CobiGenCancellationException; import com.devonfw.cobigen.api.exception.CobiGenRuntimeException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.exception.MergeException; @@ -105,10 +107,11 @@ public GenerationProcessorImpl(ConfigurationHolder configurationHolder, InputRes * @param logicClasses * logic classes to instantiate. */ - private void loadLogicClasses(List> logicClasses) { + private void loadLogicClasses(BiConsumer progressCallback, List> logicClasses) { logicClassesModel = Maps.newHashMap(); for (Class logicClass : logicClasses) { try { + progressCallback.accept(logicClass.getCanonicalName(), 100 / logicClasses.size()); if (logicClass.isEnum()) { logicClassesModel.put(logicClass.getSimpleName(), logicClass.getEnumConstants()); } else { @@ -124,15 +127,18 @@ private void loadLogicClasses(List> logicClasses) { @Override public GenerationReportTo generate(Object input, List generableArtifacts, - Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel) { + Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel, + BiConsumer progressCallback) { InputValidator.validateInputsUnequalNull(input, generableArtifacts); // initialize this.forceOverride = forceOverride; this.input = input; if (logicClasses != null) { - loadLogicClasses(logicClasses); + loadLogicClasses(progressCallback, logicClasses); } + + progressCallback.accept("createTempDirectory", 50); this.rawModel = rawModel; try { tmpTargetRootPath = Files.createTempDirectory("cobigen-"); @@ -143,29 +149,42 @@ public GenerationReportTo generate(Object input, List templatesToBeGenerated = flatten(generableArtifacts); // generate Map tmpToOrigFileTrace = Maps.newHashMap(); - for (TemplateTo template : templatesToBeGenerated) { - try { - Trigger trigger = configurationHolder.readContextConfiguration().getTrigger(template.getTriggerId()); - TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType()); - InputValidator.validateTriggerInterpreter(triggerInterpreter, trigger); - tmpToOrigFileTrace.putAll(generate(template, triggerInterpreter)); - } catch (CobiGenRuntimeException e) { - generationReport.setTemporaryWorkingDirectory(tmpTargetRootPath); - generationReport.addError(e); - LOG.error("An internal error occurred during generation.", e); - } catch (Throwable e) { - generationReport.setTemporaryWorkingDirectory(tmpTargetRootPath); - generationReport.addError(new CobiGenRuntimeException( - "Something unexpected happened" + ((e.getMessage() != null) ? ": " + e.getMessage() : "!"), e)); - LOG.error("An unknown exception occurred during generation.", e); + try { + for (TemplateTo template : templatesToBeGenerated) { + try { + Trigger trigger = + configurationHolder.readContextConfiguration().getTrigger(template.getTriggerId()); + TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType()); + InputValidator.validateTriggerInterpreter(triggerInterpreter, trigger); + tmpToOrigFileTrace.putAll(generate(template, triggerInterpreter)); + progressCallback.accept("generates... ", + Math.round(1 / (float) templatesToBeGenerated.size() * 800)); + } catch (CobiGenCancellationException e) { + throw (e); + } catch (CobiGenRuntimeException e) { + generationReport.setTemporaryWorkingDirectory(tmpTargetRootPath); + generationReport.addError(e); + LOG.error("An internal error occurred during generation.", e); + } catch (Throwable e) { + generationReport.setTemporaryWorkingDirectory(tmpTargetRootPath); + generationReport.addError(new CobiGenRuntimeException( + "Something unexpected happened" + ((e.getMessage() != null) ? ": " + e.getMessage() : "!"), e)); + LOG.error("An unknown exception occurred during generation.", e); + } } + } catch (CobiGenCancellationException e) { + LOG.error("the Generation has been Canceled.", e); + generationReport.setCancelled(true); } - - if (generationReport.isSuccessful()) { + if (generationReport.isCancelled()) { + generationReport.setTemporaryWorkingDirectory(tmpTargetRootPath); + // do nothing if cancelled + } else if (generationReport.isSuccessful()) { try { for (Entry tmpToOrigFile : tmpToOrigFileTrace.entrySet()) { Files.createDirectories(tmpToOrigFile.getValue().toPath().getParent()); diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/api/GenerationProcessor.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/api/GenerationProcessor.java index 3fb2d61d2d..f3821d4343 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/api/GenerationProcessor.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/generator/api/GenerationProcessor.java @@ -3,6 +3,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; import com.devonfw.cobigen.api.to.GenerableArtifact; import com.devonfw.cobigen.api.to.GenerationReportTo; @@ -32,5 +33,6 @@ public interface GenerationProcessor { * @return {@link GenerationReportTo the GenerationReport} */ public GenerationReportTo generate(Object input, List generableArtifacts, - Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel); + Path targetRootPath, boolean forceOverride, List> logicClasses, Map rawModel, + BiConsumer progressCallback); } From 0e00a245bb7d7613812d607a0233c0f45a092afa Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 14 Apr 2020 07:34:16 +0200 Subject: [PATCH 3/9] #1083 enable jaxb jdk8 + jdk > 8 support simultaneously --- .../reader/ContextConfigurationReader.java | 9 +++- .../cobigen/impl/config/reader/JvmUtil.java | 49 +++++++++++++++++++ .../reader/TemplatesConfigurationReader.java | 4 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JvmUtil.java diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/ContextConfigurationReader.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/ContextConfigurationReader.java index 7e71361365..27d5adf9c0 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/ContextConfigurationReader.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/ContextConfigurationReader.java @@ -19,6 +19,8 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -40,6 +42,9 @@ /** The {@link ContextConfigurationReader} reads the context xml */ public class ContextConfigurationReader { + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(ContextConfigurationReader.class); + /** XML Node 'context' of the context.xml */ private ContextConfiguration contextNode; @@ -84,7 +89,9 @@ private void readConfiguration() { // workaround to make JAXB work in OSGi context by // https://github.com/ControlSystemStudio/cs-studio/issues/2530#issuecomment-450991188 final ClassLoader orig = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + if (JvmUtil.isRunningJava9OrLater()) { + Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + } try { Unmarshaller unmarschaller = JAXBContext.newInstance(ContextConfiguration.class).createUnmarshaller(); diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JvmUtil.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JvmUtil.java new file mode 100644 index 0000000000..591fa66261 --- /dev/null +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JvmUtil.java @@ -0,0 +1,49 @@ +package com.devonfw.cobigen.impl.config.reader; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Util to determine JVM version + */ +public class JvmUtil { + + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(JvmUtil.class); + + /** Holds the information whether the currently executed JVM is running java 9 or later */ + private static boolean runningJava9OrLater = determineRunningJava9OrLater(); + + /** + * @return true if the currently executed JVM is running java 9 or later, false + * otherwise + */ + public static boolean isRunningJava9OrLater() { + return runningJava9OrLater; + } + + /** + * @return whether the currently running JVM is of version 9 or later + */ + private static boolean determineRunningJava9OrLater() { + Runtime runtime = Runtime.getRuntime(); + try { + Method getVersion = Runtime.class.getMethod("version"); + Object version = getVersion.invoke(runtime); + Method getMajorVersion = version.getClass().getMethod("major"); + int majorVersion = (int) getMajorVersion.invoke(version); + runningJava9OrLater = majorVersion >= 9; + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e1) { + LOG.info("Detected a JVM < 9"); + LOG.debug( + "Interpreted the running JVM as a version less than 9 as we could not find/execute Runtime.version() method.", + e1); + runningJava9OrLater = false; + } + return runningJava9OrLater; + } +} diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplatesConfigurationReader.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplatesConfigurationReader.java index c7e552c6be..40b61cb106 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplatesConfigurationReader.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplatesConfigurationReader.java @@ -160,7 +160,9 @@ private void readConfiguration() { // workaround to make JAXB work in OSGi context by // https://github.com/ControlSystemStudio/cs-studio/issues/2530#issuecomment-450991188 final ClassLoader orig = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + if (JvmUtil.isRunningJava9OrLater()) { + Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + } try { Unmarshaller unmarschaller = JAXBContext.newInstance(TemplatesConfiguration.class).createUnmarshaller(); From 37a3d16e45d0834e81b1b52108b695532029ab8a Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 14 Apr 2020 08:12:44 +0200 Subject: [PATCH 4/9] #1083 enable jaxb jdk8 + jdk > 8 support simultaneously --- .../impl/config/upgrade/AbstractConfigurationUpgrader.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/upgrade/AbstractConfigurationUpgrader.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/upgrade/AbstractConfigurationUpgrader.java index bef2668865..f3b17fa405 100644 --- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/upgrade/AbstractConfigurationUpgrader.java +++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/upgrade/AbstractConfigurationUpgrader.java @@ -31,6 +31,7 @@ import com.devonfw.cobigen.api.exception.CobiGenRuntimeException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.exception.NotYetSupportedException; +import com.devonfw.cobigen.impl.config.reader.JvmUtil; import com.devonfw.cobigen.impl.exceptions.BackupFailedException; import com.devonfw.cobigen.impl.util.ExceptionUtil; @@ -342,7 +343,9 @@ private Object unmarshallConfiguration(Path configurationFile, VERSIONS_TYPE lv, // workaround to make JAXB work in OSGi context by // https://github.com/ControlSystemStudio/cs-studio/issues/2530#issuecomment-450991188 final ClassLoader orig = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + if (JvmUtil.isRunningJava9OrLater()) { + Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader()); + } try { Unmarshaller unmarschaller = JAXBContext.newInstance(jaxbConfigurationClass).createUnmarshaller(); From 94cab2004188b06eb6b18d07c958f72014127d3d Mon Sep 17 00:00:00 2001 From: lilliCao Date: Wed, 22 Apr 2020 19:18:26 +0200 Subject: [PATCH 5/9] Abort generation if external trigger does not match (#1143) * check if external trigger matched * test exception when external trigger is not matched --- .../cobigen/systemtest/GenerationTest.java | 27 +++++++++++++++++++ .../context.xml | 11 ++++++++ .../external_incrementRef/templates.xml | 10 +++++++ .../valid_increment_composition/templates.xml | 14 ++++++++++ .../templates/templateDec1.ftl | 0 .../ConfigurationInterpreterImpl.java | 19 ++++++++++--- 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/context.xml create mode 100644 cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/external_incrementRef/templates.xml create mode 100644 cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/valid_increment_composition/templates.xml create mode 100644 cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/valid_increment_composition/templates/templateDec1.ftl diff --git a/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java index 12cf9e56ec..ab906959b6 100644 --- a/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java +++ b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java @@ -2,6 +2,7 @@ import static com.devonfw.cobigen.test.assertj.CobiGenAsserts.assertThat; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.sameInstance; import static org.mockito.Matchers.any; @@ -12,6 +13,7 @@ import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -23,6 +25,7 @@ import org.junit.Test; import com.devonfw.cobigen.api.CobiGen; +import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.extension.InputReader; import com.devonfw.cobigen.api.extension.MatcherInterpreter; import com.devonfw.cobigen.api.extension.TriggerInterpreter; @@ -107,6 +110,30 @@ public void testGenerationWithExternalIncrements() throws Exception { assertThat(triggersIds.size()).isEqualTo(2); } + /** + * Tests generation of external increments where its trigger does not match + * @throws IOException + * test fails + */ + public void testGenerationWithExternalIncrementsFailsWhenExternalTriggerNotMatch() throws IOException { + // given + Object input = PluginMockFactory.createSimpleJavaConfigurationMock(); + + File folder = tmpFolder.newFolder("GenerationTest"); + File target = new File(folder, "generated.txt"); + FileUtils.write(target, "base"); + + // when + CobiGen cobigen = + CobiGenFactory.create(new File(testFileRootPath + "externalIncrementsGenerationException").toURI()); + + // exception is thrown while getting all increments + assertThatThrownBy(() -> { + cobigen.getMatchingIncrements(input); + }).isInstanceOf(InvalidConfigurationException.class).hasMessageContaining( + "An external incrementRef to valid_increment_composition::0 is referenced from external_incrementref but its trigger does not match"); + } + /** * Tests whether context properties as well as cobigen properties are correctly resolved to be served in * the template in the {@link ModelBuilderImpl#NS_VARIABLES} namespace. diff --git a/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/context.xml b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/context.xml new file mode 100644 index 0000000000..b83fddfd4b --- /dev/null +++ b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/context.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/external_incrementRef/templates.xml b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/external_incrementRef/templates.xml new file mode 100644 index 0000000000..69d5691095 --- /dev/null +++ b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/external_incrementRef/templates.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/valid_increment_composition/templates.xml b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/valid_increment_composition/templates.xml new file mode 100644 index 0000000000..efa777d9f7 --- /dev/null +++ b/cobigen/cobigen-core-parent/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/externalIncrementGenerationException/valid_increment_composition/templates.xml @@ -0,0 +1,14 @@ + + + + +