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
66
67
68
69
70
71 @Nonnull
72 public String getConnectionString()
73 {
74 return properties.getProperty( FORK_NODE_CONNECTION_STRING );
75 }
76
77
78
79
80 public String getPluginPid()
81 {
82 return properties.getProperty( PLUGIN_PID );
83 }
84
85 public ProviderConfiguration deserialize()
86 {
87 final File reportsDirectory = new File( properties.getProperty( REPORTSDIRECTORY ) );
88 final String testNgVersion = properties.getProperty( TESTARTIFACT_VERSION );
89 final String testArtifactClassifier = properties.getProperty( TESTARTIFACT_CLASSIFIER );
90
91 final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue( FORKTESTSET );
92 final boolean preferTestsFromInStream =
93 properties.getBooleanProperty( FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM );
94
95 final String requestedTest = properties.getProperty( REQUESTEDTEST );
96 final File sourceDirectory = properties.getFileProperty( SOURCE_DIRECTORY );
97
98 final List<String> excludes = properties.getStringList( EXCLUDES_PROPERTY_PREFIX );
99 final List<String> includes = properties.getStringList( INCLUDES_PROPERTY_PREFIX );
100 final List<String> specificTests = properties.getStringList( SPECIFIC_TEST_PROPERTY_PREFIX );
101
102 final List<String> testSuiteXmlFiles = properties.getStringList( TEST_SUITE_XML_FILES );
103 final File testClassesDirectory = properties.getFileProperty( TEST_CLASSES_DIRECTORY );
104 final String runOrder = properties.getProperty( RUN_ORDER );
105 final String runStatisticsFile = properties.getProperty( RUN_STATISTICS_FILE );
106
107 final int rerunFailingTestsCount = properties.getIntProperty( RERUN_FAILING_TESTS_COUNT );
108
109 DirectoryScannerParameters dirScannerParams =
110 new DirectoryScannerParameters( testClassesDirectory, includes, excludes, specificTests,
111 properties.getBooleanProperty( FAILIFNOTESTS ), runOrder );
112
113 RunOrderParameters runOrderParameters
114 = new RunOrderParameters( runOrder, runStatisticsFile == null ? null : new File( runStatisticsFile ) );
115
116 TestArtifactInfo testNg = new TestArtifactInfo( testNgVersion, testArtifactClassifier );
117 TestRequest testSuiteDefinition =
118 new TestRequest( testSuiteXmlFiles, sourceDirectory, new TestListResolver( requestedTest ),
119 rerunFailingTestsCount );
120
121 ReporterConfiguration reporterConfiguration =
122 new ReporterConfiguration( reportsDirectory, properties.getBooleanProperty( ISTRIMSTACKTRACE ) );
123
124 Collection<String> cli = properties.getStringList( MAIN_CLI_OPTIONS );
125
126 int failFastCount = properties.getIntProperty( FAIL_FAST_COUNT );
127
128 Shutdown shutdown = Shutdown.valueOf( properties.getProperty( SHUTDOWN ) );
129
130 String systemExitTimeoutAsString = properties.getProperty( SYSTEM_EXIT_TIMEOUT );
131 Integer systemExitTimeout =
132 systemExitTimeoutAsString == null ? null : Integer.valueOf( systemExitTimeoutAsString );
133
134 return new ProviderConfiguration( dirScannerParams, runOrderParameters,
135 properties.getBooleanProperty( FAILIFNOTESTS ), reporterConfiguration, testNg,
136 testSuiteDefinition, properties.getProperties(), typeEncodedTestForFork,
137 preferTestsFromInStream, fromStrings( cli ), failFastCount, shutdown,
138 systemExitTimeout );
139 }
140
141 public StartupConfiguration getStartupConfiguration()
142 {
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( providerConfiguration, classpathConfiguration,
156 classLoaderConfiguration, processCheckerType );
157 }
158 }