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 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 DefaultDependencyResolver method resolve.
private void resolve(Assembly assembly, AssemblerConfigurationSource configSource, Map<DependencySet, Set<Artifact>> result, DependencySet dependencySet, ResolutionManagementInfo info) throws DependencyResolutionException {
Set<Artifact> artifacts;
if (info.isResolutionRequired()) {
final List<ArtifactRepository> repos = aggregateRemoteArtifactRepositories(configSource.getRemoteRepositories(), info.getEnabledProjects());
artifacts = info.getArtifacts();
if (info.isResolvedTransitively()) {
getLogger().debug("Resolving project dependencies transitively.");
ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(info.getScopeFilter());
artifacts = resolveTransitively(artifacts, repos, filter, configSource);
} else {
getLogger().debug("Resolving project dependencies ONLY. " + "Transitive dependencies WILL NOT be included in the results.");
artifacts = resolveNonTransitively(assembly, artifacts, configSource, repos);
}
} else {
artifacts = new HashSet<Artifact>();
}
result.put(dependencySet, artifacts);
}
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 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);
}
}
}
Aggregations