1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.nuxeo.build.maven.filter;
18
19 import java.util.List;
20
21 import org.apache.maven.artifact.Artifact;
22 import org.eclipse.aether.graph.DependencyNode;
23
24
25
26
27 public class ScopeFilter extends AbstractFilter {
28
29 @Override
30 public String toString() {
31 return super.toString() + " [" + matcher + "]";
32 }
33
34 protected SegmentMatch matcher;
35
36 public ScopeFilter(String pattern) {
37 this(SegmentMatch.parse(pattern));
38 }
39
40 public ScopeFilter(SegmentMatch matcher) {
41 this.matcher = matcher;
42 }
43
44 @Override
45 public boolean accept(Artifact artifact) {
46 return result(match(artifact.getScope()), artifact.toString());
47 }
48
49 @Override
50 public boolean accept(DependencyNode node, List<DependencyNode> parents) {
51 org.eclipse.aether.graph.Dependency dependency = node.getDependency();
52 if (dependency == null) {
53 return result(matcher == SegmentMatch.ANY, node.toString());
54 }
55 return result(match(dependency.getScope()), node.toString());
56 }
57
58 private boolean match(String scope) {
59 if (scope == null) {
60 return matcher == SegmentMatch.ANY;
61 }
62 return matcher.match(scope);
63 }
64 }