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,8 +61,14 @@ 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);
List<Path> templates = Files
.list(this.templatePath)
.filter(Files::isRegularFile)
.filter(f -> f.getFileName().toString().endsWith(".ftl"))
.toList() ;
for (Path template : templates) {
try (var outputFile = Files.newBufferedWriter( try (var outputFile = Files.newBufferedWriter(
outputPath.resolve("endpoints.scala"), outputName(template),
StandardOpenOption.CREATE, StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING StandardOpenOption.TRUNCATE_EXISTING
)) { )) {
@ -71,8 +77,14 @@ public class TargetGenerator {
templateData.put("datatypes", dataTypes); templateData.put("datatypes", dataTypes);
temp.process(templateData, outputFile); 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) ;
}
} }