Search in sources :

Example 6 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class AbstractDependencyFilterMojo method getDependencySets.

/**
     * Method creates filters and filters the projects dependencies. This method
     * also transforms the dependencies if classifier is set. The dependencies
     * are filtered in least specific to most specific order
     *
     * @param stopOnFailure
     * @return DependencyStatusSets - Bean of TreeSets that contains information
     *         on the projects dependencies
     * @throws MojoExecutionException
     */
protected DependencyStatusSets getDependencySets(boolean stopOnFailure, boolean includeParents) throws MojoExecutionException {
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();
    filter.addFilter(new ProjectTransitivityFilter(getProject().getDependencyArtifacts(), this.excludeTransitive));
    filter.addFilter(new ScopeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeScope), DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
    filter.addFilter(new TypeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeTypes), DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
    filter.addFilter(new ClassifierFilter(DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers), DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
    filter.addFilter(new GroupIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds), DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
    filter.addFilter(new ArtifactIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds), DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
    // start with all artifacts.
    Set<Artifact> artifacts = getProject().getArtifacts();
    if (includeParents) {
        // add dependencies parents
        for (Artifact dep : new ArrayList<Artifact>(artifacts)) {
            addParentArtifacts(buildProjectFromArtifact(dep), artifacts);
        }
        // add current project parent
        addParentArtifacts(getProject(), artifacts);
    }
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // transform artifacts if classifier is set
    DependencyStatusSets status;
    if (StringUtils.isNotEmpty(classifier)) {
        status = getClassifierTranslatedDependencies(artifacts, stopOnFailure);
    } else {
        status = filterMarkedDependencies(artifacts);
    }
    return status;
}
Also used : ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) ProjectTransitivityFilter(org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter) ClassifierFilter(org.apache.maven.shared.artifact.filter.collection.ClassifierFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) TypeFilter(org.apache.maven.shared.artifact.filter.collection.TypeFilter) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Example 7 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class TestCollectMojo method testCollectTestEnvironment_excludeTransitive.

/**
     * tests the proper discovery and configuration of the mojo
     *
     * @throws Exception if a problem occurs
     */
public void testCollectTestEnvironment_excludeTransitive() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
    CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    mojo.setSilent(true);
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
    mojo.execute();
    DependencyStatusSets results = mojo.getResults();
    assertNotNull(results);
    assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
}
Also used : CollectDependenciesMojo(org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo) MavenProject(org.apache.maven.project.MavenProject) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class TestResolveMojo method testresolveTestEnvironment.

/**
     * tests the proper discovery and configuration of the mojo
     * 
     * @throws Exception
     */
public void testresolveTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml");
    ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    mojo.setSilent(true);
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    DependencyStatusSets results = mojo.getResults();
    assertNotNull(results);
    assertEquals(artifacts.size(), results.getResolvedDependencies().size());
    setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
    mojo.execute();
    results = mojo.getResults();
    assertNotNull(results);
    assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ResolveDependenciesMojo(org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)8 DependencyStatusSets (org.apache.maven.plugins.dependency.utils.DependencyStatusSets)8 File (java.io.File)4 MavenProject (org.apache.maven.project.MavenProject)3 LinkedHashSet (java.util.LinkedHashSet)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CollectDependenciesMojo (org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo)2 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)2 FilterArtifacts (org.apache.maven.shared.artifact.filter.collection.FilterArtifacts)2 ArrayList (java.util.ArrayList)1 ResolveDependenciesMojo (org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo)1 DefaultFileMarkerHandler (org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler)1 ArtifactTranslator (org.apache.maven.plugins.dependency.utils.translators.ArtifactTranslator)1 ClassifierTypeTranslator (org.apache.maven.plugins.dependency.utils.translators.ClassifierTypeTranslator)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 ArtifactCoordinate (org.apache.maven.shared.artifact.ArtifactCoordinate)1 ArtifactIdFilter (org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter)1 ClassifierFilter (org.apache.maven.shared.artifact.filter.collection.ClassifierFilter)1 GroupIdFilter (org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)1 ProjectTransitivityFilter (org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter)1