Search in sources :

Example 41 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 42 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project maven-plugins by apache.

the class PurgeLocalRepositoryMojo method purgeLocalRepository.

/**
 * Purges the local repository for the dependencies in the given Maven project.
 *
 * @param project Maven project.
 * @param resolvedArtifactsToPurge The artifacts that were already purged.
 * @throws MojoFailureException in case of errors during the purge.
 */
private void purgeLocalRepository(MavenProject project, Set<Artifact> purgedArtifacts) throws MojoFailureException {
    List<Dependency> dependencies = project.getDependencies();
    TransformableFilter dependencyFilter = createPurgeArtifactsFilter(project, dependencies, purgedArtifacts);
    Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(project, dependencies, dependencyFilter);
    if (resolvedArtifactsToPurge.isEmpty()) {
        getLog().info("No artifacts included for purge for project: " + project.getId());
        return;
    }
    verbose("Purging dependencies for project: " + project.getId());
    purgeArtifacts(resolvedArtifactsToPurge);
    purgedArtifacts.addAll(resolvedArtifactsToPurge);
    if (reResolve) {
        ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
        try {
            reResolveArtifacts(project, resolvedArtifactsToPurge, artifactFilter);
        } catch (ArtifactResolutionException e) {
            String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
            MojoFailureException failure = new MojoFailureException(failureMessage);
            failure.initCause(e);
            throw failure;
        } catch (ArtifactNotFoundException e) {
            String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
            MojoFailureException failure = new MojoFailureException(failureMessage);
            failure.initCause(e);
            throw failure;
        }
    }
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) TransformableFilter(org.apache.maven.shared.artifact.filter.resolve.TransformableFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.apache.maven.model.Dependency) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 43 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project fabric8 by fabric8io.

the class BuildMojo method collectClassPath.

private ArrayList<Artifact> collectClassPath() throws DependencyGraphBuilderException {
    ArtifactFilter filter = new ScopeArtifactFilter(scope);
    DependencyNode rootNode = dependencyGraphBuilder.buildDependencyGraph(project, filter);
    final ArrayList<Artifact> artifacts = new ArrayList<>();
    rootNode.accept(new DependencyNodeVisitor() {

        @Override
        public boolean visit(DependencyNode dependencyNode) {
            artifacts.add(dependencyNode.getArtifact());
            return true;
        }

        @Override
        public boolean endVisit(DependencyNode dependencyNode) {
            return true;
        }
    });
    return artifacts;
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DependencyNodeVisitor(org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor)

Example 44 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project wso2-synapse by wso2.

the class AbstractXarMojo method buildSynapseRuntimeArtifactFilter.

/**
 * Build a filter that excludes all artifacts that are provided by Synapse at runtime.
 *
 * @return
 * @throws MojoExecutionException
 */
private ArtifactFilter buildSynapseRuntimeArtifactFilter() throws MojoExecutionException {
    final Map<String, Artifact> artifacts = new HashMap<String, Artifact>();
    for (Artifact artifact : getSynapseRuntimeArtifacts()) {
        artifacts.put(artifact.getDependencyConflictId(), artifact);
    }
    final Set<String> defaultExclusionSet = new HashSet<String>(Arrays.asList(defaultRuntimeExcludes));
    return new ArtifactFilter() {

        public boolean include(Artifact artifact) {
            Artifact runtimeArtifact = artifacts.get(artifact.getDependencyConflictId());
            if (runtimeArtifact == null) {
                return !defaultExclusionSet.contains(artifact.getDependencyConflictId());
            } else {
                if (!runtimeArtifact.getVersion().equals(artifact.getVersion())) {
                    getLog().warn("Possible runtime version conflict for " + artifact.getArtifactId() + ": XAR depends on " + artifact.getVersion() + ", Synapse runtime provides " + runtimeArtifact.getVersion());
                }
                return false;
            }
        }
    };
}
Also used : AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) TypeArtifactFilter(org.apache.maven.artifact.resolver.filter.TypeArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) HashMap(java.util.HashMap) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Aggregations

ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)44 Artifact (org.apache.maven.artifact.Artifact)32 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)20 ArrayList (java.util.ArrayList)18 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)12 LinkedHashSet (java.util.LinkedHashSet)10 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)10 StrictPatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter)8 Dependency (org.apache.maven.model.Dependency)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 StrictPatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter)7 File (java.io.File)6 IOException (java.io.IOException)6 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)6 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)5 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)4 ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)4 PatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter)4 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)4 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)4