Skip to content

Commit

Permalink
fix cjdev2#33 Excludes should allow for glob patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Crydust committed Feb 19, 2014
1 parent 2470797 commit 8f9760b
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions src/main/java/com/cj/jshintmojo/Mojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,53 @@ private List<File> findFilesToCheck() {
}

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;
}
}
public Boolean apply(File i) {
for (String exclude : excludes) {
if (!stringIsGlob(exclude)) {
File e = new File(basedir, exclude);
if (i.getAbsolutePath().startsWith(e.getAbsolutePath())) {
getLog().warn("Excluding " + i);

return Boolean.FALSE;
}
} else {
String path;
try {
path = i.getCanonicalPath();
} catch (IOException ex) {
getLog().debug("getCanonicalPath failed " + ex.getMessage());
path = i.getAbsolutePath();
}
if (pathMatchesGlob(path, exclude)) {
getLog().warn("Excluding " + i);
return Boolean.FALSE;
}
}
}

return Boolean.TRUE;
}
return Boolean.TRUE;
}
});
return matches;
}

private static boolean stringIsGlob(final String glob) {
return glob.contains("*") || glob.contains("?");
}

private static boolean pathMatchesGlob(final String path, final String glob) {
String cleanPath = path
.replaceAll("\\\\", "/");
String regex = glob
.replaceAll("\\\\", "/")
.replaceAll("\\.", "\\\\.")
.replaceAll("\\*\\*+", "\\\\DOUBLESTAR\\\\")
.replaceAll("\\*", "[^/]*")
.replaceAll("\\\\DOUBLESTAR\\\\", ".*")
.replaceAll("\\?", "[^/]");
return cleanPath.matches(regex);
}

private static Map<String, Result> lintTheFiles(final JSHint jshint, final Cache cache, List<File> filesToCheck, final Config config, final Log log) throws FileNotFoundException {
final Map<String, Result> currentResults = new HashMap<String, Result>();
for(File file : filesToCheck){
Expand Down

0 comments on commit 8f9760b

Please sign in to comment.