com.joestelmach.util.FileSearcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zipper Show documentation
Show all versions of zipper Show documentation
Zipper is a full-featured asset packaging plugin for Maven that
provides JavaScript lint lint checking, Closure Compiler and
YUI Compressor support, CSS and JavaScript concatenation,
and up-front gzipping.
package com.joestelmach.util;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.plexus.util.DirectoryScanner;
/**
* Locates files using standard ant patterns
* http://ant.apache.org/manual/dirtasks.html#patterns
*
* @author Joe Stelmach
*/
public class FileSearcher {
/**
* Searches for files with the given pattern, starting in the given base directory,
* and returns a list of absolute paths to matching files.
*
* @param pattern
* @param basePath
* @return
*/
public List search(String pattern, String basePath) {
File baseDir = new File(basePath);
if(pattern.startsWith("/")) pattern = pattern.substring(1);
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
scanner.setIncludes(new String[]{pattern});
scanner.addDefaultExcludes();
scanner.scan();
List fileNames = new ArrayList();
for(String fileName:scanner.getIncludedFiles() ) {
fileNames.add(baseDir + "/" + fileName);
}
return fileNames;
}
}