in buildSrc/src/main/java/org/grails/forge/rocker/plugin/RockerTask.java [98:175]
private static void runJavaGeneratorMain(RockerConfiguration ext,
Logger logger,
File templateDir, File outputDir, File classDir) {
if (ext.getSkip().get()) {
logger.info("Skip flag is on, will skip goal.");
return;
}
logger.info("Targeting java version " + ext.getJavaVersion().get());
try {
JavaGeneratorRunnable jgm = new JavaGeneratorRunnable();
jgm.getParser().getConfiguration().setTemplateDirectory(templateDir);
jgm.getGenerator().getConfiguration().setOutputDirectory(outputDir);
jgm.getGenerator().getConfiguration().setClassDirectory(classDir);
jgm.setFailOnError(ext.getFailOnError().get());
// passthru other config
if (ext.getSuffixRegex().isPresent()) {
jgm.setSuffixRegex(ext.getSuffixRegex().get());
}
RockerOptions rockerOptions = jgm.getParser().getConfiguration().getOptions();
rockerOptions.setJavaVersion(ext.getJavaVersion().get());
if (ext.getExtendsClass().isPresent()) {
rockerOptions.setExtendsClass(ext.getExtendsClass().get());
}
if (ext.getExtendsModelClass().isPresent()) {
rockerOptions.setExtendsModelClass(ext.getExtendsModelClass().get());
}
if (ext.getDiscardLogicWhitespace().isPresent()) {
rockerOptions.setDiscardLogicWhitespace(ext.getDiscardLogicWhitespace().get());
}
if (ext.getTargetCharset().isPresent()) {
rockerOptions.setTargetCharset(ext.getTargetCharset().get());
}
if (ext.getOptimize().isPresent()) {
rockerOptions.setOptimize(ext.getOptimize().get());
}
if (ext.getPostProcessing().isPresent()) {
List<String> postProcessing = ext.getPostProcessing().get();
if (!postProcessing.isEmpty()) {
rockerOptions.setPostProcessing(postProcessing.toArray(new String[0]));
}
}
if (ext.getMarkAsGenerated().isPresent()) {
rockerOptions.setMarkAsGenerated(ext.getMarkAsGenerated().get());
}
jgm.run();
} catch (Exception e) {
throw new RockerGradleException(e.getMessage(), e);
}
if (!ext.getSkipTouch().get()) {
String touchFile = ext.getTouchFile().orElse("").get();
if (touchFile.length() == 0) {
throw new RockerGradleException(
"If skipTouch is equal to false, then "
+ "touchFile must not be empty");
}
if (ext.getTouchFile().isPresent()) {
File f = new File(touchFile);
logger.info("Touching file " + f);
try {
if (!f.exists()) {
new FileOutputStream(f).close();
}
if (!f.setLastModified(System.currentTimeMillis())) {
throw new IOException("Could not set Last Modified");
}
} catch (IOException e) {
logger.debug("Unable to touch file: " + f.getAbsolutePath(), e);
}
}
}
}