1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.booter;
20
21 import javax.annotation.Nonnull;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Collection;
27 import java.util.List;
28
29 import org.apache.maven.surefire.api.booter.Shutdown;
30 import org.apache.maven.surefire.api.report.ReporterConfiguration;
31 import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
32 import org.apache.maven.surefire.api.testset.RunOrderParameters;
33 import org.apache.maven.surefire.api.testset.TestArtifactInfo;
34 import org.apache.maven.surefire.api.testset.TestListResolver;
35 import org.apache.maven.surefire.api.testset.TestRequest;
36
37 import static org.apache.maven.surefire.api.cli.CommandLineOption.*;
38 import static org.apache.maven.surefire.booter.BooterConstants.*;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class BooterDeserializer {
54 private final PropertiesWrapper properties;
55
56 public BooterDeserializer(InputStream inputStream) throws IOException {
57 properties = SystemPropertyManager.loadProperties(inputStream);
58 }
59
60 public int getForkNumber() {
61 return properties.getIntProperty(FORK_NUMBER);
62 }
63
64
65
66
67
68
69
70 @Nonnull
71 public String getConnectionString() {
72 return properties.getProperty(FORK_NODE_CONNECTION_STRING);
73 }
74
75
76
77
78 public String getPluginPid() {
79 return properties.getProperty(PLUGIN_PID);
80 }
81
82 public ProviderConfiguration deserialize() {
83 final File reportsDirectory = new File(properties.getProperty(REPORTSDIRECTORY));
84 final String testNgVersion = properties.getProperty(TESTARTIFACT_VERSION);
85 final String testArtifactClassifier = properties.getProperty(TESTARTIFACT_CLASSIFIER);
86
87 final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue(FORKTESTSET);
88 final boolean preferTestsFromInStream = properties.getBooleanProperty(FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM);
89
90 final String requestedTest = properties.getProperty(REQUESTEDTEST);
91 final File sourceDirectory = properties.getFileProperty(SOURCE_DIRECTORY);
92
93 final List<String> excludes = properties.getStringList(EXCLUDES_PROPERTY_PREFIX);
94 final List<String> includes = properties.getStringList(INCLUDES_PROPERTY_PREFIX);
95 final List<String> specificTests = properties.getStringList(SPECIFIC_TEST_PROPERTY_PREFIX);
96
97 final File testClassesDirectory = properties.getFileProperty(TEST_CLASSES_DIRECTORY);
98 final String runOrder = properties.getProperty(RUN_ORDER);
99 final Long runOrderRandomSeed = properties.getLongProperty(RUN_ORDER_RANDOM_SEED);
100 final String runStatisticsFile = properties.getProperty(RUN_STATISTICS_FILE);
101
102 final int rerunFailingTestsCount = properties.getIntProperty(RERUN_FAILING_TESTS_COUNT);
103
104 DirectoryScannerParameters dirScannerParams =
105 new DirectoryScannerParameters(testClassesDirectory, includes, excludes, specificTests, runOrder);
106
107 RunOrderParameters runOrderParameters = new RunOrderParameters(
108 runOrder, runStatisticsFile == null ? null : new File(runStatisticsFile), runOrderRandomSeed);
109
110 TestArtifactInfo testNg = new TestArtifactInfo(testNgVersion, testArtifactClassifier);
111 TestRequest testSuiteDefinition =
112 new TestRequest(sourceDirectory, new TestListResolver(requestedTest), rerunFailingTestsCount);
113
114 ReporterConfiguration reporterConfiguration =
115 new ReporterConfiguration(reportsDirectory, properties.getBooleanProperty(ISTRIMSTACKTRACE));
116
117 Collection<String> cli = properties.getStringList(MAIN_CLI_OPTIONS);
118
119 int failFastCount = properties.getIntProperty(FAIL_FAST_COUNT);
120
121 Shutdown shutdown = Shutdown.valueOf(properties.getProperty(SHUTDOWN));
122
123 String systemExitTimeoutAsString = properties.getProperty(SYSTEM_EXIT_TIMEOUT);
124 Integer systemExitTimeout =
125 systemExitTimeoutAsString == null ? null : Integer.valueOf(systemExitTimeoutAsString);
126
127 return new ProviderConfiguration(
128 dirScannerParams,
129 runOrderParameters,
130 reporterConfiguration,
131 testNg,
132 testSuiteDefinition,
133 properties.getProperties(),
134 typeEncodedTestForFork,
135 preferTestsFromInStream,
136 fromStrings(cli),
137 failFastCount,
138 shutdown,
139 systemExitTimeout);
140 }
141
142 public StartupConfiguration getStartupConfiguration() {
143 boolean useSystemClassLoader = properties.getBooleanProperty(USESYSTEMCLASSLOADER);
144 boolean useManifestOnlyJar = properties.getBooleanProperty(USEMANIFESTONLYJAR);
145 String providerConfiguration = properties.getProperty(PROVIDER_CONFIGURATION);
146
147 ClassLoaderConfiguration classLoaderConfiguration =
148 new ClassLoaderConfiguration(useSystemClassLoader, useManifestOnlyJar);
149
150 ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration(properties);
151
152 String processChecker = properties.getProperty(PROCESS_CHECKER);
153 ProcessCheckerType processCheckerType = ProcessCheckerType.toEnum(processChecker);
154
155 return StartupConfiguration.inForkedVm(
156 providerConfiguration, classpathConfiguration,
157 classLoaderConfiguration, processCheckerType);
158 }
159 }