|
20 | 20 |
|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Set;
|
| 23 | +import java.util.function.Predicate; |
23 | 24 | import java.util.stream.Collectors;
|
24 | 25 |
|
25 | 26 | import org.apache.maven.artifact.ArtifactUtils;
|
26 | 27 | import org.apache.maven.model.Dependency;
|
27 |
| -import org.apache.maven.plugin.logging.Log; |
28 | 28 | import org.apache.maven.project.MavenProject;
|
29 |
| -import org.apache.maven.shared.artifact.filter.resolve.AbstractFilter; |
30 |
| -import org.apache.maven.shared.artifact.filter.resolve.Node; |
31 |
| -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; |
| 29 | +import org.slf4j.Logger; |
| 30 | +import org.slf4j.LoggerFactory; |
32 | 31 |
|
33 | 32 | /**
|
34 |
| - * {@link TransformableFilter} implementation that excludes artifacts found in the Reactor. |
| 33 | + * Filter implementation that excludes artifacts found in the Reactor. |
35 | 34 | *
|
36 | 35 | * @author Maarten Mulders
|
37 | 36 | */
|
38 |
| -public class ExcludeReactorProjectsDependencyFilter extends AbstractFilter { |
39 |
| - private final Log log; |
| 37 | +public class ExcludeReactorProjectsDependencyFilter implements Predicate<Dependency> { |
| 38 | + private final Logger log = LoggerFactory.getLogger(ExcludeReactorProjectsDependencyFilter.class); |
40 | 39 | private final Set<String> reactorArtifactKeys;
|
41 | 40 |
|
42 |
| - public ExcludeReactorProjectsDependencyFilter(final List<MavenProject> reactorProjects, final Log log) { |
43 |
| - this.log = log; |
| 41 | + public ExcludeReactorProjectsDependencyFilter(final List<MavenProject> reactorProjects) { |
44 | 42 | this.reactorArtifactKeys = reactorProjects.stream()
|
45 | 43 | .map(project -> ArtifactUtils.key(project.getArtifact()))
|
46 | 44 | .collect(Collectors.toSet());
|
47 | 45 | }
|
48 | 46 |
|
49 | 47 | @Override
|
50 |
| - public boolean accept(final Node node, final List<Node> parents) { |
51 |
| - final Dependency dependency = node.getDependency(); |
52 |
| - if (dependency != null) { |
53 |
| - final String dependencyArtifactKey = |
54 |
| - ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); |
55 |
| - |
56 |
| - final boolean result = isDependencyArtifactInReactor(dependencyArtifactKey); |
57 |
| - |
58 |
| - if (log.isDebugEnabled() && result) { |
59 |
| - log.debug("Skipped dependency " + dependencyArtifactKey + " because it is present in the reactor"); |
| 48 | + public boolean test(Dependency dependency) { |
| 49 | + String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); |
| 50 | + if (reactorArtifactKeys.contains(key)) { |
| 51 | + if (log.isDebugEnabled()) { |
| 52 | + log.debug("Skipped dependency {} because it is present in the reactor", key); |
60 | 53 | }
|
61 |
| - |
62 |
| - return !result; |
| 54 | + return false; |
63 | 55 | }
|
64 | 56 | return true;
|
65 | 57 | }
|
66 |
| - |
67 |
| - private boolean isDependencyArtifactInReactor(final String dependencyArtifactKey) { |
68 |
| - for (final String reactorArtifactKey : this.reactorArtifactKeys) { |
69 |
| - // This check only includes GAV. Should we take a look at the types, too? |
70 |
| - if (reactorArtifactKey.equals(dependencyArtifactKey)) { |
71 |
| - return true; |
72 |
| - } |
73 |
| - } |
74 |
| - return false; |
75 |
| - } |
76 | 58 | }
|
0 commit comments