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