Set<File> toBeUpdated = new HashSet<File>();
// find out all the classes that need to be updated
for (File tf : allTemplates) {
String cname = getClassName(tf);
RendererClass rc = japidClasses.get(cname);
if (rc == null) {
toBeUpdated.add(tf);
} else if (rc.getScriptTimestamp() < tf.lastModified()) {
toBeUpdated.add(tf);
} else if (rc.getJavaSourceCode() == null || rc.getJavaSourceCode().length() == 0) {
toBeUpdated.add(tf);
} else if (rc.getBytecode() == null || rc.getBytecode().length == 0) {
toBeUpdated.add(tf);
}
}
Set<String> currentClassesOnDir = createClassNameSet(allTemplates);
Set<String> currentClassNames = japidClasses.keySet();
if (!currentClassNames.equals(currentClassesOnDir)) {
Set<String> classNamesRegistered = new HashSet<String>(currentClassNames);
Set<String> classNamesDir = new HashSet<String>(currentClassesOnDir);
if (classNamesRegistered.containsAll(classNamesDir)) {
classNamesRegistered.removeAll(classNamesDir);
if (!classNamesRegistered.isEmpty()) {
for (String n : classNamesRegistered) {
if (!n.contains("$")) {
if (!specialClasses.contains(n)) {
touch();
break;
}
}
}
}
} else {
touch();
}
} else {
// no name changes
}
// allClassNamesOnDir.removeAll(currentClassNames); // got new
// templates
removeRemoved(currentClassesOnDir, currentClassNames);
for (File tb : toBeUpdated) {
String scriptSrc = DirUtil.readFileAsString(tb);
String javaCode = JapidTemplateTransformer.generateInMemory(scriptSrc, cleanPath(tb), usePlay);
JapidFlags.log("converted: " + tb.getPath());
String className = getClassName(tb);
RendererClass rc = newRendererClass(className);
rc.setScriptFile(tb);
rc.setJapidSourceCode(scriptSrc);
rc.setJavaSourceCode(javaCode);
removeInnerClasses(className);
cleanByteCode(rc);
japidClasses.put(className, rc);
}