use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project maven-plugins by apache.
the class TreeMojo method createDependencyNodeFilter.
/**
* Gets the dependency node filter to use when serializing the dependency graph.
*
* @return the dependency node filter, or <code>null</code> if none required
*/
private DependencyNodeFilter createDependencyNodeFilter() {
List<DependencyNodeFilter> filters = new ArrayList<DependencyNodeFilter>();
// filter includes
if (includes != null) {
List<String> patterns = Arrays.asList(includes.split(","));
getLog().debug("+ Filtering dependency tree by artifact include patterns: " + patterns);
ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter(patterns);
filters.add(new ArtifactDependencyNodeFilter(artifactFilter));
}
// filter excludes
if (excludes != null) {
List<String> patterns = Arrays.asList(excludes.split(","));
getLog().debug("+ Filtering dependency tree by artifact exclude patterns: " + patterns);
ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter(patterns);
filters.add(new ArtifactDependencyNodeFilter(artifactFilter));
}
return filters.isEmpty() ? null : new AndDependencyNodeFilter(filters);
}
use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project maven-plugins by apache.
the class DefaultRepositoryAssembler method buildRemoteRepository.
public void buildRemoteRepository(File repositoryDirectory, RepositoryInfo repository, RepositoryBuilderConfigSource configSource) throws RepositoryAssemblyException {
MavenProject project = configSource.getProject();
ProjectBuildingRequest buildingRequest = configSource.getProjectBuildingRequest();
Iterable<ArtifactResult> result = null;
Collection<Dependency> dependencies = project.getDependencies();
if (dependencies == null) {
Logger logger = getLogger();
if (logger.isDebugEnabled()) {
logger.debug("dependency-artifact set for project: " + project.getId() + " is null. Skipping repository processing.");
}
return;
}
Collection<Dependency> managedDependencies = null;
if (project.getDependencyManagement() != null) {
managedDependencies = project.getDependencyManagement().getDependencies();
}
// Older Aether versions use an cache which can't be cleared. So can't delete repoDir and use it again.
// Instead create a temporary repository, delete it at end (should be in a finally-block)
File tempRepo = new File(repositoryDirectory.getParentFile(), repositoryDirectory.getName() + "_tmp");
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, tempRepo);
try {
result = dependencyResolver.resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
} catch (DependencyResolverException e) {
throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
}
ArtifactFilter filter = buildRepositoryFilter(repository, project);
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, repositoryDirectory);
Map<String, GroupVersionAlignment> groupVersionAlignments = createGroupVersionAlignments(repository.getGroupVersionAlignments());
assembleRepositoryArtifacts(buildingRequest, result, filter, groupVersionAlignments);
if (repository.isIncludeMetadata()) {
// assembleRepositoryMetadata( result, filter, centralRepository, targetRepository );
}
try {
FileUtils.deleteDirectory(tempRepo);
} catch (IOException e) {
// noop
}
}
use of org.apache.maven.artifact.resolver.filter.ArtifactFilter 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;
}
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