Search in sources :

Example 21 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project maven-plugins by apache.

the class FilterUtils method reportFilteringStatistics.

public static void reportFilteringStatistics(final Collection<ArtifactFilter> filters, final Logger logger) {
    for (final ArtifactFilter f : filters) {
        if (f instanceof StatisticsReportingArtifactFilter) {
            final StatisticsReportingArtifactFilter sFilter = (StatisticsReportingArtifactFilter) f;
            if (logger.isDebugEnabled()) {
                logger.debug("Statistics for " + sFilter + "\n");
            }
            sFilter.reportMissedCriteria(logger);
            sFilter.reportFilteredArtifacts(logger);
        }
    }
}
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) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter)

Example 22 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter 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

ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)22 Artifact (org.apache.maven.artifact.Artifact)16 ArrayList (java.util.ArrayList)11 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)6 LinkedHashSet (java.util.LinkedHashSet)5 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)5 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)5 File (java.io.File)4 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 PatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter)4 StrictPatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter)4 StrictPatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter)4 IOException (java.io.IOException)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)3 ResolutionGroup (org.apache.maven.artifact.metadata.ResolutionGroup)3 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)3 ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)3 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)3