1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire;
20
21 import javax.annotation.Nonnull;
22
23 import java.lang.reflect.InvocationTargetException;
24 import java.util.Map;
25
26 import org.apache.maven.plugin.surefire.booterclient.Platform;
27 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
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 import org.apache.maven.surefire.booter.ClasspathConfiguration;
32 import org.apache.maven.surefire.booter.ProviderConfiguration;
33 import org.apache.maven.surefire.booter.StartupConfiguration;
34 import org.apache.maven.surefire.booter.SurefireExecutionException;
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 private final StartupConfiguration startupConfig;
52 private final StartupReportConfiguration startupReportConfig;
53 private final ProviderConfiguration providerConfig;
54 private final ConsoleLogger consoleLogger;
55 private final Platform platform;
56
57 public InPluginVMSurefireStarter(
58 @Nonnull StartupConfiguration startupConfig,
59 @Nonnull ProviderConfiguration providerConfig,
60 @Nonnull StartupReportConfiguration startupReportConfig,
61 @Nonnull ConsoleLogger consoleLogger,
62 @Nonnull Platform platform) {
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 Map<String, String> providerProperties = providerConfig.getProviderProperties();
76 scanResult.writeTo(providerProperties);
77
78 startupConfig.writeSurefireTestClasspathProperty();
79 ClassLoader testClassLoader = startupConfig
80 .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 return platform.isShutdown()
90 ? new RunResult(0, 0, 0, 0)
91 : invokeProvider(null, testClassLoader, factory, providerConfig, false, startupConfig, true);
92 } catch (InvocationTargetException e) {
93 throw new SurefireExecutionException("Exception in provider", e.getTargetException());
94 }
95 }
96 }