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