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;
}
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());
}
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());
}
Aggregations