1 package com.github.searls.jasmine.io; 2 3 import org.codehaus.plexus.util.DirectoryScanner; 4 5 import java.io.File; 6 import java.util.ArrayList; 7 import java.util.Collections; 8 import java.util.LinkedHashSet; 9 import java.util.List; 10 import java.util.Set; 11 12 import static java.util.Arrays.asList; 13 14 public class ScansDirectory { 15 16 public final static List<String> DEFAULT_INCLUDES = asList("**" + File.separator + "*.js", "**" + File.separator + "*.coffee"); 17 18 private final DirectoryScanner directoryScanner = new DirectoryScanner(); 19 20 public List<String> scan(File directory, List<String> includes, List<String> excludes) { 21 Set<String> set = new LinkedHashSet<String>(); 22 for (String include : includes) { 23 set.addAll(performScan(directory, include, excludes)); 24 } 25 return new ArrayList<String>(set); 26 } 27 28 private List<String> performScan(File directory, String include, List<String> excludes) { 29 directoryScanner.setBasedir(directory); 30 directoryScanner.setIncludes(new String[]{include}); 31 directoryScanner.setExcludes(excludes.toArray(new String[]{})); 32 directoryScanner.addDefaultExcludes(); 33 directoryScanner.scan(); 34 ArrayList<String> result = new ArrayList<String>(asList(directoryScanner.getIncludedFiles())); 35 Collections.sort(result); 36 return result; 37 } 38 39 }