Search in sources :

Example 21 with InvalidConfigurationException

use of com.devonfw.cobigen.api.exception.InvalidConfigurationException 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 22 with InvalidConfigurationException

use of com.devonfw.cobigen.api.exception.InvalidConfigurationException in project cobigen by devonfw.

the class ContextVariableResolver method resolveVariables.

/**
 * Resolves all {@link VariableAssignment}s by using the given {@link TriggerInterpreter}
 *
 * @param triggerInterpreter to be used
 * @param report is getting filled as side-effect
 * @param parent the parent {@link Variables} to inherit.
 * @return the mapping of variable to value
 * @throws InvalidConfigurationException if there are {@link VariableAssignment}s, which could not be resolved
 */
public Variables resolveVariables(TriggerInterpreter triggerInterpreter, Variables parent, GenerationReportTo report) throws InvalidConfigurationException {
    Variables variables = new Variables(parent);
    for (Matcher m : this.trigger.getMatcher()) {
        MatcherTo matcherTo = new MatcherTo(m.getType(), m.getValue(), this.input);
        if (triggerInterpreter.getMatcher().matches(matcherTo)) {
            Map<String, String> resolvedVariables;
            try {
                resolvedVariables = triggerInterpreter.getMatcher().resolveVariables(matcherTo, getVariableAssignments(m), report);
            } catch (InvalidConfigurationException e) {
                throw e;
            } catch (Throwable e) {
                throw new PluginProcessingException(e);
            }
            InputValidator.validateResolvedVariables(resolvedVariables);
            variables.putAll(resolvedVariables);
        }
    }
    return variables;
}
Also used : Variables(com.devonfw.cobigen.impl.config.entity.Variables) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) PluginProcessingException(com.devonfw.cobigen.impl.exceptions.PluginProcessingException) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException)

Example 23 with InvalidConfigurationException

use of com.devonfw.cobigen.api.exception.InvalidConfigurationException in project cobigen by devonfw.

the class ConfigurationClassLoaderUtil method getContextConfiguration.

/**
 * Checks the ClassLoader for any context.xml provided either in configurationFolder or in templates-plugin and
 * returns its URL
 *
 * @param classLoader ClassLoader to check resources from
 * @return URL of the context configuration file path
 * @throws InvalidConfigurationException if no configuration file was found
 */
public static URL getContextConfiguration(ClassLoader classLoader) throws InvalidConfigurationException {
    URL contextConfigurationLocation = null;
    for (String possibleLocation : configFileLocations) {
        URL configLocation = classLoader.getResource(possibleLocation);
        if (configLocation != null) {
            contextConfigurationLocation = configLocation;
            LOG.debug("Found context.xml URL @ {}", contextConfigurationLocation);
            break;
        }
    }
    if (contextConfigurationLocation == null) {
        throw new InvalidConfigurationException("No context.xml could be found in the classpath!");
    }
    return contextConfigurationLocation;
}
Also used : URL(java.net.URL) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException)

Example 24 with InvalidConfigurationException

use of com.devonfw.cobigen.api.exception.InvalidConfigurationException in project cobigen by devonfw.

the class VersionValidatorTest method testInvalidCobiGenVersion_tooOld_contextConfiguration.

/**
 * Testing the CobiGen version to be too old for the provided configuration version, which indicates to make an update
 * of CobiGen to read the configuration properly.
 *
 * @author mbrunnli (May 17, 2016)
 */
@Test(expected = InvalidConfigurationException.class)
public void testInvalidCobiGenVersion_tooOld_contextConfiguration() {
    try {
        VersionValidator validator = new VersionValidator(Type.CONTEXT_CONFIGURATION, "2.0.2");
        validator.validate(2.1f);
    } catch (InvalidConfigurationException e) {
        assertThat(e.getMessage()).matches(".* version '2.1' .* context configuration is unknown .* CobiGen '2.0'.*");
        throw e;
    }
}
Also used : VersionValidator(com.devonfw.cobigen.impl.config.versioning.VersionValidator) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException) Test(org.junit.Test)

Example 25 with InvalidConfigurationException

use of com.devonfw.cobigen.api.exception.InvalidConfigurationException in project cobigen by devonfw.

the class VersionValidatorTest method testInvalidCobiGenVersion_tooNew_contextConfiguration.

/**
 * Testing the CobiGen version to be too new for the provided configuration version, which indicates to make an update
 * of the configuration to read it properly.
 *
 * @author mbrunnli (May 17, 2016)
 */
@Test(expected = InvalidConfigurationException.class)
public void testInvalidCobiGenVersion_tooNew_contextConfiguration() {
    try {
        VersionValidator validator = new VersionValidator(Type.CONTEXT_CONFIGURATION, "2.1.0");
        validator.validate(1.2f);
    } catch (InvalidConfigurationException e) {
        assertThat(e.getMessage()).matches(".* version '1.2' has to be upgraded .*");
        throw e;
    }
}
Also used : VersionValidator(com.devonfw.cobigen.impl.config.versioning.VersionValidator) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException) Test(org.junit.Test)

Aggregations

InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)25 Increment (com.devonfw.cobigen.impl.config.entity.Increment)5 Template (com.devonfw.cobigen.impl.config.entity.Template)5 VersionValidator (com.devonfw.cobigen.impl.config.versioning.VersionValidator)5 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 TemplatePath (com.devonfw.cobigen.impl.config.entity.TemplatePath)4 IOException (java.io.IOException)4 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)3 Increments (com.devonfw.cobigen.impl.config.entity.io.Increments)3 JAXBContext (jakarta.xml.bind.JAXBContext)3 JAXBException (jakarta.xml.bind.JAXBException)3 UnmarshalException (jakarta.xml.bind.UnmarshalException)3 Unmarshaller (jakarta.xml.bind.Unmarshaller)3 InputStream (java.io.InputStream)3 BigDecimal (java.math.BigDecimal)3 StreamSource (javax.xml.transform.stream.StreamSource)3 Schema (javax.xml.validation.Schema)3 SchemaFactory (javax.xml.validation.SchemaFactory)3 SAXException (org.xml.sax.SAXException)3