1 | |
package org.apache.maven.surefire.booter; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class StartupConfiguration |
28 | |
{ |
29 | |
private final String providerClassName; |
30 | |
|
31 | |
private final ClasspathConfiguration classpathConfiguration; |
32 | |
|
33 | |
private final ClassLoaderConfiguration classLoaderConfiguration; |
34 | |
|
35 | |
private final boolean isForkRequested; |
36 | |
|
37 | |
private final boolean isInForkedVm; |
38 | |
|
39 | |
private final static String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path"; |
40 | |
|
41 | |
|
42 | |
public StartupConfiguration( String providerClassName, ClasspathConfiguration classpathConfiguration, |
43 | |
ClassLoaderConfiguration classLoaderConfiguration, boolean isForkRequested, |
44 | |
boolean inForkedVm ) |
45 | 0 | { |
46 | 0 | this.classpathConfiguration = classpathConfiguration; |
47 | 0 | this.classLoaderConfiguration = classLoaderConfiguration; |
48 | 0 | this.isForkRequested = isForkRequested; |
49 | 0 | this.providerClassName = providerClassName; |
50 | 0 | isInForkedVm = inForkedVm; |
51 | 0 | } |
52 | |
|
53 | |
public boolean isProviderMainClass() |
54 | |
{ |
55 | 0 | return providerClassName.endsWith( "#main" ); |
56 | |
} |
57 | |
|
58 | |
public static StartupConfiguration inForkedVm( String providerClassName, |
59 | |
ClasspathConfiguration classpathConfiguration, |
60 | |
ClassLoaderConfiguration classLoaderConfiguration ) |
61 | |
{ |
62 | 0 | return new StartupConfiguration( providerClassName, classpathConfiguration, classLoaderConfiguration, true, |
63 | |
true ); |
64 | |
} |
65 | |
|
66 | |
public ClasspathConfiguration getClasspathConfiguration() |
67 | |
{ |
68 | 0 | return classpathConfiguration; |
69 | |
} |
70 | |
|
71 | |
public boolean useSystemClassLoader() |
72 | |
{ |
73 | |
|
74 | 0 | return classLoaderConfiguration.isUseSystemClassLoader() && ( isInForkedVm || isForkRequested ); |
75 | |
} |
76 | |
|
77 | |
public boolean isManifestOnlyJarRequestedAndUsable() |
78 | |
{ |
79 | 0 | return classLoaderConfiguration.isManifestOnlyJarRequestedAndUsable(); |
80 | |
} |
81 | |
|
82 | |
public String getProviderClassName() |
83 | |
{ |
84 | 0 | return providerClassName; |
85 | |
} |
86 | |
|
87 | |
public String getActualClassName() |
88 | |
{ |
89 | 0 | if ( isProviderMainClass() ) |
90 | |
{ |
91 | 0 | return stripEnd( providerClassName, "#main" ); |
92 | |
} |
93 | 0 | return providerClassName; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public static String stripEnd( String str, String strip ) |
107 | |
{ |
108 | 0 | if ( str == null ) |
109 | |
{ |
110 | 0 | return null; |
111 | |
} |
112 | 0 | int end = str.length(); |
113 | |
|
114 | 0 | if ( strip == null ) |
115 | |
{ |
116 | 0 | while ( ( end != 0 ) && Character.isWhitespace( str.charAt( end - 1 ) ) ) |
117 | |
{ |
118 | 0 | end--; |
119 | |
} |
120 | |
} |
121 | |
else |
122 | |
{ |
123 | 0 | while ( ( end != 0 ) && ( strip.indexOf( str.charAt( end - 1 ) ) != -1 ) ) |
124 | |
{ |
125 | 0 | end--; |
126 | |
} |
127 | |
} |
128 | 0 | return str.substring( 0, end ); |
129 | |
} |
130 | |
|
131 | |
public ClassLoaderConfiguration getClassLoaderConfiguration() |
132 | |
{ |
133 | 0 | return classLoaderConfiguration; |
134 | |
} |
135 | |
|
136 | |
public boolean isShadefire() |
137 | |
{ |
138 | 0 | return providerClassName.startsWith( "org.apache.maven.surefire.shadefire" ); |
139 | |
} |
140 | |
|
141 | |
public void writeSurefireTestClasspathProperty() |
142 | |
{ |
143 | 0 | ClasspathConfiguration classpathConfiguration = getClasspathConfiguration(); |
144 | 0 | classpathConfiguration.getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH ); |
145 | 0 | } |
146 | |
|
147 | |
} |