Example usage for org.apache.commons.io.filefilter AndFileFilter AndFileFilter

List of usage examples for org.apache.commons.io.filefilter AndFileFilter AndFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter AndFileFilter AndFileFilter.

Prototype

public AndFileFilter(final List fileFilters) 

Source Link

Document

Constructs a new instance of AndFileFilter with the specified list of filters.

Usage

From source file:com.arcbees.gwtpolymer.fs.CopyPolymerFilter.java

public CopyPolymerFilter() {
    List<IOFileFilter> filters = new ArrayList<>();
    filters.add(new WildcardFileFilter(
            new String[] { "*.html", "*.css", "*.js", "*.js.map", "src", "transitions" }, INSENSITIVE));
    filters.add(new NotFileFilter(new WildcardFileFilter(NAMES_TO_IGNORE, INSENSITIVE)));

    delegate = new AndFileFilter(filters);
}

From source file:net.peakplatform.sonar.plugins.spring.file.SpringProjectFileSystem.java

public List<InputFile> getFiles() {
    List<InputFile> result = Lists.newArrayList();
    if (getSourceDirs() == null) {
        return result;
    }//w w w .  j  a va  2s .  com

    IOFileFilter suffixFilter = getFileSuffixFilter();
    WildcardPattern[] exclusionPatterns = getExclusionPatterns(true);
    IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE;

    for (File dir : getSourceDirs()) {
        if (dir.exists()) {
            // exclusion filter
            IOFileFilter exclusionFilter = new ExclusionFilter(dir, exclusionPatterns);
            // visible filter
            List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter,
                    exclusionFilter);
            // inclusion filter
            String inclusionPattern = (String) project.getProperty(SpringPlugin.INCLUDE_FILE_FILTER);
            if (inclusionPattern != null) {
                fileFilters.add(new InclusionFilter(dir, inclusionPattern));
            }
            fileFilters.addAll(this.filters);

            // create DefaultInputFile for each file.
            List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters),
                    HiddenFileFilter.VISIBLE);
            for (File file : files) {
                String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir);
                result.add(new DefaultInputFile(dir, relativePath));
            }
        }
    }
    return result;
}

From source file:de.dentrassi.build.apt.repo.AptWriter.java

public void build() throws Exception {
    if (this.configuration.getTargetFolder().exists()) {
        throw new IllegalStateException(
                "The target path must not exists: " + this.configuration.getTargetFolder());
    }/*from w  w w . j  a  va 2s. c  o  m*/

    if (!this.configuration.getSourceFolder().isDirectory()) {
        throw new IllegalStateException(
                "The source path must exists and must be a directory: " + this.configuration.getTargetFolder());
    }

    this.configuration.validate();

    this.configuration.getTargetFolder().mkdirs();

    this.pool = new File(this.configuration.getTargetFolder(), "pool");
    this.dists = new File(this.configuration.getTargetFolder(), "dists");

    this.pool.mkdirs();
    this.dists.mkdirs();

    final FileFilter debFilter = new AndFileFilter( //
            Arrays.asList( //
                    CanReadFileFilter.CAN_READ, //
                    FileFileFilter.FILE, //
                    new SuffixFileFilter(".deb") //
            ) //
    );

    for (final File packageFile : this.configuration.getSourceFolder().listFiles(debFilter)) {
        processPackageFile(packageFile);
    }

    writePackageLists();
}

From source file:de.ee.hezel.PDFCorpusAnalyser.java

/**
 * Run thru the given folders and find pdf document which have the same name.
 * For every pair, a PDFInfoHolder objects gets created.
 * //  w  ww . j ava  2 s  .  c o m
 * @param pdfs1 for the 1st directory
 * @param pdfs2 for the 2nd directory
 * @param prefix 
 * @return list of all pdf pairs
 */
