All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vandmo.textchecker.maven.FileSupplier Maven / Gradle / Ivy

There is a newer version: 0.22.1
Show newest version
package se.vandmo.textchecker.maven;

import static java.util.Arrays.asList;
import static org.apache.commons.io.FileUtils.listFiles;

import java.io.File;
import java.util.Collection;

import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;

import com.google.common.collect.ImmutableSet;


public final class FileSupplier {

  private static final ImmutableSet EXCLUDES = ImmutableSet.of("target", ".git", ".junk");

  private final File baseFolder;

  public FileSupplier(File baseFolder) {
    this.baseFolder = baseFolder;
  }

  public Collection getFiles() {
    return listFiles(baseFolder,
      new SuffixFileFilter(
        asList(".java", ".txt", ".xml", ".js", ".html")),
      new IOFileFilter() {
        @Override
        public boolean accept(File dir) {
          return dir.isDirectory() && !EXCLUDES.contains(dir.getName());
        }

        @Override
        public boolean accept(File dir, String name) {
          return true;
        }
      });
  }

  public String relativeFileNameFor(File file) {
    return file.getAbsolutePath().substring(baseFolder.getAbsolutePath().length() + 1);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy