1 | |
package org.apache.maven.plugin.surefire.booterclient; |
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.util.Properties; |
25 | |
import org.apache.maven.surefire.booter.BooterConstants; |
26 | |
import org.apache.maven.surefire.booter.ClassLoaderConfiguration; |
27 | |
import org.apache.maven.surefire.booter.KeyValueSource; |
28 | |
import org.apache.maven.surefire.booter.PropertiesWrapper; |
29 | |
import org.apache.maven.surefire.booter.ProviderConfiguration; |
30 | |
import org.apache.maven.surefire.booter.StartupConfiguration; |
31 | |
import org.apache.maven.surefire.booter.SystemPropertyManager; |
32 | |
import org.apache.maven.surefire.report.ReporterConfiguration; |
33 | |
import org.apache.maven.surefire.testset.DirectoryScannerParameters; |
34 | |
import org.apache.maven.surefire.testset.RunOrderParameters; |
35 | |
import org.apache.maven.surefire.testset.TestArtifactInfo; |
36 | |
import org.apache.maven.surefire.testset.TestRequest; |
37 | |
import org.apache.maven.surefire.util.RunOrder; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
class BooterSerializer |
55 | |
{ |
56 | |
private final ForkConfiguration forkConfiguration; |
57 | |
|
58 | |
public BooterSerializer( ForkConfiguration forkConfiguration ) |
59 | 12 | { |
60 | 12 | this.forkConfiguration = forkConfiguration; |
61 | 12 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public File serialize( KeyValueSource sourceProperties, ProviderConfiguration booterConfiguration, |
68 | |
StartupConfiguration providerConfiguration, Object testSet, boolean readTestsFromInStream ) |
69 | |
throws IOException |
70 | |
{ |
71 | |
|
72 | 12 | PropertiesWrapper properties = new PropertiesWrapper( new Properties() ); |
73 | 12 | sourceProperties.copyTo( properties.getProperties() ); |
74 | |
|
75 | 12 | providerConfiguration.getClasspathConfiguration().addForkProperties( properties ); |
76 | |
|
77 | 12 | TestArtifactInfo testNg = booterConfiguration.getTestArtifact(); |
78 | 12 | if ( testNg != null ) |
79 | |
{ |
80 | 12 | properties.setProperty( BooterConstants.TESTARTIFACT_VERSION, testNg.getVersion() ); |
81 | 12 | properties.setProperty( BooterConstants.TESTARTIFACT_CLASSIFIER, testNg.getClassifier() ); |
82 | |
} |
83 | |
|
84 | 12 | properties.setProperty( BooterConstants.FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM, |
85 | |
Boolean.valueOf( readTestsFromInStream ) ); |
86 | 12 | properties.setProperty( BooterConstants.FORKTESTSET, getTypeEncoded( testSet ) ); |
87 | |
|
88 | 12 | TestRequest testSuiteDefinition = booterConfiguration.getTestSuiteDefinition(); |
89 | 12 | if ( testSuiteDefinition != null ) |
90 | |
{ |
91 | 12 | properties.setProperty( BooterConstants.SOURCE_DIRECTORY, testSuiteDefinition.getTestSourceDirectory() ); |
92 | 12 | properties.addList( testSuiteDefinition.getSuiteXmlFiles(), BooterConstants.TEST_SUITE_XML_FILES ); |
93 | 12 | properties.setProperty( BooterConstants.REQUESTEDTEST, testSuiteDefinition.getRequestedTest() ); |
94 | 12 | properties.setProperty( BooterConstants.REQUESTEDTESTMETHOD, testSuiteDefinition.getRequestedTestMethod() ); |
95 | |
} |
96 | |
|
97 | 12 | DirectoryScannerParameters directoryScannerParameters = booterConfiguration.getDirScannerParams(); |
98 | 12 | if ( directoryScannerParameters != null ) |
99 | |
{ |
100 | 12 | properties.setProperty( BooterConstants.FAILIFNOTESTS, |
101 | |
String.valueOf( directoryScannerParameters.isFailIfNoTests() ) ); |
102 | 12 | properties.addList( directoryScannerParameters.getIncludes(), BooterConstants.INCLUDES_PROPERTY_PREFIX ); |
103 | 12 | properties.addList( directoryScannerParameters.getExcludes(), BooterConstants.EXCLUDES_PROPERTY_PREFIX ); |
104 | 12 | properties.addList( directoryScannerParameters.getSpecificTests(), |
105 | |
BooterConstants.SPECIFIC_TEST_PROPERTY_PREFIX ); |
106 | |
|
107 | 12 | properties.setProperty( BooterConstants.TEST_CLASSES_DIRECTORY, |
108 | |
directoryScannerParameters.getTestClassesDirectory() ); |
109 | |
} |
110 | |
|
111 | 12 | final RunOrderParameters runOrderParameters = booterConfiguration.getRunOrderParameters(); |
112 | 12 | if ( runOrderParameters != null ) |
113 | |
{ |
114 | 12 | properties.setProperty( BooterConstants.RUN_ORDER, RunOrder.asString( runOrderParameters.getRunOrder() ) ); |
115 | 12 | properties.setProperty( BooterConstants.RUN_STATISTICS_FILE, runOrderParameters.getRunStatisticsFile() ); |
116 | |
} |
117 | |
|
118 | 12 | ReporterConfiguration reporterConfiguration = booterConfiguration.getReporterConfiguration(); |
119 | |
|
120 | 12 | Boolean rep = reporterConfiguration.isTrimStackTrace(); |
121 | 12 | properties.setProperty( BooterConstants.ISTRIMSTACKTRACE, rep ); |
122 | 12 | properties.setProperty( BooterConstants.REPORTSDIRECTORY, reporterConfiguration.getReportsDirectory() ); |
123 | 12 | ClassLoaderConfiguration classLoaderConfiguration = providerConfiguration.getClassLoaderConfiguration(); |
124 | 12 | properties.setProperty( BooterConstants.USESYSTEMCLASSLOADER, |
125 | |
String.valueOf( classLoaderConfiguration.isUseSystemClassLoader() ) ); |
126 | 12 | properties.setProperty( BooterConstants.USEMANIFESTONLYJAR, |
127 | |
String.valueOf( classLoaderConfiguration.isUseManifestOnlyJar() ) ); |
128 | 12 | properties.setProperty( BooterConstants.FAILIFNOTESTS, |
129 | |
String.valueOf( booterConfiguration.isFailIfNoTests() ) ); |
130 | 12 | properties.setProperty( BooterConstants.PROVIDER_CONFIGURATION, providerConfiguration.getProviderClassName() ); |
131 | |
|
132 | 12 | return SystemPropertyManager.writePropertiesFile( properties.getProperties(), |
133 | |
forkConfiguration.getTempDirectory(), "surefire", |
134 | |
forkConfiguration.isDebug() ); |
135 | |
} |
136 | |
|
137 | |
|
138 | |
private String getTypeEncoded( Object value ) |
139 | |
{ |
140 | 12 | if ( value == null ) |
141 | |
{ |
142 | 1 | return null; |
143 | |
} |
144 | |
String valueToUse; |
145 | 11 | if ( value instanceof Class ) |
146 | |
{ |
147 | 0 | valueToUse = ( (Class<?>) value ).getName(); |
148 | |
} |
149 | |
else |
150 | |
{ |
151 | 11 | valueToUse = value.toString(); |
152 | |
} |
153 | 11 | return value.getClass().getName() + "|" + valueToUse; |
154 | |
} |
155 | |
|
156 | |
} |