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