try {
final File targetPath = new File(basedir, "target");
mkdirs(targetPath);
final File cachePath = new File(targetPath, "lint.cache");
final Cache cache = readCache(cachePath, new Cache(this.options, this.globals));
if(!nullSafeEquals(options, cache.options)){
getLog().warn("Options changed ... clearing cache");
cache.previousResults.clear();
}
if(!nullSafeEquals(globals, cache.globals)){
getLog().warn("Globals changed ... clearing cache");
cache.previousResults.clear();
}
List<File> javascriptFiles = new ArrayList<File>();
for(String next: directories){
File path = new File(basedir, next);
if(!path.exists() && !path.isDirectory()){
getLog().warn("You told me to find tests in " + next + ", but there is nothing there (" + path.getAbsolutePath() + ")");
}else{
collect(path, javascriptFiles);
}
}
List<File> matches = FunctionalJava.filter(javascriptFiles, new Fn<File, Boolean>(){
public Boolean apply(File i) {
for(String exclude : excludes){
File e = new File(basedir, exclude);
if(i.getAbsolutePath().startsWith(e.getAbsolutePath())){
getLog().warn("Excluding " + i);
return Boolean.FALSE;
}
}
return Boolean.TRUE;
}
});
JSHint jshint = new JSHint();
final Map<String, Result> currentResults = new HashMap<String, Result>();
for(File file : matches){
Result previousResult = cache.previousResults.get(file.getAbsolutePath());
Result theResult;
if(previousResult==null || (previousResult.lastModified.longValue()!=file.lastModified())){
getLog().info(" " + file );
List<Error> errors = jshint.run(new FileInputStream(file), options, globals);
theResult = new Result(file.getAbsolutePath(), file.lastModified(), errors);
}else{
getLog().info(" " + file + " [no change]");
theResult = previousResult;
}
if(theResult!=null){
currentResults.put(theResult.path, theResult);
Result r = theResult;
currentResults.put(r.path, r);
for(Error error: r.errors){
getLog().error(" " + error.line.intValue() + "," + error.character.intValue() + ": " + error.reason);
}
}
}
Util.writeObject(new Cache(options, this.globals, currentResults), cachePath);
char NEWLINE = '\n';
StringBuilder errorRecap = new StringBuilder(NEWLINE);
int numProblematicFiles = 0;