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 | |
import java.io.File; |
23 | |
import java.io.FileInputStream; |
24 | |
import java.io.InputStream; |
25 | |
import java.io.PrintStream; |
26 | |
import org.apache.maven.surefire.suite.RunResult; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class ForkedBooter |
40 | |
{ |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public static void main( String[] args ) |
50 | |
throws Throwable |
51 | |
{ |
52 | |
try |
53 | |
{ |
54 | 0 | if ( args.length > 1 ) |
55 | |
{ |
56 | 0 | SystemPropertyManager.setSystemProperties( new File( args[1] ) ); |
57 | |
} |
58 | |
|
59 | 0 | File surefirePropertiesFile = new File( args[0] ); |
60 | 0 | InputStream stream = surefirePropertiesFile.exists() ? new FileInputStream( surefirePropertiesFile ) : null; |
61 | 0 | BooterDeserializer booterDeserializer = new BooterDeserializer( stream ); |
62 | 0 | ProviderConfiguration providerConfiguration = booterDeserializer.deserialize(); |
63 | 0 | final StartupConfiguration startupConfiguration = booterDeserializer.getProviderConfiguration(); |
64 | |
|
65 | 0 | TypeEncodedValue forkedTestSet = providerConfiguration.getTestForFork(); |
66 | |
|
67 | 0 | final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); |
68 | 0 | final ClassLoader testClassLoader = classpathConfiguration.createForkingTestClassLoader( |
69 | |
startupConfiguration.isManifestOnlyJarRequestedAndUsable() ); |
70 | |
|
71 | 0 | startupConfiguration.writeSurefireTestClasspathProperty(); |
72 | |
|
73 | 0 | Object testSet = forkedTestSet != null ? forkedTestSet.getDecodedValue() : null; |
74 | 0 | runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration ); |
75 | |
|
76 | |
|
77 | 0 | System.exit( 0 ); |
78 | |
} |
79 | 0 | catch ( Throwable t ) |
80 | |
{ |
81 | |
|
82 | |
|
83 | 0 | t.printStackTrace( System.err ); |
84 | |
|
85 | 0 | System.exit( 1 ); |
86 | 0 | } |
87 | 0 | } |
88 | |
|
89 | |
public static RunResult runSuitesInProcess( Object testSet, ClassLoader testsClassLoader, |
90 | |
StartupConfiguration startupConfiguration, |
91 | |
ProviderConfiguration providerConfiguration ) |
92 | |
throws SurefireExecutionException |
93 | |
{ |
94 | 0 | final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); |
95 | 0 | ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader( testsClassLoader ); |
96 | |
|
97 | 0 | SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader ); |
98 | |
|
99 | 0 | final Object factory = createForkingReporterFactory( surefireReflector, providerConfiguration ); |
100 | |
|
101 | 0 | return ProviderFactory.invokeProvider( testSet, testsClassLoader, surefireClassLoader, factory, |
102 | |
providerConfiguration, true, startupConfiguration ); |
103 | |
} |
104 | |
|
105 | |
private static Object createForkingReporterFactory( SurefireReflector surefireReflector, |
106 | |
ProviderConfiguration providerConfiguration ) |
107 | |
{ |
108 | 0 | final Boolean trimStackTrace = providerConfiguration.getReporterConfiguration().isTrimStackTrace(); |
109 | 0 | final PrintStream originalSystemOut = providerConfiguration.getReporterConfiguration().getOriginalSystemOut(); |
110 | 0 | return surefireReflector.createForkingReporterFactory( trimStackTrace, originalSystemOut ); |
111 | |
} |
112 | |
} |