1 package org.codehaus.plexus.compiler.util.scan;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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 }