1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.filter;
20
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import org.eclipse.aether.graph.Dependency;
27 import org.eclipse.aether.graph.DependencyFilter;
28 import org.eclipse.aether.graph.DependencyNode;
29
30 import static java.util.Objects.requireNonNull;
31
32
33
34
35 public final class ExclusionsDependencyFilter implements DependencyFilter {
36
37 private final Set<String> excludes = new HashSet<>();
38
39
40
41
42
43
44
45 public ExclusionsDependencyFilter(Collection<String> excludes) {
46 if (excludes != null) {
47 this.excludes.addAll(excludes);
48 }
49 }
50
51 public boolean accept(DependencyNode node, List<DependencyNode> parents) {
52 requireNonNull(node, "node cannot be null");
53 requireNonNull(parents, "parents cannot be null");
54 Dependency dependency = node.getDependency();
55
56 if (dependency == null) {
57 return true;
58 }
59
60 String id = dependency.getArtifact().getArtifactId();
61
62 if (excludes.contains(id)) {
63 return false;
64 }
65
66 id = dependency.getArtifact().getGroupId() + ':' + id;
67
68 return !(excludes.contains(id));
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (this == obj) {
74 return true;
75 }
76
77 if (obj == null || !getClass().equals(obj.getClass())) {
78 return false;
79 }
80
81 ExclusionsDependencyFilter that = (ExclusionsDependencyFilter) obj;
82
83 return this.excludes.equals(that.excludes);
84 }
85
86 @Override
87 public int hashCode() {
88 int hash = 17;
89 hash = hash * 31 + excludes.hashCode();
90 return hash;
91 }
92 }