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 if (excludes.contains(id)) {
69 return false;
70 }
71
72 return true;
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80
81 if (obj == null || !getClass().equals(obj.getClass())) {
82 return false;
83 }
84
85 ExclusionsDependencyFilter that = (ExclusionsDependencyFilter) obj;
86
87 return this.excludes.equals(that.excludes);
88 }
89
90 @Override
91 public int hashCode() {
92 int hash = 17;
93 hash = hash * 31 + excludes.hashCode();
94 return hash;
95 }
96 }