use of org.apache.maven.shared.artifact.filter.collection.ScopeFilter in project maven-dependency-plugin 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 true to fail if artifacts can't be resolved false otherwise.
* @param includeParents <code>true</code> if parents should be included or not <code>false</code>.
* @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
* @throws MojoExecutionException in case of errors.
*/
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.shared.artifact.filter.collection.ScopeFilter in project spring-boot by spring-projects.
the class DependencyFilterMojoTests method filterScopeKeepOrder.
@Test
void filterScopeKeepOrder() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "", new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.foo", "two", Artifact.SCOPE_SYSTEM);
Artifact three = createArtifact("com.foo", "three", Artifact.SCOPE_RUNTIME);
Set<Artifact> artifacts = mojo.filterDependencies(one, two, three);
assertThat(artifacts).containsExactly(one, three);
}
use of org.apache.maven.shared.artifact.filter.collection.ScopeFilter in project spring-boot by spring-projects.
the class RepackageMojo method getAdditionalFilters.
private ArtifactsFilter[] getAdditionalFilters() {
List<ArtifactsFilter> filters = new ArrayList<>();
if (this.excludeDevtools) {
Exclude exclude = new Exclude();
exclude.setGroupId("org.springframework.boot");
exclude.setArtifactId("spring-boot-devtools");
ExcludeFilter filter = new ExcludeFilter(exclude);
filters.add(filter);
}
if (!this.includeSystemScope) {
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
}
return filters.toArray(new ArtifactsFilter[filters.size()]);
}
use of org.apache.maven.shared.artifact.filter.collection.ScopeFilter in project spring-boot by spring-projects.
the class AbstractPackagerMojo method getAdditionalFilters.
private ArtifactsFilter[] getAdditionalFilters() {
List<ArtifactsFilter> filters = new ArrayList<>();
if (this.excludeDevtools) {
Exclude exclude = new Exclude();
exclude.setGroupId("org.springframework.boot");
exclude.setArtifactId("spring-boot-devtools");
ExcludeFilter filter = new ExcludeFilter(exclude);
filters.add(filter);
}
if (!this.includeSystemScope) {
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
}
return filters.toArray(new ArtifactsFilter[0]);
}
use of org.apache.maven.shared.artifact.filter.collection.ScopeFilter 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 true to fail if artifacts can't be resolved false otherwise.
* @param includeParents <code>true</code> if parents should be included or not <code>false</code>.
* @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
* @throws MojoExecutionException in case of errors.
*/
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;
}
Aggregations