@Override public void update() { if (isUpdating) { return; } // logger.info("********** Updating templates for directory "+_directory.getAbsolutePath()); try { Set<String> previousKnownTemplates = new HashSet<String>(templates.keySet()); CGTemplate[] newTemplates = findAllTemplates(); if (newTemplates != null) { for (CGTemplate template : newTemplates) { String relativePath = template.getRelativePathWithoutSetPrefix(); if (templates.get(relativePath) == null) { // logger.info(">>>> Adding file "+file.getAbsolutePath()+" relative path = // "+relativePath); templates.put(relativePath, template); registerTemplate(template); } if (previousKnownTemplates.contains(relativePath)) { previousKnownTemplates.remove(relativePath); } } } for (String templateRelativePath : previousKnownTemplates) { CGTemplate template = templates.get(templateRelativePath); if (template == null) { continue; // GPO: see bug 1007011 (this should not happen because I prevented recursion // from happening with flag // isUpdating, but I leave this just to be really sure that no NPE } // will occur) if (!template.isDeleted()) { template.delete(); } if (logger.isLoggable(Level.INFO)) { logger.info("Removing " + templateRelativePath); } templates.remove(templateRelativePath); unregisterTemplate(template); } for (CGTemplate template : templates.values()) { if (template.getIsVersionOnDiskSeemsNewer()) { logger.fine("Updating file: " + template.getRelativePath()); template.update(true); } } } finally { isUpdating = false; } }
protected void unregisterTemplate(CGTemplate template) { CGTemplateFolder folder = retrieveFolder(template.getFolderPath()); folder.templates.remove(template); }