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