1 package org.apache.rat.mp.util.ignore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.util.DirectoryScanner;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import static java.lang.Boolean.FALSE;
28 import static java.lang.Boolean.TRUE;
29
30 public class IgnoringDirectoryScanner extends DirectoryScanner {
31
32 public IgnoringDirectoryScanner() {
33 super();
34 }
35
36 List<IgnoreMatcher> ignoreMatcherList = new ArrayList<>();
37
38 public void addIgnoreMatcher(IgnoreMatcher ignoreMatcher) {
39 ignoreMatcherList.add(ignoreMatcher);
40 }
41
42 private boolean matchesAnIgnoreMatcher(String name) {
43 for (IgnoreMatcher ignoreMatcher : ignoreMatcherList) {
44 if (ignoreMatcher.isIgnoredFile(name).orElse(FALSE) == TRUE) {
45 return true;
46 }
47 }
48 return false;
49 }
50
51 @Override
52 protected boolean isExcluded(String name) {
53 if (matchesAnIgnoreMatcher(name)) {
54 return true;
55 }
56 return super.isExcluded(name);
57 }
58
59 @Override
60 protected boolean isExcluded(String name, String[] tokenizedName) {
61 if (matchesAnIgnoreMatcher(name)) {
62 return true;
63 }
64 return super.isExcluded(name, tokenizedName);
65 }
66
67 @Override
68 protected boolean isExcluded(String name, char[][] tokenizedName) {
69 if (matchesAnIgnoreMatcher(name)) {
70 return true;
71 }
72 return super.isExcluded(name, tokenizedName);
73 }
74 }