Merge branch '1.5.x'

This commit is contained in:
Phillip Webb
2017-03-02 00:09:56 -08:00
17 changed files with 172 additions and 88 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.boot.maven;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
@@ -87,29 +87,15 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
this.excludeArtifactIds = excludeArtifactIds;
}
@SuppressWarnings("unchecked")
protected Set<Artifact> filterDependencies(Set<Artifact> dependencies,
FilterArtifacts filters) throws MojoExecutionException {
List<ArtifactsFilter> artifactsFilters = filters.getFilters();
try {
for (ArtifactsFilter filter : artifactsFilters) {
Set<Artifact> result = filter.filter(dependencies);
applyFiltering(dependencies, result);
}
return dependencies;
Set<Artifact> filtered = new LinkedHashSet<Artifact>(dependencies);
filtered.retainAll(filters.filter(dependencies));
return filtered;
}
catch (ArtifactFilterException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
private void applyFiltering(Set<Artifact> original, Set<Artifact> filtered) {
Iterator<Artifact> iterator = original.iterator();
while (iterator.hasNext()) {
Artifact element = iterator.next();
if (!filtered.contains(element)) {
iterator.remove();
}
catch (ArtifactFilterException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}

View File

@@ -103,7 +103,7 @@ public class DependencyFilterMojoTests {
}
@Test
public void filterExcludeKeepOrder() throws MojoExecutionException {
public void filterExcludeKeepOrder() throws MojoExecutionException {
Exclude exclude = new Exclude();
exclude.setGroupId("com.bar");
exclude.setArtifactId("two");
@@ -121,7 +121,8 @@ public class DependencyFilterMojoTests {
return createArtifact(groupId, artifactId, null);
}
private static Artifact createArtifact(String groupId, String artifactId, String scope) {
private static Artifact createArtifact(String groupId, String artifactId,
String scope) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);