*/
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("using jshint version " + version);
JSHint jshint;
try {
jshint = new JSHint(version);
} catch (IllegalArgumentException err) {
getLog().debug(err);
throw new MojoFailureException(err.getMessage());
}
if (StringUtils.isNotBlank(this.configFile)) {
getLog().info("Reading JSHint settings from configuration file: " + this.configFile);
processConfigFile();
}
if(directories.isEmpty()){
directories.add("src");
}
getLog().debug("Globals are : " + globals);
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;
}
});
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;
}