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 java.util.ArrayList; |
23 | |
import java.util.Collections; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import org.apache.commons.lang3.StringUtils; |
27 | |
|
28 | |
import javax.annotation.Nonnull; |
29 | |
|
30 | |
final class ScannerUtil { |
31 | |
|
32 | 0 | private ScannerUtil() {} |
33 | |
|
34 | 1 | private static final String FS = System.getProperty( "file.separator" ); |
35 | |
|
36 | |
private static final String JAVA_SOURCE_FILE_EXTENSION = ".java"; |
37 | |
|
38 | |
private static final String JAVA_CLASS_FILE_EXTENSION = ".class"; |
39 | |
|
40 | 1 | private static final boolean IS_NON_UNIX_FS = (!FS.equals( "/" )); |
41 | |
|
42 | |
public static @Nonnull String convertToJavaClassName( @Nonnull String test ) |
43 | |
{ |
44 | 3 | return StringUtils.removeEnd( test, ".class" ).replace( FS, "." ); |
45 | |
} |
46 | |
|
47 | |
public static @Nonnull String convertJarFileResourceToJavaClassName( @Nonnull String test ) |
48 | |
{ |
49 | 1 | return StringUtils.removeEnd( test, ".class" ).replace( "/", "." ); |
50 | |
} |
51 | |
|
52 | |
public static @Nonnull String convertSlashToSystemFileSeparator( @Nonnull String path ) |
53 | |
{ |
54 | 15 | return ( IS_NON_UNIX_FS ? path.replace( "/", FS ) : path ); |
55 | |
} |
56 | |
|
57 | |
public static @Nonnull String stripBaseDir( String basedir, String test ) |
58 | |
{ |
59 | 3 | return StringUtils.removeStart( test, basedir ); |
60 | |
} |
61 | |
|
62 | |
public static @Nonnull String[] processIncludesExcludes( @Nonnull List<String> list ) |
63 | |
{ |
64 | 6 | List<String> newList = new ArrayList<String>(); |
65 | 6 | for ( Object aList : list ) |
66 | |
{ |
67 | 2 | String include = (String) aList; |
68 | 2 | String[] includes = include.split( "," ); |
69 | 2 | Collections.addAll( newList, includes ); |
70 | 2 | } |
71 | |
|
72 | 6 | String[] incs = new String[newList.size()]; |
73 | |
|
74 | 8 | for ( int i = 0; i < incs.length; i++ ) |
75 | |
{ |
76 | 2 | String inc = newList.get( i ); |
77 | 2 | if ( inc.endsWith( JAVA_SOURCE_FILE_EXTENSION ) ) |
78 | |
{ |
79 | 2 | inc = StringUtils.removeEnd( inc, JAVA_SOURCE_FILE_EXTENSION ) + JAVA_CLASS_FILE_EXTENSION; |
80 | |
} |
81 | 2 | incs[i] = convertSlashToSystemFileSeparator( inc ); |
82 | |
|
83 | |
} |
84 | 6 | return incs; |
85 | |
} |
86 | |
} |