Search in sources :

Example 1 with NotFileFilter

use of org.apache.commons.io.filefilter.NotFileFilter in project maven-plugins by apache.

the class ScmPublishPublishScmMojo method update.

/**
     * Update scm checkout directory with content.
     *
     * @param checkout        the scm checkout directory
     * @param dir             the content to put in scm (can be <code>null</code>)
     * @param doNotDeleteDirs directory names that should not be deleted from scm even if not in new content:
     *                        used for modules, which content is available only when staging
     * @throws IOException
     */
private void update(File checkout, File dir, List<String> doNotDeleteDirs) throws IOException {
    String scmSpecificFilename = scmProvider.getScmSpecificFilename();
    String[] files = scmSpecificFilename != null ? checkout.list(new NotFileFilter(new NameFileFilter(scmSpecificFilename))) : checkout.list();
    Set<String> checkoutContent = new HashSet<String>(Arrays.asList(files));
    List<String> dirContent = (dir != null) ? Arrays.asList(dir.list()) : Collections.<String>emptyList();
    Set<String> deleted = new HashSet<String>(checkoutContent);
    deleted.removeAll(dirContent);
    MatchPatterns ignoreDeleteMatchPatterns = null;
    List<String> pathsAsList = new ArrayList<String>(0);
    if (ignorePathsToDelete != null && ignorePathsToDelete.length > 0) {
        ignoreDeleteMatchPatterns = MatchPatterns.from(ignorePathsToDelete);
        pathsAsList = Arrays.asList(ignorePathsToDelete);
    }
    for (String name : deleted) {
        if (ignoreDeleteMatchPatterns != null && ignoreDeleteMatchPatterns.matches(name, true)) {
            getLog().debug(name + " match one of the patterns '" + pathsAsList + "': do not add to deleted files");
            continue;
        }
        getLog().debug("file marked for deletion: " + name);
        File file = new File(checkout, name);
        if ((doNotDeleteDirs != null) && file.isDirectory() && (doNotDeleteDirs.contains(name))) {
            // ignore directory not available
            continue;
        }
        if (file.isDirectory()) {
            update(file, null, null);
        }
        this.deleted.add(file);
    }
    for (String name : dirContent) {
        File file = new File(checkout, name);
        File source = new File(dir, name);
        if (source.isDirectory()) {
            directories++;
            if (!checkoutContent.contains(name)) {
                this.added.add(file);
                file.mkdir();
            }
            update(file, source, null);
        } else {
            if (checkoutContent.contains(name)) {
                this.updated.add(file);
            } else {
                this.added.add(file);
            }
            copyFile(source, file);
        }
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) MatchPatterns(org.codehaus.plexus.util.MatchPatterns) ArrayList(java.util.ArrayList) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with NotFileFilter

use of org.apache.commons.io.filefilter.NotFileFilter in project symmetric-ds by JumpMind.

the class FileTrigger method createIOFileFilter.

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);
        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;
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) OrFileFilter(org.apache.commons.io.filefilter.OrFileFilter) ArrayList(java.util.ArrayList) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Aggregations

ArrayList (java.util.ArrayList)2 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)2 File (java.io.File)1 HashSet (java.util.HashSet)1 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 OrFileFilter (org.apache.commons.io.filefilter.OrFileFilter)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 MatchPatterns (org.codehaus.plexus.util.MatchPatterns)1