diff --git a/src/main/java/com/cj/jshintmojo/Mojo.java b/src/main/java/com/cj/jshintmojo/Mojo.java index 8693197..d42bbe4 100644 --- a/src/main/java/com/cj/jshintmojo/Mojo.java +++ b/src/main/java/com/cj/jshintmojo/Mojo.java @@ -18,6 +18,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.maven.model.FileSet; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -27,8 +28,6 @@ import com.cj.jshintmojo.cache.Cache; import com.cj.jshintmojo.cache.Result; import com.cj.jshintmojo.jshint.EmbeddedJshintCode; -import com.cj.jshintmojo.jshint.FunctionalJava; -import com.cj.jshintmojo.jshint.FunctionalJava.Fn; import com.cj.jshintmojo.jshint.JSHint; import com.cj.jshintmojo.jshint.JSHint.Error; import com.cj.jshintmojo.reporter.CheckStyleReporter; @@ -185,25 +184,14 @@ private List findFilesToCheck() { 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); + FileSet fs = new FileSet(); + fs.setDirectory(path.getAbsolutePath()); + fs.addInclude("**/*.js"); + fs.setExcludes(excludes); + javascriptFiles.addAll(toFileList(fs)); } } - - List matches = FunctionalJava.filter(javascriptFiles, new Fn(){ - 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; - } - }); - return matches; + return javascriptFiles; } private static Map lintTheFiles(final JSHint jshint, final Cache cache, List filesToCheck, final Config config, final Log log) throws FileNotFoundException { @@ -368,16 +356,6 @@ private Cache readCache(File path, Cache.Hash hash){ return new Cache(hash); } - - private void collect(File directory, List files) { - for(File next : directory.listFiles()){ - if(next.isDirectory()){ - collect(next, files); - }else if(next.getName().endsWith(".js")){ - files.add(next); - } - } - } /** * Read contents of the specified config file and use the values defined there instead of the ones defined directly in pom.xml config. diff --git a/src/main/java/com/cj/jshintmojo/util/Util.java b/src/main/java/com/cj/jshintmojo/util/Util.java index c195768..7804621 100644 --- a/src/main/java/com/cj/jshintmojo/util/Util.java +++ b/src/main/java/com/cj/jshintmojo/util/Util.java @@ -6,8 +6,10 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.List; import org.apache.commons.io.FileUtils; +import org.apache.maven.model.FileSet; public class Util { @@ -72,5 +74,28 @@ public static void mkdirs(File path) { throw new RuntimeException("Could not create directory: " + path.getAbsolutePath()); } } - + + public static List toFileList(final FileSet fileSet) { + File directory = new File(fileSet.getDirectory()); + String includes = toCommaSeparated(fileSet.getIncludes()); + String excludes = toCommaSeparated(fileSet.getExcludes()); + try { + return org.codehaus.plexus.util.FileUtils.getFiles( + directory, includes, excludes); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String toCommaSeparated(final List strings) { + StringBuilder sb = new StringBuilder(); + for (String s : strings) { + sb.append(s).append(','); + } + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + } + return sb.toString(); + } + }