use of java.nio.file.PathMatcher in project JMRI by JMRI.
the class FileLineEndingsTest method getFiles.
/**
* Get all files with the given prefixes in a directory and validate them.
*
* @param directory the directory containing the files
* @param patterns glob patterns of files to match
* @return a collection of files to validate
*/
public static Collection<Object[]> getFiles(File directory, String[] patterns) {
// setup logging early so this method can log
Log4JFixture.setUp();
ArrayList<Object[]> files = new ArrayList<>();
try {
for (String pattern : patterns) {
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
// ignore the build directory if immediately under the passed in directory
PathMatcher target = FileSystems.getDefault().getPathMatcher("glob:./target/**");
Files.walk(directory.toPath()).filter(path -> !target.matches(path)).filter(matcher::matches).forEach((path) -> {
if (path.toFile().isFile()) {
files.add(new Object[] { path.toFile() });
}
});
}
} catch (IOException ex) {
log.error("Unable to get files in {}", directory, ex);
}
return files;
}
Aggregations