|
8 | 8 | import java.util.UUID; |
9 | 9 | import java.util.stream.Collectors; |
10 | 10 |
|
11 | | -import org.apache.commons.lang.StringUtils; |
| 11 | +import org.apache.commons.lang3.StringUtils; |
12 | 12 | import org.apache.commons.text.StringSubstitutor; |
13 | 13 |
|
| 14 | +import io.marioslab.basis.template.Template; |
| 15 | +import io.marioslab.basis.template.TemplateContext; |
| 16 | +import io.marioslab.basis.template.TemplateLoader; |
14 | 17 | import io.oneko.automations.LifetimeBehaviour; |
15 | 18 | import io.oneko.deployable.DeploymentBehaviour; |
16 | 19 | import io.oneko.kubernetes.deployments.DesiredState; |
@@ -113,13 +116,22 @@ default String calculateConfiguration() { |
113 | 116 | * template or a modified version template and the effective template variables. |
114 | 117 | */ |
115 | 118 | default List<WritableConfigurationTemplate> getCalculatedConfigurationTemplates() { |
116 | | - StringSubstitutor sub = new StringSubstitutor(this.calculateEffectiveTemplateVariables()); |
117 | | - |
| 119 | + final Map<String, String> variables = this.calculateEffectiveTemplateVariables(); |
118 | 120 | //somehow java does not properly figure out the list type here |
119 | 121 | final List<ConfigurationTemplate> unifiedTemplates = ConfigurationTemplates.unifyTemplateSets(getProject().getDefaultConfigurationTemplates(), getConfigurationTemplates()); |
| 122 | + |
| 123 | + TemplateContext context = new TemplateContext(); |
| 124 | + variables.forEach(context::set); |
| 125 | + context.set("fn", TemplateFunctions.class); |
| 126 | + |
120 | 127 | return unifiedTemplates.stream() |
121 | 128 | .map(WritableConfigurationTemplate::clone) |
122 | | - .peek(template -> template.setContent(sub.replace(template.getContent()))) |
| 129 | + .peek(template -> { |
| 130 | + TemplateLoader.MapTemplateLoader loader = new TemplateLoader.MapTemplateLoader(); |
| 131 | + loader.set("tpl", template.getContent()); |
| 132 | + final Template tpl = loader.load("tpl"); |
| 133 | + template.setContent(tpl.render(context)); |
| 134 | + }) |
123 | 135 | .collect(Collectors.toList()); |
124 | 136 | } |
125 | 137 |
|
|
0 commit comments