Support several templates
This commit is contained in:
parent
127e4013e0
commit
e4e6b6fc25
1 changed files with 21 additions and 9 deletions
|
@ -61,18 +61,30 @@ public class TargetGenerator {
|
||||||
cfg.setWrapUncheckedExceptions(true);
|
cfg.setWrapUncheckedExceptions(true);
|
||||||
cfg.setFallbackOnNullLoopVariable(false);
|
cfg.setFallbackOnNullLoopVariable(false);
|
||||||
Template temp = cfg.getTemplate(ENDPOINTS_TEMPLATE_NAME);
|
Template temp = cfg.getTemplate(ENDPOINTS_TEMPLATE_NAME);
|
||||||
try (var outputFile = Files.newBufferedWriter(
|
List<Path> templates = Files
|
||||||
outputPath.resolve("endpoints.scala"),
|
.list(this.templatePath)
|
||||||
StandardOpenOption.CREATE,
|
.filter(Files::isRegularFile)
|
||||||
StandardOpenOption.TRUNCATE_EXISTING
|
.filter(f -> f.getFileName().toString().endsWith(".ftl"))
|
||||||
)) {
|
.toList() ;
|
||||||
HashMap<String, Object> templateData = new HashMap<>();
|
for (Path template : templates) {
|
||||||
templateData.put("endpoints", endpoints);
|
try (var outputFile = Files.newBufferedWriter(
|
||||||
templateData.put("datatypes", dataTypes);
|
outputName(template),
|
||||||
temp.process(templateData, outputFile);
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.TRUNCATE_EXISTING
|
||||||
|
)) {
|
||||||
|
HashMap<String, Object> templateData = new HashMap<>();
|
||||||
|
templateData.put("endpoints", endpoints);
|
||||||
|
templateData.put("datatypes", dataTypes);
|
||||||
|
temp.process(templateData, outputFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (TemplateException | IOException ex) {
|
} catch (TemplateException | IOException ex) {
|
||||||
throw new TargetGeneratorException(ex);
|
throw new TargetGeneratorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path outputName(Path templatePath) {
|
||||||
|
String name = templatePath.getFileName().toString().replace(".ftl", ".scala") ;
|
||||||
|
return this.outputPath.resolve(name) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue