Search in sources :

Example 1 with PatternExcludesArtifactFilter

use of org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter in project maven-plugins by apache.

the class DefaultRepositoryAssembler method buildRepositoryFilter.

private ArtifactFilter buildRepositoryFilter(RepositoryInfo repository, MavenProject project) {
    AndArtifactFilter filter = new AndArtifactFilter();
    ArtifactFilter scopeFilter = new ScopeArtifactFilter(repository.getScope());
    filter.add(scopeFilter);
    // ----------------------------------------------------------------------------
    // Includes
    //
    // We'll take everything if no includes are specified to try and make
    // this
    // process more maintainable. Don't want to have to update the assembly
    // descriptor everytime the POM is updated.
    // ----------------------------------------------------------------------------
    List<String> includes = repository.getIncludes();
    if ((includes == null) || includes.isEmpty()) {
        List<String> patterns = new ArrayList<String>();
        Set<Artifact> projectArtifacts = project.getDependencyArtifacts();
        if (projectArtifacts != null) {
            for (Artifact artifact : projectArtifacts) {
                patterns.add(artifact.getDependencyConflictId());
            }
        }
        PatternIncludesArtifactFilter includeFilter = new PatternIncludesArtifactFilter(patterns, true);
        filter.add(includeFilter);
    } else {
        filter.add(new PatternIncludesArtifactFilter(repository.getIncludes(), true));
    }
    // ----------------------------------------------------------------------------
    // Excludes
    //
    // We still want to make it easy to exclude a few things even if we
    // slurp
    // up everything.
    // ----------------------------------------------------------------------------
    List<String> excludes = repository.getExcludes();
    if ((excludes != null) && !excludes.isEmpty()) {
        filter.add(new PatternExcludesArtifactFilter(repository.getExcludes(), true));
    }
    return filter;
}
Also used : ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with PatternExcludesArtifactFilter

use of org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter in project maven-plugins by apache.

the class FilterUtils method filterProjects.

public static Set<MavenProject> filterProjects(final Set<MavenProject> projects, final List<String> includes, final List<String> excludes, final boolean actTransitively, final Logger logger) {
    final List<PatternIncludesArtifactFilter> allFilters = new ArrayList<PatternIncludesArtifactFilter>();
    final AndArtifactFilter filter = new AndArtifactFilter();
    if (!includes.isEmpty()) {
        final PatternIncludesArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
        allFilters.add(includeFilter);
    }
    if (!excludes.isEmpty()) {
        final PatternExcludesArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
        allFilters.add(excludeFilter);
    }
    Set<MavenProject> result = new LinkedHashSet<MavenProject>(projects.size());
    for (MavenProject project : projects) {
        final Artifact artifact = project.getArtifact();
        if (filter.include(artifact)) {
            result.add(project);
        }
    }
    for (final PatternIncludesArtifactFilter f : allFilters) {
        if (f != null) {
            f.reportMissedCriteria(logger);
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with PatternExcludesArtifactFilter

use of org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter in project maven-plugins by apache.

the class FilterUtils method filterArtifacts.

public static void filterArtifacts(final Set<Artifact> artifacts, final List<String> includes, final List<String> excludes, final boolean strictFiltering, final boolean actTransitively, final Logger logger, final ArtifactFilter... additionalFilters) throws InvalidAssemblerConfigurationException {
    final List<ArtifactFilter> allFilters = new ArrayList<ArtifactFilter>();
    final AndArtifactFilter filter = new AndArtifactFilter();
    if (additionalFilters != null && additionalFilters.length > 0) {
        for (final ArtifactFilter additionalFilter : additionalFilters) {
            if (additionalFilter != null) {
                filter.add(additionalFilter);
            }
        }
    }
    if (!includes.isEmpty()) {
        final ArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
        allFilters.add(includeFilter);
    }
    if (!excludes.isEmpty()) {
        final ArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
        allFilters.add(excludeFilter);
    }
    for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) {
        final Artifact artifact = it.next();
        if (!filter.include(artifact)) {
            it.remove();
            if (logger.isDebugEnabled()) {
                logger.debug(artifact.getId() + " was removed by one or more filters.");
            }
        }
    }
    reportFilteringStatistics(allFilters, logger);
    for (final ArtifactFilter f : allFilters) {
        if (f instanceof StatisticsReportingArtifactFilter) {
            final StatisticsReportingArtifactFilter sFilter = (StatisticsReportingArtifactFilter) f;
            if (strictFiltering && sFilter.hasMissedCriteria()) {
                throw new InvalidAssemblerConfigurationException("One or more filters had unmatched criteria. Check debug log for more information.");
            }
        }
    }
}
Also used : PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)3 PatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter)3 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 LinkedHashSet (java.util.LinkedHashSet)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 MavenProject (org.apache.maven.project.MavenProject)1 ScopeArtifactFilter (org.apache.maven.shared.artifact.filter.ScopeArtifactFilter)1 StatisticsReportingArtifactFilter (org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter)1