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);
}
}
}
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.");
}
}
}
}
Aggregations