Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SpecificTestClassFilter |
|
| 5.5;5,5 |
1 | package org.apache.maven.surefire; | |
2 | /* | |
3 | * Licensed to the Apache Software Foundation (ASF) under one | |
4 | * or more contributor license agreements. See the NOTICE file | |
5 | * distributed with this work for additional information | |
6 | * regarding copyright ownership. The ASF licenses this file | |
7 | * to you under the Apache License, Version 2.0 (the | |
8 | * "License"); you may not use this file except in compliance | |
9 | * with the License. You may obtain a copy of the License at | |
10 | * | |
11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
12 | * | |
13 | * Unless required by applicable law or agreed to in writing, | |
14 | * software distributed under the License is distributed on an | |
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
16 | * KIND, either express or implied. See the License for the | |
17 | * specific language governing permissions and limitations | |
18 | * under the License. | |
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 | 1 | 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 | 4 | { |
39 | 4 | if ( classNames != null && classNames.length > 0 ) |
40 | { | |
41 | 4 | this.names = new HashSet(); |
42 | 8 | for ( int i = 0; i < classNames.length; i++ ) |
43 | { | |
44 | 4 | String name = classNames[i]; |
45 | 4 | names.add( name ); |
46 | } | |
47 | } | |
48 | 4 | } |
49 | ||
50 | public boolean accept( Class testClass ) | |
51 | { | |
52 | // If the tests enumeration is empty, allow anything. | |
53 | 4 | boolean result = true; |
54 | ||
55 | 4 | if ( names != null && !names.isEmpty() ) |
56 | { | |
57 | 4 | String className = testClass.getName().replace( '.', FS ) + JAVA_CLASS_FILE_EXTENSION; |
58 | ||
59 | 4 | boolean found = false; |
60 | 4 | for ( Iterator it = names.iterator(); it.hasNext(); ) |
61 | { | |
62 | 4 | String pattern = (String) it.next(); |
63 | 4 | if ( '\\' == FS ) |
64 | { | |
65 | 4 | pattern = pattern.replace( '/', FS ); |
66 | } | |
67 | ||
68 | // This is the same utility used under the covers in the plexus DirectoryScanner, and | |
69 | // therefore in the surefire DefaultDirectoryScanner implementation. | |
70 | 4 | if ( SelectorUtils.matchPath( pattern, className, true ) ) |
71 | { | |
72 | 4 | found = true; |
73 | 4 | break; |
74 | } | |
75 | 0 | } |
76 | ||
77 | 4 | if ( !found ) |
78 | { | |
79 | 0 | result = false; |
80 | } | |
81 | } | |
82 | ||
83 | 4 | return result; |
84 | } | |
85 | ||
86 | } |