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.Arrays;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.eclipse.aether.graph.Dependency;
28 import org.eclipse.aether.graph.DependencyFilter;
29 import org.eclipse.aether.graph.DependencyNode;
30
31
32
33
34
35
36
37 public final class ScopeDependencyFilter implements DependencyFilter {
38
39 private final Set<String> included = new HashSet<>();
40
41 private final Set<String> excluded = new HashSet<>();
42
43
44
45
46
47
48
49 public ScopeDependencyFilter(Collection<String> included, Collection<String> excluded) {
50 if (included != null) {
51 this.included.addAll(included);
52 }
53 if (excluded != null) {
54 this.excluded.addAll(excluded);
55 }
56 }
57
58
59
60
61
62
63 public ScopeDependencyFilter(String... excluded) {
64 if (excluded != null) {
65 this.excluded.addAll(Arrays.asList(excluded));
66 }
67 }
68
69 public boolean accept(DependencyNode node, List<DependencyNode> parents) {
70 Dependency dependency = node.getDependency();
71
72 if (dependency == null) {
73 return true;
74 }
75
76 String scope = node.getDependency().getScope();
77 return (included.isEmpty() || included.contains(scope)) && (excluded.isEmpty() || !excluded.contains(scope));
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85
86 if (obj == null || !getClass().equals(obj.getClass())) {
87 return false;
88 }
89
90 ScopeDependencyFilter that = (ScopeDependencyFilter) obj;
91
92 return this.included.equals(that.included) && this.excluded.equals(that.excluded);
93 }
94
95 @Override
96 public int hashCode() {
97 int hash = 17;
98 hash = hash * 31 + included.hashCode();
99 hash = hash * 31 + excluded.hashCode();
100 return hash;
101 }
102 }