View Javadoc
1   package org.codehaus.plexus.compiler.util.scan;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.Set;
24  
25  import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
26  import org.codehaus.plexus.util.DirectoryScanner;
27  
28  /**
29   * @author jdcasey
30   */
31  public abstract class AbstractSourceInclusionScanner implements SourceInclusionScanner {
32      private final List<SourceMapping> sourceMappings = new ArrayList<>();
33  
34      public final void addSourceMapping(SourceMapping sourceMapping) {
35          sourceMappings.add(sourceMapping);
36      }
37  
38      protected final List<SourceMapping> getSourceMappings() {
39          return Collections.unmodifiableList(sourceMappings);
40      }
41  
42      protected String[] scanForSources(File sourceDir, Set<String> sourceIncludes, Set<String> sourceExcludes) {
43          DirectoryScanner ds = new DirectoryScanner();
44          ds.setFollowSymlinks(true);
45          ds.setBasedir(sourceDir);
46  
47          String[] includes;
48          if (sourceIncludes.isEmpty()) {
49              includes = new String[0];
50          } else {
51              includes = sourceIncludes.toArray(new String[0]);
52          }
53  
54          ds.setIncludes(includes);
55  
56          String[] excludes;
57          if (sourceExcludes.isEmpty()) {
58              excludes = new String[0];
59          } else {
60              excludes = sourceExcludes.toArray(new String[0]);
61          }
62  
63          ds.setExcludes(excludes);
64          ds.addDefaultExcludes();
65  
66          ds.scan();
67  
68          return ds.getIncludedFiles();
69      }
70  }