Search in sources :

Example 1 with StatisticsReportingArtifactFilter

use of org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter 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 2 with StatisticsReportingArtifactFilter

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

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