use of org.apache.maven.plugins.annotations.Parameter in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method overrideTemplateParameters.
/**
* Before applying the given template lets allow template parameters to be overridden via the maven
* properties - or optionally - via the command line if in interactive mode.
*/
protected static void overrideTemplateParameters(Template template, MavenProject project, Logger log) {
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
if (parameters != null && project != null) {
Properties properties = getProjectAndFabric8Properties(project);
boolean missingProperty = false;
for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
String parameterName = parameter.getName();
String name = "fabric8.apply." + parameterName;
String propertyValue = properties.getProperty(name);
if (propertyValue != null) {
log.info("Overriding template parameter " + name + " with value: " + propertyValue);
parameter.setValue(propertyValue);
} else {
missingProperty = true;
log.info("No property defined for template parameter: " + name);
}
}
if (missingProperty) {
log.debug("Current properties " + new TreeSet<>(properties.keySet()));
}
}
}
use of org.apache.maven.plugins.annotations.Parameter in project fabric8-maven-plugin by fabric8io.
the class HelmMojo method createTemplateParameters.
private void createTemplateParameters(File outputDir, Template template, File templatesDir) throws MojoExecutionException {
JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
ObjectNode values = nodeFactory.objectNode();
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
if (parameters == null || parameters.isEmpty()) {
return;
}
List<HelmParameter> helmParameters = new ArrayList<>();
for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
HelmParameter helmParameter = new HelmParameter(parameter);
helmParameter.addToValue(values);
helmParameters.add(helmParameter);
}
File outputChartFile = new File(outputDir, "values.yaml");
try {
saveYaml(values, outputChartFile);
} catch (IOException e) {
throw new MojoExecutionException("Failed to save chart values " + outputChartFile + ": " + e, e);
}
// now lets replace all the parameter expressions in each template
File[] files = templatesDir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
String extension = Files.getExtension(file.getName()).toLowerCase();
if (extension.equals("yaml") || extension.equals("yml")) {
convertTemplateParameterExpressionsWithHelmExpressions(file, helmParameters);
}
}
}
}
}
Aggregations