Search in sources :

Example 16 with ArtifactFilter

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);
}
Also used : StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) StrictPatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) StrictPatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter) StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter) ArrayList(java.util.ArrayList) ArtifactDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter) DependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter) AncestorOrSelfDependencyNodeFilter(org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter)

Example 17 with ArtifactFilter

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;
}
Also used : ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 18 with ArtifactFilter

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);
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 19 with ArtifactFilter

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
    }
}
Also used : DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) Logger(org.codehaus.plexus.logging.Logger) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) MavenProject(org.apache.maven.project.MavenProject) GroupVersionAlignment(org.apache.maven.plugins.assembly.repository.model.GroupVersionAlignment) File(java.io.File)

Example 20 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)

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