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