1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.booter;
20
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.maven.surefire.api.cli.CommandLineOption;
26 import org.apache.maven.surefire.api.provider.CommandChainReader;
27 import org.apache.maven.surefire.api.provider.ProviderParameters;
28 import org.apache.maven.surefire.api.report.ReporterConfiguration;
29 import org.apache.maven.surefire.api.report.ReporterFactory;
30 import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
31 import org.apache.maven.surefire.api.testset.RunOrderParameters;
32 import org.apache.maven.surefire.api.testset.TestArtifactInfo;
33 import org.apache.maven.surefire.api.testset.TestRequest;
34 import org.apache.maven.surefire.api.util.DefaultDirectoryScanner;
35 import org.apache.maven.surefire.api.util.DefaultRunOrderCalculator;
36 import org.apache.maven.surefire.api.util.DefaultScanResult;
37 import org.apache.maven.surefire.api.util.DirectoryScanner;
38 import org.apache.maven.surefire.api.util.RunOrderCalculator;
39 import org.apache.maven.surefire.api.util.ScanResult;
40
41 import static java.util.Collections.emptyList;
42
43
44
45
46 public class BaseProviderFactory implements ProviderParameters {
47 private final boolean insideFork;
48
49 private ReporterFactory reporterFactory;
50
51 private List<CommandLineOption> mainCliOptions = emptyList();
52
53 private Map<String, String> providerProperties;
54
55 private DirectoryScannerParameters directoryScannerParameters;
56
57 private ReporterConfiguration reporterConfiguration;
58
59 private RunOrderParameters runOrderParameters;
60
61 private ClassLoader testClassLoader;
62
63 private TestRequest testRequest;
64
65 private TestArtifactInfo testArtifactInfo;
66
67 private int skipAfterFailureCount;
68
69 private Integer systemExitTimeout;
70
71 private CommandChainReader commandReader;
72
73 public BaseProviderFactory(boolean insideFork) {
74 this.insideFork = insideFork;
75 }
76
77 @Override
78 public CommandChainReader getCommandReader() {
79 return commandReader;
80 }
81
82 public void setCommandReader(CommandChainReader commandReader) {
83 this.commandReader = commandReader;
84 }
85
86 @Override
87 @Deprecated
88 public DirectoryScanner getDirectoryScanner() {
89 return directoryScannerParameters == null
90 ? null
91 : new DefaultDirectoryScanner(
92 directoryScannerParameters.getTestClassesDirectory(),
93 directoryScannerParameters.getIncludes(),
94 directoryScannerParameters.getExcludes(),
95 directoryScannerParameters.getSpecificTests());
96 }
97
98 @Override
99 public ScanResult getScanResult() {
100 return DefaultScanResult.from(providerProperties);
101 }
102
103 private int getThreadCount() {
104 final String threadcount = providerProperties.get(ProviderParameterNames.THREADCOUNT_PROP);
105 return threadcount == null ? 1 : Math.max(Integer.parseInt(threadcount), 1);
106 }
107
108 @Override
109 public RunOrderCalculator getRunOrderCalculator() {
110 return new DefaultRunOrderCalculator(runOrderParameters, getThreadCount());
111 }
112
113 public void setReporterFactory(ReporterFactory reporterFactory) {
114 this.reporterFactory = reporterFactory;
115 }
116
117 @Override
118 public ReporterFactory getReporterFactory() {
119 return reporterFactory;
120 }
121
122 public void setDirectoryScannerParameters(DirectoryScannerParameters directoryScannerParameters) {
123 this.directoryScannerParameters = directoryScannerParameters;
124 }
125
126 public void setReporterConfiguration(ReporterConfiguration reporterConfiguration) {
127 this.reporterConfiguration = reporterConfiguration;
128 }
129
130 public void setClassLoaders(ClassLoader testClassLoader) {
131 this.testClassLoader = testClassLoader;
132 }
133
134 public void setTestRequest(TestRequest testRequest) {
135 this.testRequest = testRequest;
136 }
137
138 @Override
139 public DirectoryScannerParameters getDirectoryScannerParameters() {
140 return directoryScannerParameters;
141 }
142
143 @Override
144 public ReporterConfiguration getReporterConfiguration() {
145 return reporterConfiguration;
146 }
147
148 @Override
149 public TestRequest getTestRequest() {
150 return testRequest;
151 }
152
153 @Override
154 public ClassLoader getTestClassLoader() {
155 return testClassLoader;
156 }
157
158 public void setProviderProperties(Map<String, String> providerProperties) {
159 this.providerProperties = providerProperties;
160 }
161
162 @Override
163 public Map<String, String> getProviderProperties() {
164 return providerProperties;
165 }
166
167 @Override
168 public TestArtifactInfo getTestArtifactInfo() {
169 return testArtifactInfo;
170 }
171
172 public void setTestArtifactInfo(TestArtifactInfo testArtifactInfo) {
173 this.testArtifactInfo = testArtifactInfo;
174 }
175
176 public void setRunOrderParameters(RunOrderParameters runOrderParameters) {
177 this.runOrderParameters = runOrderParameters;
178 }
179
180 @Override
181 public List<CommandLineOption> getMainCliOptions() {
182 return mainCliOptions;
183 }
184
185
186
187
188
189
190 public void setMainCliOptions(List<CommandLineOption> mainCliOptions) {
191 this.mainCliOptions = mainCliOptions == null ? Collections.<CommandLineOption>emptyList() : mainCliOptions;
192 }
193
194 @Override
195 public int getSkipAfterFailureCount() {
196 return skipAfterFailureCount;
197 }
198
199
200
201
202
203
204 public void setSkipAfterFailureCount(int skipAfterFailureCount) {
205 this.skipAfterFailureCount = skipAfterFailureCount;
206 }
207
208 @Override
209 public boolean isInsideFork() {
210 return insideFork;
211 }
212
213 @Override
214 public Integer getSystemExitTimeout() {
215 return systemExitTimeout;
216 }
217
218 public void setSystemExitTimeout(Integer systemExitTimeout) {
219 this.systemExitTimeout = systemExitTimeout;
220 }
221 }