allNames.removeAll(keySet); // got new templates
removeRemoved(currentClassesOnDir, keySet);
for (String c : allNames) {
RendererClass rc = newRendererClass(c);
japidClasses.put(c, rc);
}
// now all the class set size is up to date
// now update any Java source code
List<File> gen = gen(defaultTemplateRoot);
// this would include both new and updated java
Set<String> updatedClasses = new HashSet<String>();
if (gen.size() > 0) {
for (File f : gen) {
String className = getClassName(f);
updatedClasses.add(className);
RendererClass rendererClass = japidClasses.get(className);
if (rendererClass == null) {
// this should not happen, since
throw new RuntimeException("any new class names should have been in the classes container: "
+ className);
// rendererClass = newRendererClass(className);
// classes.put(className, rendererClass);
}
JapidRenderer.setSources(rendererClass, f);
removeInnerClasses(className);
cleanClassHolder(rendererClass);
}
}
// find all render class without bytecode
for (Iterator<String> i = japidClasses.keySet().iterator(); i.hasNext();) {
String k = i.next();
RendererClass rc = japidClasses.get(k);
if (rc.getSourceCode() == null) {
if (!rc.getClassName().contains("$")) {
String pathname = defaultTemplateRoot + sep + k.replace(".", sep);
File f = new File(pathname + ".java");
JapidRenderer.setSources(rc, f);
cleanClassHolder(rc);
updatedClasses.add(k);
} else {
rc.setLastUpdated(0);
}
} else {
if (rc.getBytecode() == null) {
cleanClassHolder(rc);
updatedClasses.add(k);
}
}
}
// compile all
if (updatedClasses.size() > 0) {
String[] names = new String[updatedClasses.size()];
int i = 0;
for (String s : updatedClasses) {
names[i++] = s;
}
long t = System.currentTimeMillis();
// newly compiled class bytecode bodies are set in the global
// classes set ready for defining
compiler.compile(names);
initJapidClassLoader();
for (RendererClass rc : japidClasses.values()) {
try {
if (isDevMode())
rc.setClz(null); // to enable JIT loading in DEV mode
else
rc.setClz((Class<JapidTemplateBaseWithoutPlay>) japidClassLoader.loadClass(rc.getClassName()));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}