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 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 if ( args.length > 1 )
55 {
56 SystemPropertyManager.setSystemProperties( new File( args[1] ) );
57 }
58
59 File surefirePropertiesFile = new File( args[0] );
60 InputStream stream = surefirePropertiesFile.exists() ? new FileInputStream( surefirePropertiesFile ) : null;
61 BooterDeserializer booterDeserializer = new BooterDeserializer( stream );
62 ProviderConfiguration providerConfiguration = booterDeserializer.deserialize();
63 final StartupConfiguration startupConfiguration = booterDeserializer.getProviderConfiguration();
64
65 TypeEncodedValue forkedTestSet = providerConfiguration.getTestForFork();
66
67 final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
68 final ClassLoader testClassLoader = classpathConfiguration.createForkingTestClassLoader(
69 startupConfiguration.isManifestOnlyJarRequestedAndUsable() );
70
71 startupConfiguration.writeSurefireTestClasspathProperty();
72
73 Object testSet = forkedTestSet != null ? forkedTestSet.getDecodedValue() : null;
74 runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration );
75
76
77 System.exit( 0 );
78 }
79 catch ( Throwable t )
80 {
81
82
83 t.printStackTrace( System.err );
84
85 System.exit( 1 );
86 }
87 }
88
89 public static RunResult runSuitesInProcess( Object testSet, ClassLoader testsClassLoader,
90 StartupConfiguration startupConfiguration,
91 ProviderConfiguration providerConfiguration )
92 throws SurefireExecutionException
93 {
94 final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
95 ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader( testsClassLoader );
96
97 SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
98
99 final Object factory = createForkingReporterFactory( surefireReflector, providerConfiguration );
100
101 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 final Boolean trimStackTrace = providerConfiguration.getReporterConfiguration().isTrimStackTrace();
109 final PrintStream originalSystemOut = providerConfiguration.getReporterConfiguration().getOriginalSystemOut();
110 return surefireReflector.createForkingReporterFactory( trimStackTrace, originalSystemOut );
111 }
112 }