Search in sources :

Example 31 with ArtifactFilter

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

the class AbstractAnalyzeMojo method filterDependencies.

private List<Artifact> filterDependencies(Set<Artifact> artifacts, String[] excludes) throws MojoExecutionException {
    ArtifactFilter filter = new StrictPatternExcludesArtifactFilter(Arrays.asList(excludes));
    List<Artifact> result = new ArrayList<Artifact>();
    for (Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) {
        Artifact artifact = it.next();
        if (!filter.include(artifact)) {
            it.remove();
            result.add(artifact);
        }
    }
    return result;
}
Also used : StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 32 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project fabric8 by jboss-fuse.

the class AbstractProfileMojo method createResolvingArtifactFilter.

/**
 * Gets the artifact filter to use when resolving the dependency tree.
 *
 * @return the artifact filter
 */
private ArtifactFilter createResolvingArtifactFilter() {
    ArtifactFilter filter;
    if (scope != null) {
        getLog().debug("+ Resolving dependency tree for scope '" + scope + "'");
        filter = new ScopeArtifactFilter(scope);
    } else {
        filter = null;
    }
    return filter;
}
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)

Example 33 with ArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ArtifactFilter in project scala-maven-plugin by davidB.

the class ScalaMojoSupport method createScalaDistroDependencyFilter.

/**
 * @return
 *          A filter to only extract artifacts deployed from scala distributions
 */
private DependencyNodeFilter createScalaDistroDependencyFilter() {
    List<ArtifactFilter> filters = new ArrayList<ArtifactFilter>();
    filters.add(new ScalaDistroArtifactFilter(getScalaOrganization()));
    return new AndDependencyNodeFilter(filters);
}
Also used : AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ScalaDistroArtifactFilter(scala_maven_dependency.ScalaDistroArtifactFilter) ScalaDistroArtifactFilter(scala_maven_dependency.ScalaDistroArtifactFilter) AndDependencyNodeFilter(org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter) ArrayList(java.util.ArrayList)

Example 34 with ArtifactFilter

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

the class FilterUtilsTest method testFilterArtifacts_ShouldRemoveArtifactExcludedByAdditionalFilter.

public void testFilterArtifacts_ShouldRemoveArtifactExcludedByAdditionalFilter() throws InvalidAssemblerConfigurationException {
    final ArtifactFilter filter = new ArtifactFilter() {

        public boolean include(final Artifact artifact) {
            return false;
        }
    };
    verifyArtifactExclusion("group", "artifact", "fail:fail", null, null, filter);
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 35 with ArtifactFilter

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

the class TreeMojo method execute.

// Mojo methods -----------------------------------------------------------
/*
     * @see org.apache.maven.plugin.Mojo#execute()
     */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    try {
        String dependencyTreeString;
        // TODO: note that filter does not get applied due to MSHARED-4
        ArtifactFilter artifactFilter = createResolvingArtifactFilter();
        if (verbose) {
            // To fix we probably need a different DependencyCollector in Aether, which doesn't remove nodes which
            // have already been resolved.
            getLog().info("Verbose not supported since maven-dependency-plugin 3.0");
        }
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setProject(project);
        // non-verbose mode use dependency graph component, which gives consistent results with Maven version
        // running
        rootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, artifactFilter, reactorProjects);
        dependencyTreeString = serializeDependencyTree(rootNode);
        if (outputFile != null) {
            DependencyUtil.write(dependencyTreeString, outputFile, this.appendOutput, getLog());
            getLog().info("Wrote dependency tree to: " + outputFile);
        } else {
            DependencyUtil.log(dependencyTreeString, getLog());
        }
    } catch (DependencyGraphBuilderException exception) {
        throw new MojoExecutionException("Cannot build project dependency graph", exception);
    } catch (IOException exception) {
        throw new MojoExecutionException("Cannot serialise project dependency graph", exception);
    }
}
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) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyGraphBuilderException(org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException) IOException(java.io.IOException) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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