public static Set<PDFInfoHolder> getSimplePDFInfoHolders(File pdfs1, File pdfs2, String prefix) {
    Set<PDFInfoHolder> pdfInfoHolders = new HashSet<PDFInfoHolder>();

    // are those valid pathes
    if (pdfs1 != null && pdfs2 != null && pdfs1.isDirectory() && pdfs2.isDirectory()) {
        // create a filter to only get pdf files
        List<FilenameFilter> filters = new ArrayList<FilenameFilter>();
        if (null != prefix && prefix.length() > 0) {
            PrefixFileFilter filter = new PrefixFileFilter(prefix, IOCase.SYSTEM);
            filters.add(filter);
        }
        filters.add(new SuffixFileFilter(".pdf", IOCase.INSENSITIVE));
        FilenameFilter filter = new AndFileFilter(filters);

        //get all pdf file sin this folder
        String[] pdfDocuments1 = pdfs1.list(filter);

        for (int i = 0; i < pdfDocuments1.length; i++) {
            // get the pdf file name
            String pdfFilename1 = pdfDocuments1[i];

            // get the path for both pdf files
            File pdfFile1 = new File(pdfs1, pdfFilename1);
            File pdfFile2 = new File(pdfs2, pdfFilename1);

            // bind them together in a PDFInfoHolder objects
            PDFInfoHolder newPDFInfoHolder = new PDFInfoHolder(pdfFile1, pdfFile2);

            // remember them all
            pdfInfoHolders.add(newPDFInfoHolder);
        }

        // TODO what should happen if there are less reference documents than new generated ones
    } else {
        log.error("The path is not valid.");
    }

    return pdfInfoHolders;
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * List the files in the given path string with wild cards.
 * //from   w  w  w.  j a  v a2 s.c  om
 * @param baseDir
 *            the base directory to search for files in
 * 
 * @param filePathWithWildCards
 *            the file path to search in - can be absolute
 * 
 * @param recursive
 *            whether to look in sub-directories or not
 * 
 * @param additionalFilters
 *            additional file filters that need to be used when scanning for
 *            files
 * 
 * @return the list of files and directories that match the criteria
 */
public static List<File> listFiles(File baseDir, String filePathWithWildCards, boolean recursive,
        List<IOFileFilter> additionalFilters) {
    if (filePathWithWildCards == null) {
        throw new IllegalArgumentException("Filepath cannot be null");
    }

    // change *.* to *
    filePathWithWildCards = filePathWithWildCards.replace("*.*", "*");

    // normalize
    filePathWithWildCards = FilenameUtils.normalize(filePathWithWildCards);

    if (filePathWithWildCards.endsWith(File.pathSeparator)) {
        filePathWithWildCards += "*";
    }

    // check if this is an absolute path or not
    String prefix = FilenameUtils.getPrefix(filePathWithWildCards);
    final boolean isAbsolute = !prefix.isEmpty();

    // change the base dir if absolute directory
    if (isAbsolute) {
        baseDir = new File(filePathWithWildCards);
        if (!baseDir.isDirectory()) {
            // not a directory - get the base directory
            filePathWithWildCards = baseDir.getName();
            if (filePathWithWildCards.equals("~")) {
                filePathWithWildCards = "*";
            }

            if (AssertUtils.isEmpty(filePathWithWildCards)) {
                filePathWithWildCards = "*";
            }

            baseDir = baseDir.getParentFile();
            if (baseDir == null) {
                baseDir = getUsersHomeDirectory();
            }
        }
    }

    // check if the provided argument is a directory
    File dir = new File(filePathWithWildCards);
    if (dir.isDirectory()) {
        baseDir = dir.getAbsoluteFile();
        filePathWithWildCards = "*";
    } else {
        // let's check for base directory
        File parent = dir.getParentFile();
        if (parent != null) {
            baseDir = parent.getAbsoluteFile();
            filePathWithWildCards = dir.getName();
        }
    }

    // check for user home
    String basePath = baseDir.getPath();
    if (basePath.startsWith("~")) {
        basePath = getUsersHomeDirectory().getAbsolutePath() + File.separator + basePath.substring(1);
        basePath = FilenameUtils.normalize(basePath);
        baseDir = new File(basePath);
    }

    // now read the files
    WildcardFileFilter wildcardFileFilter = new WildcardFileFilter(filePathWithWildCards, IOCase.SYSTEM);
    IOFileFilter finalFilter = wildcardFileFilter;
    if (AssertUtils.isNotEmpty(additionalFilters)) {
        additionalFilters.add(0, wildcardFileFilter);
        finalFilter = new AndFileFilter(additionalFilters);
    }

    Collection<File> files = org.apache.commons.io.FileUtils.listFiles(baseDir, finalFilter,
            recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);

    return (List<File>) files;
}

From source file:org.jumpmind.symmetric.model.FileTrigger.java

public IOFileFilter createIOFileFilter() {
    String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" };
    String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null;
    IOFileFilter filter = new WildcardFileFilter(includes);
    if (excludes != null && excludes.length > 0) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);/*from   w  w  w.j ava2s  .c  o  m*/
        fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes)));
        filter = new AndFileFilter(fileFilters);
    }
    if (!recurse) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter()));
        filter = new AndFileFilter(fileFilters);
    } else {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(FileFilterUtils.directoryFileFilter());
        filter = new OrFileFilter(fileFilters);
    }
    return filter;
}

