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 org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
23 import org.apache.maven.surefire.booter.ProviderConfiguration;
24 import org.apache.maven.surefire.booter.StartupConfiguration;
25 import org.apache.maven.surefire.booter.SurefireExecutionException;
26 import org.apache.maven.surefire.suite.RunResult;
27 import org.apache.maven.surefire.testset.TestSetFailedException;
28 import org.apache.maven.surefire.util.DefaultScanResult;
29
30 import javax.annotation.Nonnull;
31 import java.lang.reflect.InvocationTargetException;
32 import java.util.Map;
33
34 import static org.apache.maven.surefire.booter.ProviderFactory.invokeProvider;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class InPluginVMSurefireStarter
49 {
50 private final StartupConfiguration startupConfig;
51 private final StartupReportConfiguration startupReportConfig;
52 private final ProviderConfiguration providerConfig;
53 private final ConsoleLogger consoleLogger;
54
55 public InPluginVMSurefireStarter( @Nonnull StartupConfiguration startupConfig,
56 @Nonnull ProviderConfiguration providerConfig,
57 @Nonnull StartupReportConfiguration startupReportConfig,
58 @Nonnull ConsoleLogger consoleLogger )
59 {
60 this.startupConfig = startupConfig;
61 this.startupReportConfig = startupReportConfig;
62 this.providerConfig = providerConfig;
63 this.consoleLogger = consoleLogger;
64 }
65
66 public RunResult runSuitesInProcess( @Nonnull DefaultScanResult scanResult )
67 throws SurefireExecutionException, TestSetFailedException
68 {
69
70
71
72 Map<String, String> providerProperties = providerConfig.getProviderProperties();
73 scanResult.writeTo( providerProperties );
74
75 startupConfig.writeSurefireTestClasspathProperty();
76 ClassLoader testClassLoader = startupConfig.getClasspathConfiguration().createMergedClassLoader();
77
78 CommonReflector surefireReflector = new CommonReflector( testClassLoader );
79
80 Object factory = surefireReflector.createReportingReporterFactory( startupReportConfig, consoleLogger );
81
82 try
83 {
84 return invokeProvider( null, testClassLoader, factory, providerConfig, false, startupConfig, true );
85 }
86 catch ( InvocationTargetException e )
87 {
88 throw new SurefireExecutionException( "Exception in provider", e.getTargetException() );
89 }
90 }
91
92 }