for (UISchema screen : schema.getChildren())
{
if (screen.getClass() == Plugin.class)
{
Plugin plugin = (Plugin) screen;
String fullKlazzName = plugin.getPluginType();
String packageName = fullKlazzName;
if (fullKlazzName.contains(".")) packageName = fullKlazzName.substring(0,
fullKlazzName.lastIndexOf("."));
String shortKlazzName = fullKlazzName;
if (fullKlazzName.contains(".")) shortKlazzName = fullKlazzName.substring(fullKlazzName
.lastIndexOf(".") + 1);
File targetFile = new File(this.getHandWrittenPath(options) + "/" + fullKlazzName.replace(".", "/")
+ ".java");
File targetFtl = new File(fullKlazzName.replace(".", "/") + ".ftl");
// only generate if the file doesn't exist AND is not on
// classpath
Class<?> c = null;
try
{
c = Class.forName(fullKlazzName);
// return;
}
catch (ClassNotFoundException e)
{
logger.debug("skipped plugin " + plugin.getName() + " as it is on the classpath");
}
logger.debug("tested classforname on " + fullKlazzName + ": " + c);
if (!targetFile.exists() && c == null)
{
File targetDir = new File(this.getHandWrittenPath(options) + "/" + packageName.replace(".", "/"));
boolean created = targetDir.mkdirs();
if (!created && !targetDir.exists())
{
throw new IOException("could not create " + targetDir);
}
templateArgs.put("screen", plugin);
templateArgs.put("template", template.getName());
templateArgs.put("clazzName", shortKlazzName);
templateArgs.put("macroName", fullKlazzName.replace(".", "_"));
templateArgs.put("templatePath", targetFtl.toString().replace("\\", "/"));
templateArgs.put("package", packageName);
templateArgs.put("flavor", plugin.getFlavor().toString().toLowerCase());
OutputStream targetOut = new FileOutputStream(targetFile);
template.process(templateArgs, new OutputStreamWriter(targetOut, Charset.forName("UTF-8")));
targetOut.close();