in freemarker-generator-maven-plugin/src/main/java/org/apache/freemarker/generator/maven/OutputGenerator.java [142:176]
public void generate(Configuration config) {
final File outputFile = new File(outputLocation.toFile().getAbsolutePath());
final File templateFile = templateLocation.toFile();
final File generatorFile = generatorLocation.toFile();
if (outputFile.exists()) {
//early exit only if the output file is newer than all files that contribute to its generation
if (outputFile.lastModified() > generatorFile.lastModified()
&& outputFile.lastModified() > templateFile.lastModified()
&& outputFile.lastModified() > pomModifiedTimestamp) {
return;
}
} else {
final File parentDir = outputFile.getParentFile();
if (parentDir.isFile()) {
throw new RuntimeException("Parent directory of output file is a file: " + parentDir.getAbsoluteFile());
}
parentDir.mkdirs();
if (!parentDir.isDirectory()) {
throw new RuntimeException("Could not create directory: " + parentDir.getAbsoluteFile());
}
}
final Template template;
try {
template = config.getTemplate(templateFile.getName());
} catch (Throwable t) {
throw new RuntimeException("Could not read template: " + templateFile.getName(), t);
}
try (FileWriter writer = new FileWriter(outputFile)) {
template.process(dataModel, writer);
} catch (Throwable t) {
throw new RuntimeException("Could not process template associated with data file: " + generatorLocation, t);
}
}