1 package org.apache.maven.surefire;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Set;
24 import org.apache.maven.shared.utils.io.SelectorUtils;
25 import org.apache.maven.surefire.util.ScannerFilter;
26
27 public class SpecificTestClassFilter
28 implements ScannerFilter
29 {
30
31 private static final char FS = System.getProperty( "file.separator" ).charAt( 0 );
32
33 private static final String JAVA_CLASS_FILE_EXTENSION = ".class";
34
35 private Set<String> names;
36
37 public SpecificTestClassFilter( String[] classNames )
38 {
39 if ( classNames != null && classNames.length > 0 )
40 {
41 this.names = new HashSet<String>();
42 Collections.addAll( names, classNames );
43 }
44 }
45
46 public boolean accept( Class testClass )
47 {
48
49 boolean result = true;
50
51 if ( names != null && !names.isEmpty() )
52 {
53 String className = testClass.getName().replace( '.', FS ) + JAVA_CLASS_FILE_EXTENSION;
54
55 boolean found = false;
56 for ( String pattern : names )
57 {
58 if ( '\\' == FS )
59 {
60 pattern = pattern.replace( '/', FS );
61 }
62
63
64
65 if ( SelectorUtils.matchPath( pattern, className, true ) )
66 {
67 found = true;
68 break;
69 }
70 }
71
72 if ( !found )
73 {
74 result = false;
75 }
76 }
77
78 return result;
79 }
80
81 }