1 package org.apache.maven.plugin.surefire.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.maven.plugin.surefire.util.ScannerUtil.convertSlashToSystemFileSeparator;
23 import static org.apache.maven.plugin.surefire.util.ScannerUtil.convertToJavaClassName;
24 import static org.apache.maven.plugin.surefire.util.ScannerUtil.processIncludesExcludes;
25 import static org.apache.maven.plugin.surefire.util.ScannerUtil.stripBaseDir;
26
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.apache.maven.surefire.util.DefaultScanResult;
32
33
34
35
36
37
38
39 public class DirectoryScanner
40 {
41 private final File basedir;
42
43 private final List<String> includes;
44
45 private final List<String> excludes;
46
47 private final List<String> specificTests;
48
49 public DirectoryScanner( File basedir, List<String> includes, List<String> excludes, List<String> specificTests )
50 {
51 this.basedir = basedir;
52 this.includes = includes;
53 this.excludes = excludes;
54 this.specificTests = specificTests;
55 }
56
57 public DefaultScanResult scan()
58 {
59 String[] specific = specificTests == null ? new String[0] : processIncludesExcludes( specificTests );
60 SpecificFileFilter specificTestFilter = new SpecificFileFilter( specific );
61
62 List<String> result = new ArrayList<String>();
63 if ( basedir.exists() )
64 {
65 org.apache.maven.shared.utils.io.DirectoryScanner scanner =
66 new org.apache.maven.shared.utils.io.DirectoryScanner();
67
68 scanner.setBasedir( basedir );
69
70 if ( includes != null )
71 {
72 scanner.setIncludes( processIncludesExcludes( includes ) );
73 }
74
75 if ( excludes != null )
76 {
77 scanner.setExcludes( processIncludesExcludes( excludes ) );
78 }
79
80 scanner.scan();
81 for ( String test : scanner.getIncludedFiles() )
82 {
83 if ( specificTestFilter.accept(
84 convertSlashToSystemFileSeparator(
85 stripBaseDir( basedir.getAbsolutePath(), test ) ) ) )
86 {
87 result.add( convertToJavaClassName( test ) );
88 }
89 }
90 }
91 return new DefaultScanResult( result );
92 }
93 }