A {@link DirectoryScanner} boiler plate.

@param fileSet {@link FileSet} to scan
@return the included paths
326147
private String[] scan( FileSet fileSet )
    {
        File basedir = new File( fileSet.getDirectory() );
        if ( !basedir.exists() || !basedir.isDirectory() )
        {
            return null;
        }

        DirectoryScanner scanner = new DirectoryScanner();

        List<String> includes = fileSet.getIncludes();
        List<String> excludes = fileSet.getExcludes();

        if ( includes != null && includes.size() > 0 )
        {
            scanner.setIncludes( includes.toArray( new String[0] ) );
        }

        if ( excludes != null && excludes.size() > 0 )
        {
            scanner.setExcludes( excludes.toArray( new String[0] ) );
        }

        scanner.setBasedir( basedir );

        scanner.scan();
        return scanner.getIncludedFiles();
    }
664758
public static List getClasspathDirectories()
    {
        List directories = new ArrayList();
        List components = getClasspathComponents();
        for (Iterator i = components.iterator(); i.hasNext();)
        {
            String possibleDir = (String) i.next();
            File file = new File(possibleDir);
            if (file.isDirectory())
            {
                directories.add(possibleDir);
            }
        }
        List tomcatPaths = getTomcatPaths();
        if (tomcatPaths != null)
        {
            directories.addAll(tomcatPaths);
        }
        return directories;
    }
586639
public static ArrayList<File> getDirectoriesInDirectoryTree(String path) {
		File file = new File(path);
		return getContentsInDirectoryTree(file, "*", false, true);
	}
104242
public String[] getSpillingDirectoriesPaths() {
		String[] strings = new String[this.paths.length];
		for (int i = 0; i < strings.length; i++) {
			strings[i] = paths[i].getAbsolutePath();
		}
		return strings;
	}
749046
public Set<String> getPackagesFromMainSources() {
        Set<String> packages = new LinkedHashSet<>();
        File classes = getClassesDirectory();
        if (classes.isDirectory()) {
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(classes);
            scanner.setIncludes(new String[]{"**/*.class"});
            scanner.addDefaultExcludes();
            scanner.scan();

            for (int i = 0; i < scanner.getIncludedFiles().length; i++) {
                packages.add(Packages.getPackageName(scanner.getIncludedFiles()[i]));
            }
        }

        return packages;
    }
54200
private List<Path> getApplicableFilePaths(final Path dataDir, final FileSystem fs) throws IOException {
    try {
      return applicablePathCache.get(dataDir, new Callable<List<Path>>() {

        @Override
        public List<Path> call() throws Exception {
          if (!MRCompactorJobRunner.this.fs.exists(dataDir)) {
            return Lists.newArrayList();
          }
          List<Path> paths = Lists.newArrayList();
          for (FileStatus fileStatus : FileListUtils.listFilesRecursively(fs, dataDir,
              new PathFilter() {
            @Override
            public boolean accept(Path path) {
              for (String validExtention : getApplicableFileExtensions()) {
                if (path.getName().endsWith(validExtention)) {
                  return true;
                }
              }
              return false;
            }
          })) {
            paths.add(fileStatus.getPath());
          }
          return paths;
        }
      });
    } catch (ExecutionException e) {
      throw new IOException(e);
    }
  }
370
public SortedSet<T> firstSubset(SortedSet<T> set) {
        if (this.rootNodes.isEmpty() || set == null || set.isEmpty()) {
            return null;
        }
        return firstSubset(set, this.rootNodes);
    }
1016417
public static TreeSet<File> getLogFiles() {

        TreeSet<File> result = new TreeSet<>();
        for (File file : new File(CmsLogFileApp.LOG_FOLDER).listFiles()) {
            result.add(file);
        }
        for (String dir : getAdditionalLogDirectories()) {
            File file = new File(dir);
            if (file.exists()) {
                if (file.isDirectory()) {
                    for (File child : file.listFiles()) {
                        if (child.canRead()) {
                            result.add(child);
                        } else {
                            LOG.error("Can not read " + child.getAbsolutePath());
                        }
                    }
                }
            }
        }
        return result;
    }
