use of com.devonfw.cobigen.impl.config.entity.io.IncrementRef in project cobigen by devonfw.
the class TemplatesConfigurationReader method addAllTemplatesRecursively.
/**
* Adds all templates defined within the increment and sub increments recursively.
*
* @param rootIncrement the {@link Increment} on which the templates should be added
* @param current the source {@link com.devonfw.cobigen.impl.config.entity.io.Increment} from which to retrieve the
* data
* @param templates {@link Map} of all templates (see {@link TemplatesConfigurationReader#loadTemplates(Trigger)}
* @param increments {@link Map} of all retrieved increments
* @throws InvalidConfigurationException if there is an invalid ref attribute
*/
private void addAllTemplatesRecursively(Increment rootIncrement, com.devonfw.cobigen.impl.config.entity.io.Increment current, Map<String, Template> templates, Map<String, Increment> increments) throws InvalidConfigurationException {
for (TemplateRef ref : current.getTemplateRefOrIncrementRefOrTemplateScanRef().stream().filter(e -> e instanceof TemplateRef).map(e -> (TemplateRef) e).collect(Collectors.toList())) {
Template temp = templates.get(ref.getRef());
if (temp == null) {
if (isExternalRef(ref.getRef())) {
rootIncrement.addTemplate(loadExternalTemplate(ref));
} else {
throw new InvalidConfigurationException(this.configFilePath.toUri().toString(), "No template found for ref='" + ref.getRef() + "'!");
}
} else {
rootIncrement.addTemplate(temp);
}
}
for (IncrementRef ref : current.getTemplateRefOrIncrementRefOrTemplateScanRef().stream().filter(e -> e instanceof IncrementRef).map(e -> (IncrementRef) e).collect(Collectors.toList())) {
Increment parentPkg = increments.get(current.getName());
Increment childPkg = increments.get(ref.getRef());
if (childPkg == null) {
// We try to find the increment inside our templates.xml file
Increments incrementsNode = this.configNode.getIncrements();
com.devonfw.cobigen.impl.config.entity.io.Increment source = null;
if (incrementsNode != null) {
// We only add the specific increment we want
source = getSpecificIncrement(incrementsNode.getIncrement(), ref.getRef());
if (source != null) {
addAllTemplatesRecursively(rootIncrement, source, templates, increments);
} else // incrementRef contains "::". That would mean we have to search on another folder.
if (isExternalRef(ref.getRef())) {
parentPkg.addIncrementDependency(loadExternalIncrement(ref));
} else {
throw new InvalidConfigurationException(this.configFilePath.toUri().toString(), "No increment found for ref='" + ref.getRef() + "'!");
}
}
} else {
parentPkg.addIncrementDependency(childPkg);
com.devonfw.cobigen.impl.config.entity.io.Increment pkg = getIncrementDeclaration(ref);
addAllTemplatesRecursively(rootIncrement, pkg, templates, increments);
}
}
for (TemplateScanRef ref : current.getTemplateRefOrIncrementRefOrTemplateScanRef().stream().filter(e -> e instanceof TemplateScanRef).map(e -> (TemplateScanRef) e).collect(Collectors.toList())) {
List<String> scannedTemplateNames = this.templateScanTemplates.get(ref.getRef());
if (scannedTemplateNames == null) {
throw new InvalidConfigurationException(this.configFilePath.toUri().toString(), "No templateScan found for ref='" + ref.getRef() + "'!");
} else {
for (String scannedTemplateName : scannedTemplateNames) {
rootIncrement.addTemplate(templates.get(scannedTemplateName));
}
}
}
}
Aggregations