Support several templates

This commit is contained in:
Johan Maasing 2025-03-19 21:31:32 +01:00
parent 127e4013e0
commit e4e6b6fc25
Signed by: johan
GPG key ID: FFD31BABEE2DEED2

View file

@ -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) ;
}
} }