in tooling/camel-spring-boot-config-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootConfigGeneratorMojo.java [72:114]
public void execute() throws MojoExecutionException {
try {
getLog().info("Loading config from " + sourceClassFile);
String classFile = Files.readString(Paths.get(sourceClassFile));
JavaClass<JavaClassSource> inputClass = (JavaClass) Roaster.parse(classFile);
List<Option> options = new ArrayList<>();
for (Method<JavaClassSource, ?> mth : inputClass.getMethods()) {
if (mth.getName().startsWith("set")) {
String name = mth.getName().substring(3);
String fieldName = name.substring(0, 1).toLowerCase(Locale.ROOT) + name.substring(1);
String propName = camelCaseToDash(name);
String javaType = mth.getParameters().get(0).getType().getQualifiedName();
String defaultValue = null;
Field<JavaClassSource> field = inputClass.getField(fieldName);
if (field != null && field.getLiteralInitializer() != null) {
defaultValue = field.getLiteralInitializer();
}
String description = "";
int idx = classFile.indexOf("public void " + mth.getName());
if (idx > 0) {
String str = classFile.substring(0, idx);
idx = str.lastIndexOf("/**");
if (idx > 0) {
str = str.substring(idx);
description = str.trim().replace("\n ", "\n ");
}
}
options.add(new Option(fieldName, propName, javaType, defaultValue, description));
}
}
Map<String, Object> context = new HashMap<>();
context.put("options", options);
String output = velocity(template, context);
Path path = Paths.get(outputFile);
Files.createDirectories(path.getParent());
try (Writer w = Files.newBufferedWriter(path)) {
w.write(output);
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to parse/generated config", e);
}
}