Search in sources :

Example 1 with MatchPatterns

use of org.codehaus.plexus.util.MatchPatterns 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 MatchPatterns

use of org.codehaus.plexus.util.MatchPatterns in project maven-plugins by apache.

the class AbstractJDepsMojo method addJDepsClasses.

protected void addJDepsClasses(Commandline cmd) {
    // <classes> can be a pathname to a .class file, a directory, a JAR file, or a fully-qualified class name.
    cmd.createArg().setFile(new File(getClassesDirectory()));
    if (dependenciesToAnalyzeIncludes != null) {
        MatchPatterns includes = MatchPatterns.from(dependenciesToAnalyzeIncludes);
        MatchPatterns excludes;
        if (dependenciesToAnalyzeExcludes != null) {
            excludes = MatchPatterns.from(dependenciesToAnalyzeExcludes);
        } else {
            excludes = MatchPatterns.from(Collections.<String>emptyList());
        }
        for (Artifact artifact : project.getArtifacts()) {
            String versionlessKey = ArtifactUtils.versionlessKey(artifact);
            if (includes.matchesPatternStart(versionlessKey, true) && !excludes.matchesPatternStart(versionlessKey, true)) {
                cmd.createArg().setFile(artifact.getFile());
            }
        }
    }
}
Also used : MatchPatterns(org.codehaus.plexus.util.MatchPatterns) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)2 MatchPatterns (org.codehaus.plexus.util.MatchPatterns)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)1 Artifact (org.apache.maven.artifact.Artifact)1