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.HashSet;
22 import java.util.Iterator;
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 names;
36
37 public SpecificTestClassFilter( String[] classNames )
38 {
39 if ( classNames != null && classNames.length > 0 )
40 {
41 this.names = new HashSet();
42 for ( int i = 0; i < classNames.length; i++ )
43 {
44 String name = classNames[i];
45 names.add( name );
46 }
47 }
48 }
49
50 public boolean accept( Class testClass )
51 {
52
53 boolean result = true;
54
55 if ( names != null && !names.isEmpty() )
56 {
57 String className = testClass.getName().replace( '.', FS ) + JAVA_CLASS_FILE_EXTENSION;
58
59 boolean found = false;
60 for ( Iterator it = names.iterator(); it.hasNext(); )
61 {
62 String pattern = (String) it.next();
63 if ( '\\' == FS )
64 {
65 pattern = pattern.replace( '/', FS );
66 }
67
68
69
70 if ( SelectorUtils.matchPath( pattern, className, true ) )
71 {
72 found = true;
73 break;
74 }
75 }
76
77 if ( !found )
78 {
79 result = false;
80 }
81 }
82
83 return result;
84 }
85
86 }