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