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