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