From source file:org.sonar.batch.bootstrap.TempDirectories.java

/**
 * This method is executed by picocontainer during shutdown.
 *///  www.  ja v  a 2  s  .co m
public void stop() {
    directoriesByKey.clear();

    // Deleting temp directory does not work on MS Windows and Sun JVM because URLClassLoader locks JARs and resources.
    // The workaround is that sonar deletes orphans itself.

    // older than AGE_BEFORE_DELETION to be sure that the current dir is deleted on mac and linux.
    rootDir.setLastModified(System.currentTimeMillis() - AGE_BEFORE_DELETION - 60 * 60 * 1000);

    File[] directoriesToDelete = rootDir.getParentFile()
            .listFiles((FileFilter) new AndFileFilter(
                    Arrays.asList(DirectoryFileFilter.DIRECTORY, new PrefixFileFilter(DIR_PREFIX),
                            new AgeFileFilter(System.currentTimeMillis() - AGE_BEFORE_DELETION))));
    for (File dir : directoriesToDelete) {
        LoggerFactory.getLogger(getClass()).debug("Delete temporary directory: " + dir);
        FileUtils.deleteQuietly(dir);
    }
}

From source file:org.sonar.batch.scan.DefaultProjectBootstrapper.java

/**
 * Returns files matching specified pattern.
 *//* w  w  w.j  ava 2 s  . c o m*/
@VisibleForTesting
protected static File[] getLibraries(File baseDir, String pattern) {
    final int i = Math.max(pattern.lastIndexOf('/'), pattern.lastIndexOf('\\'));
    final String dirPath, filePattern;
    if (i == -1) {
        dirPath = ".";
        filePattern = pattern;
    } else {
        dirPath = pattern.substring(0, i);
        filePattern = pattern.substring(i + 1);
    }
    List<IOFileFilter> filters = new ArrayList<IOFileFilter>();
    if (pattern.indexOf('*') >= 0) {
        filters.add(FileFileFilter.FILE);
    }
    filters.add(new WildcardFileFilter(filePattern));
    File dir = resolvePath(baseDir, dirPath);
    File[] files = dir.listFiles((FileFilter) new AndFileFilter(filters));
    if (files == null) {
        files = new File[0];
    }
    return files;
}

From source file:org.sonar.plugins.web.api.ProjectFileManager.java

/**
 * Gets the list of files that are in scope for importing and analysis.
 *///from   w  ww .  j av  a2s .c  om
public List<InputFile> getFiles() {
    List<InputFile> result = Lists.newArrayList();

    IOFileFilter suffixFilter = getFileSuffixFilter();
    WildcardPattern[] exclusionPatterns = getExclusionPatterns(true);
    IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE;

    for (File dir : sourceDirs) {
        if (dir.exists()) {

            // exclusion filter
            IOFileFilter exclusionFilter = new ExclusionFilter(dir, exclusionPatterns);
            // visible filter
            List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter,
                    exclusionFilter);
            fileFilters.addAll(this.filters);

            // create DefaultInputFile for each file.
            List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters),
                    HiddenFileFilter.VISIBLE);
            for (File file : files) {
                String relativePath = getRelativePath(file, dir);
                result.add(new WebInputFile(dir, relativePath));
            }
        }
    }
    return result;
}

From source file:org.sonar.plugins.xml.XmlProjectFileSystem.java

public List<InputFile> getFiles() {
    List<InputFile> result = Lists.newArrayList();
    if (getSourceDirs() == null) {
        return result;
    }/*from  w ww .j a v  a  2  s.com*/

    IOFileFilter suffixFilter = getFileSuffixFilter();
    WildcardPattern[] exclusionPatterns = getExclusionPatterns(true);
    IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE;

    for (File dir : getSourceDirs()) {
        if (dir.exists()) {

            // exclusion filter
            IOFileFilter exclusionFilter = new ExclusionFilter(dir, exclusionPatterns);
            // visible filter
            List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter,
                    exclusionFilter);
            // inclusion filter
            String inclusionPattern = (String) project.getProperty(XmlPlugin.INCLUDE_FILE_FILTER);
            if (inclusionPattern != null) {
                fileFilters.add(new InclusionFilter(dir, inclusionPattern));
            }
            fileFilters.addAll(this.filters);

            // create DefaultInputFile for each file.
            List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters),
                    HiddenFileFilter.VISIBLE);
            for (File file : files) {
                String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir);
                result.add(new DefaultInputFile(dir, relativePath));
            }
        }
    }
    return result;
}