1 | |
package org.apache.maven.plugin.surefire; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.lang.reflect.InvocationTargetException; |
23 | |
import java.util.Properties; |
24 | |
import org.apache.maven.surefire.booter.ProviderConfiguration; |
25 | |
import org.apache.maven.surefire.booter.ProviderFactory; |
26 | |
import org.apache.maven.surefire.booter.StartupConfiguration; |
27 | |
import org.apache.maven.surefire.booter.SurefireExecutionException; |
28 | |
import org.apache.maven.surefire.suite.RunResult; |
29 | |
import org.apache.maven.surefire.testset.TestSetFailedException; |
30 | |
import org.apache.maven.surefire.util.DefaultScanResult; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class InPluginVMSurefireStarter |
45 | |
{ |
46 | |
|
47 | |
private final StartupConfiguration startupConfiguration; |
48 | |
|
49 | |
private final StartupReportConfiguration startupReportConfiguration; |
50 | |
|
51 | |
private final ProviderConfiguration providerConfiguration; |
52 | |
|
53 | |
public InPluginVMSurefireStarter( StartupConfiguration startupConfiguration, |
54 | |
ProviderConfiguration providerConfiguration, |
55 | |
StartupReportConfiguration startupReportConfiguration ) |
56 | 0 | { |
57 | 0 | this.startupConfiguration = startupConfiguration; |
58 | 0 | this.startupReportConfiguration = startupReportConfiguration; |
59 | 0 | this.providerConfiguration = providerConfiguration; |
60 | 0 | } |
61 | |
|
62 | |
public RunResult runSuitesInProcess( DefaultScanResult scanResult ) |
63 | |
throws SurefireExecutionException, TestSetFailedException |
64 | |
{ |
65 | |
|
66 | |
|
67 | |
|
68 | 0 | Properties providerProperties = providerConfiguration.getProviderProperties(); |
69 | 0 | scanResult.writeTo( providerProperties ); |
70 | |
|
71 | 0 | startupConfiguration.writeSurefireTestClasspathProperty(); |
72 | 0 | ClassLoader testsClassLoader = startupConfiguration.getClasspathConfiguration().createTestClassLoader(); |
73 | |
|
74 | 0 | ClassLoader surefireClassLoader = |
75 | |
startupConfiguration.getClasspathConfiguration().createInprocSurefireClassLoader( testsClassLoader ); |
76 | |
|
77 | 0 | CommonReflector surefireReflector = new CommonReflector( surefireClassLoader ); |
78 | |
|
79 | 0 | final Object factory = surefireReflector.createReportingReporterFactory( startupReportConfiguration ); |
80 | |
|
81 | |
try |
82 | |
{ |
83 | 0 | return ProviderFactory.invokeProvider( null, testsClassLoader, surefireClassLoader, factory, |
84 | |
providerConfiguration, false, startupConfiguration, true ); |
85 | |
} |
86 | 0 | catch ( InvocationTargetException e ) |
87 | |
{ |
88 | 0 | throw new SurefireExecutionException( "Exception in provider", e.getTargetException() ); |
89 | |
} |
90 | |
} |
91 | |
|
92 | |
} |