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
54
55 private final PropertiesWrapper properties;
56
57 public BooterDeserializer( InputStream inputStream )
58 throws IOException
59 {
60 properties = SystemPropertyManager.loadProperties( inputStream );
61 }
62
63 public ProviderConfiguration deserialize()
64 {
65 final File reportsDirectory = new File( properties.getProperty( REPORTSDIRECTORY ) );
66 final String testNgVersion = properties.getProperty( TESTARTIFACT_VERSION );
67 final String testArtifactClassifier = properties.getProperty( TESTARTIFACT_CLASSIFIER );
68
69 final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue( FORKTESTSET );
70 final boolean preferTestsFromInStream =
71 properties.getBooleanProperty( FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM );
72
73 final String requestedTest = properties.getProperty( REQUESTEDTEST );
74 final File sourceDirectory = properties.getFileProperty( SOURCE_DIRECTORY );
75
76 final List<String> excludes = properties.getStringList( EXCLUDES_PROPERTY_PREFIX );
77 final List<String> includes = properties.getStringList( INCLUDES_PROPERTY_PREFIX );
78 final List<String> specificTests = properties.getStringList( SPECIFIC_TEST_PROPERTY_PREFIX );
79
80 final List<String> testSuiteXmlFiles = properties.getStringList( TEST_SUITE_XML_FILES );
81 final File testClassesDirectory = properties.getFileProperty( TEST_CLASSES_DIRECTORY );
82 final String runOrder = properties.getProperty( RUN_ORDER );
83 final String runStatisticsFile = properties.getProperty( RUN_STATISTICS_FILE );
84
85 final int rerunFailingTestsCount = properties.getIntProperty( RERUN_FAILING_TESTS_COUNT );
86
87 DirectoryScannerParameters dirScannerParams =
88 new DirectoryScannerParameters( testClassesDirectory, includes, excludes, specificTests,
89 properties.getBooleanProperty( FAILIFNOTESTS ), runOrder );
90
91 RunOrderParameters runOrderParameters = new RunOrderParameters( runOrder, runStatisticsFile );
92
93 TestArtifactInfo testNg = new TestArtifactInfo( testNgVersion, testArtifactClassifier );
94 TestRequest testSuiteDefinition =
95 new TestRequest( testSuiteXmlFiles, sourceDirectory, new TestListResolver( requestedTest ),
96 rerunFailingTestsCount );
97
98 ReporterConfiguration reporterConfiguration =
99 new ReporterConfiguration( reportsDirectory, properties.getBooleanProperty( ISTRIMSTACKTRACE ) );
100
101 Collection<String> cli = properties.getStringList( MAIN_CLI_OPTIONS );
102
103 int failFastCount = properties.getIntProperty( FAIL_FAST_COUNT );
104
105 Shutdown shutdown = Shutdown.valueOf( properties.getProperty( SHUTDOWN ) );
106
107 return new ProviderConfiguration( dirScannerParams, runOrderParameters,
108 properties.getBooleanProperty( FAILIFNOTESTS ), reporterConfiguration, testNg,
109 testSuiteDefinition, properties.getProperties(), typeEncodedTestForFork,
110 preferTestsFromInStream, fromStrings( cli ), failFastCount, shutdown );
111 }
112
113 public StartupConfiguration getProviderConfiguration()
114 {
115 boolean useSystemClassLoader = properties.getBooleanProperty( USESYSTEMCLASSLOADER );
116 boolean useManifestOnlyJar = properties.getBooleanProperty( USEMANIFESTONLYJAR );
117 String providerConfiguration = properties.getProperty( PROVIDER_CONFIGURATION );
118
119 ClassLoaderConfiguration classLoaderConfiguration =
120 new ClassLoaderConfiguration( useSystemClassLoader, useManifestOnlyJar );
121
122 ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( properties );
123
124 return StartupConfiguration.inForkedVm( providerConfiguration, classpathConfiguration,
125 classLoaderConfiguration );
126 }
127 }