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;
}
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;
}
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;
}
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;
}
}
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;
}
}
Aggregations