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