1364923
private SortedSet<ClassDoc> get(Map<ClassDoc, SortedSet<ClassDoc>> map, ClassDoc cd) {
        SortedSet<ClassDoc> aset = map.get(cd);
        if (aset == null) {
            return new TreeSet<>(comparator);
        }
        return aset;
    }
1177441
public List<String> scan() {
        try {
            JarFile jar = new JarFile(jarURL.getFile());
            try {
                List<String> result = new ArrayList<>();
                Enumeration<JarEntry> en = jar.entries();
                while (en.hasMoreElements()) {
                    JarEntry entry = en.nextElement();
                    String path = entry.getName();
                    boolean match = includes.size() == 0;
                    if (!match) {
                        for (String pattern : includes) {
                            if ( patternMatches(pattern, path)) {
                                match = true;
                                break;
                            }
                        }
                    }
                    if (match) {
                        for (String pattern : excludes) {
                            if ( patternMatches(pattern, path)) {
                                match = false;
                                break;
                            }
                        }
                    }
                    if (match) {
                        result.add(path);
                    }
                }
                return result;
            } finally {
                jar.close();
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
305823
private static Set<File> findAllFiles(File dir) {
        Set<File> foundFiles = new HashSet<>();
        if (dir == null) {
            return foundFiles;
        }
        recurse(dir, foundFiles);
        return foundFiles;
    }
497646
private void addFilePathMapping(BundlePathMapping bundlePathMapping, Set<String> paths) {
		for (String path : paths) {
			addFilePathMapping(bundlePathMapping, path);
		}
	}
1166632
public static ArrayList<File> getFilesInDirectoryTree(String path) {
		File directory = new File(path);
		return getContentsInDirectoryTree(directory, "*", true, false);
	}
517575
@SuppressWarnings("PMD.AvoidThreadGroup")
    private String[] findFiles(final File workspaceRoot) {
        FileSet fileSet = new FileSet();
        org.apache.tools.ant.Project project = new org.apache.tools.ant.Project();
        fileSet.setProject(project);
        fileSet.setDir(workspaceRoot);
        fileSet.setIncludes(filePattern);

        if (StringUtils.isNotBlank(excludeFilePattern)) {
            fileSet.setExcludes(excludeFilePattern);
        }

        log("Scanning folder '" + workspaceRoot + "' for files matching the pattern '" + filePattern
                + "' - excludes: " + excludeFilePattern);

        return fileSet.getDirectoryScanner(project).getIncludedFiles();
    }
62406
public final Set<K> keySet() {
		try {
			Set<K> set = new HashSet<K>();
			listFilesToSet(getPath(), set);
			return set;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
575224
@SuppressWarnings("unchecked")
    private Set<Path> extractUserProvidedClassPathEntries(Container container) {
        Map<Path, List<String>> localizedResources;
        try {
            Field lf = container.getClass().getDeclaredField("localizedResources");
            lf.setAccessible(true);
            localizedResources = (Map<Path, List<String>>) lf.get(container);
            Set<Path> paths = localizedResources.keySet();
            // Needed for Tez
            for (Path path : paths) {
                if (path.toString().endsWith("tez-conf.pb") || path.toString().endsWith("tez-dag.pb")){
                    File sourceFile = new File(path.toUri());

                    File targetFile = new File(System.getenv(Environment.PWD.name()) + "/" + sourceFile.getName());
                    FileUtils.copyFile(sourceFile, targetFile);

//			System.out.println("######## Copied file: " + targetFile);
//			FileInputStream fis = new FileInputStream(new File(System.getenv(Environment.PWD.name()), targetFile.getName()));
//			System.out.println(fis.available());
//			fis.close();
//			break;
                }
            }
            return paths;
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1109346
public static List<File> pathsFiles(final String paths, final Predicate<File> predicate) {
        final List<File> files = new ArrayList<File>();
        for (final String filePathAndName : paths.split(File.pathSeparator)) {
            final File file = new File(filePathAndName);
            if (file.isDirectory()) {
                try (final Stream<Path> stream = Files.walk(file.toPath(), Integer.MAX_VALUE)) {
                    stream.map(f -> f.toFile()).filter(predicate).forEach(files::add);
                } catch (final IOException ex) {
                    throw new RuntimeException("Error walking path: " + file, ex);
                }
            } else {
                if (predicate.test(file)) {
                    files.add(file);
                }
            }
        }
        return files;
    }