View Javadoc
1   package org.apache.rat.mp.util.ignore;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }