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 import org.apache.maven.surefire.report.ReporterConfiguration;
28 import org.apache.maven.surefire.testset.DirectoryScannerParameters;
29 import org.apache.maven.surefire.testset.RunOrderParameters;
30 import org.apache.maven.surefire.testset.TestArtifactInfo;
31 import org.apache.maven.surefire.testset.TestListResolver;
32 import org.apache.maven.surefire.testset.TestRequest;
33
34
35 import static org.apache.maven.surefire.booter.BooterConstants.*;
36 import static org.apache.maven.surefire.cli.CommandLineOption.*;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class BooterDeserializer
52 {
53 private final PropertiesWrapper properties;
54
55 public BooterDeserializer( InputStream inputStream )
56 throws IOException
57 {
58 properties = SystemPropertyManager.loadProperties( inputStream );
59 }
60
61
62
63
64 public Long getPluginPid()
65 {
66 return properties.getLongProperty( PLUGIN_PID );
67 }
68
69 public ProviderConfiguration deserialize()
70 {
71 final File reportsDirectory = new File( properties.getProperty( REPORTSDIRECTORY ) );
72 final String testNgVersion = properties.getProperty( TESTARTIFACT_VERSION );
73 final String testArtifactClassifier = properties.getProperty( TESTARTIFACT_CLASSIFIER );
74
75 final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue( FORKTESTSET );
76 final boolean preferTestsFromInStream =
77 properties.getBooleanProperty( FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM );
78
79 final String requestedTest = properties.getProperty( REQUESTEDTEST );
80 final File sourceDirectory = properties.getFileProperty( SOURCE_DIRECTORY );
81
82 final List<String> excludes = properties.getStringList( EXCLUDES_PROPERTY_PREFIX );
83 final List<String> includes = properties.getStringList( INCLUDES_PROPERTY_PREFIX );
84 final List<String> specificTests = properties.getStringList( SPECIFIC_TEST_PROPERTY_PREFIX );
85
86 final List<String> testSuiteXmlFiles = properties.getStringList( TEST_SUITE_XML_FILES );
87 final File testClassesDirectory = properties.getFileProperty( TEST_CLASSES_DIRECTORY );
88 final String runOrder = properties.getProperty( RUN_ORDER );
89 final String runStatisticsFile = properties.getProperty( RUN_STATISTICS_FILE );
90
91 final int rerunFailingTestsCount = properties.getIntProperty( RERUN_FAILING_TESTS_COUNT );
92
93 DirectoryScannerParameters dirScannerParams =
94 new DirectoryScannerParameters( testClassesDirectory, includes, excludes, specificTests,
95 properties.getBooleanProperty( FAILIFNOTESTS ), runOrder );
96
97 RunOrderParameters runOrderParameters
98 = new RunOrderParameters( runOrder, runStatisticsFile == null ? null : new File( runStatisticsFile ) );
99
100 TestArtifactInfo testNg = new TestArtifactInfo( testNgVersion, testArtifactClassifier );
101 TestRequest testSuiteDefinition =
102 new TestRequest( testSuiteXmlFiles, sourceDirectory, new TestListResolver( requestedTest ),
103 rerunFailingTestsCount );
104
105 ReporterConfiguration reporterConfiguration =
106 new ReporterConfiguration( reportsDirectory, properties.getBooleanProperty( ISTRIMSTACKTRACE ) );
107
108 Collection<String> cli = properties.getStringList( MAIN_CLI_OPTIONS );
109
110 int failFastCount = properties.getIntProperty( FAIL_FAST_COUNT );
111
112 Shutdown shutdown = Shutdown.valueOf( properties.getProperty( SHUTDOWN ) );
113
114 String systemExitTimeoutAsString = properties.getProperty( SYSTEM_EXIT_TIMEOUT );
115 Integer systemExitTimeout =
116 systemExitTimeoutAsString == null ? null : Integer.valueOf( systemExitTimeoutAsString );
117
118 return new ProviderConfiguration( dirScannerParams, runOrderParameters,
119 properties.getBooleanProperty( FAILIFNOTESTS ), reporterConfiguration, testNg,
120 testSuiteDefinition, properties.getProperties(), typeEncodedTestForFork,
121 preferTestsFromInStream, fromStrings( cli ), failFastCount, shutdown,
122 systemExitTimeout );
123 }
124
125 public StartupConfiguration getProviderConfiguration()
126 {
127 boolean useSystemClassLoader = properties.getBooleanProperty( USESYSTEMCLASSLOADER );
128 boolean useManifestOnlyJar = properties.getBooleanProperty( USEMANIFESTONLYJAR );
129 String providerConfiguration = properties.getProperty( PROVIDER_CONFIGURATION );
130
131 ClassLoaderConfiguration classLoaderConfiguration =
132 new ClassLoaderConfiguration( useSystemClassLoader, useManifestOnlyJar );
133
134 ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( properties );
135
136 return StartupConfiguration.inForkedVm( providerConfiguration, classpathConfiguration,
137 classLoaderConfiguration );
138 }
139 }