1 | |
package org.apache.maven.plugin.surefire; |
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.util.List; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.apache.maven.plugin.MojoFailureException; |
26 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
27 | |
import org.apache.maven.plugins.annotations.Mojo; |
28 | |
import org.apache.maven.plugins.annotations.Parameter; |
29 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
30 | |
import org.apache.maven.surefire.suite.RunResult; |
31 | |
import org.apache.maven.surefire.util.NestedCheckedException; |
32 | |
import org.apache.maven.surefire.util.internal.StringUtils; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
@Mojo( name = "test", defaultPhase = LifecyclePhase.TEST, threadSafe = true, |
41 | |
requiresDependencyResolution = ResolutionScope.TEST ) |
42 | 2 | public class SurefirePlugin |
43 | |
extends AbstractSurefireMojo |
44 | |
implements SurefireReportParameters |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Parameter( property = "maven.test.failure.ignore", defaultValue = "false" ) |
52 | |
private boolean testFailureIgnore; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Parameter( defaultValue = "${project.build.directory}/surefire-reports" ) |
58 | |
private File reportsDirectory; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
@Parameter( property = "test" ) |
72 | |
private String test; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Parameter( property = "surefire.printSummary", defaultValue = "true" ) |
78 | |
private boolean printSummary; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
@Parameter( property = "surefire.reportFormat", defaultValue = "brief" ) |
85 | |
private String reportFormat; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@Parameter( property = "surefire.useFile", defaultValue = "true" ) |
91 | |
private boolean useFile; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
@Parameter( property = "surefire.failIfNoSpecifiedTests" ) |
101 | |
private Boolean failIfNoSpecifiedTests; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
@Parameter( property = "maven.surefire.debug" ) |
112 | |
private String debugForkedProcess; |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
@Parameter( property = "surefire.timeout" ) |
121 | |
private int forkedProcessTimeoutInSeconds; |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
@Parameter( property = "surefire.parallel.timeout" ) |
131 | |
private int parallelTestsTimeoutInSeconds; |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
@Parameter( property = "surefire.parallel.forcedTimeout" ) |
142 | |
private int parallelTestsTimeoutForcedInSeconds; |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
@Parameter |
160 | |
private List<String> includes; |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
@Parameter( property = "surefire.useSystemClassLoader", defaultValue = "true" ) |
170 | |
private boolean useSystemClassLoader; |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
@Parameter( property = "surefire.useManifestOnlyJar", defaultValue = "true" ) |
183 | |
private boolean useManifestOnlyJar; |
184 | |
|
185 | |
protected void handleSummary( RunResult summary, NestedCheckedException firstForkException ) |
186 | |
throws MojoExecutionException, MojoFailureException |
187 | |
{ |
188 | 0 | assertNoException( firstForkException ); |
189 | |
|
190 | 0 | SurefireHelper.reportExecution( this, summary, getLog() ); |
191 | 0 | } |
192 | |
|
193 | |
private void assertNoException( NestedCheckedException firstForkException ) |
194 | |
throws MojoFailureException |
195 | |
{ |
196 | 0 | if ( firstForkException != null ) |
197 | |
{ |
198 | 0 | throw new MojoFailureException( firstForkException.getMessage(), firstForkException ); |
199 | |
} |
200 | 0 | } |
201 | |
|
202 | |
private void assertNoFailureOrTimeout( NestedCheckedException summary ) |
203 | |
throws MojoFailureException |
204 | |
{ |
205 | 0 | if ( summary != null ) |
206 | |
{ |
207 | 0 | throw new MojoFailureException( "Failure or timeout" ); |
208 | |
} |
209 | 0 | } |
210 | |
|
211 | |
protected boolean isSkipExecution() |
212 | |
{ |
213 | 0 | return isSkip() || isSkipTests() || isSkipExec(); |
214 | |
} |
215 | |
|
216 | |
protected String getPluginName() |
217 | |
{ |
218 | 0 | return "surefire"; |
219 | |
} |
220 | |
|
221 | |
protected String[] getDefaultIncludes() |
222 | |
{ |
223 | 0 | return new String[]{ "**/Test*.java", "**/*Test.java", "**/*TestCase.java" }; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
public boolean isSkipTests() |
229 | |
{ |
230 | 0 | return skipTests; |
231 | |
} |
232 | |
|
233 | |
public void setSkipTests( boolean skipTests ) |
234 | |
{ |
235 | 0 | this.skipTests = skipTests; |
236 | 0 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
public boolean isSkipExec() |
242 | |
{ |
243 | 0 | return skipExec; |
244 | |
} |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
public void setSkipExec( boolean skipExec ) |
250 | |
{ |
251 | 0 | this.skipExec = skipExec; |
252 | 0 | } |
253 | |
|
254 | |
public boolean isSkip() |
255 | |
{ |
256 | 0 | return skip; |
257 | |
} |
258 | |
|
259 | |
public void setSkip( boolean skip ) |
260 | |
{ |
261 | 0 | this.skip = skip; |
262 | 0 | } |
263 | |
|
264 | |
public boolean isTestFailureIgnore() |
265 | |
{ |
266 | 0 | return testFailureIgnore; |
267 | |
} |
268 | |
|
269 | |
public void setTestFailureIgnore( boolean testFailureIgnore ) |
270 | |
{ |
271 | 0 | this.testFailureIgnore = testFailureIgnore; |
272 | 0 | } |
273 | |
|
274 | |
public File getBasedir() |
275 | |
{ |
276 | 0 | return basedir; |
277 | |
} |
278 | |
|
279 | |
public void setBasedir( File basedir ) |
280 | |
{ |
281 | 0 | this.basedir = basedir; |
282 | 0 | } |
283 | |
|
284 | |
public File getTestClassesDirectory() |
285 | |
{ |
286 | 0 | return testClassesDirectory; |
287 | |
} |
288 | |
|
289 | |
public void setTestClassesDirectory( File testClassesDirectory ) |
290 | |
{ |
291 | 0 | this.testClassesDirectory = testClassesDirectory; |
292 | 0 | } |
293 | |
|
294 | |
public File getClassesDirectory() |
295 | |
{ |
296 | 0 | return classesDirectory; |
297 | |
} |
298 | |
|
299 | |
public void setClassesDirectory( File classesDirectory ) |
300 | |
{ |
301 | 0 | this.classesDirectory = classesDirectory; |
302 | 0 | } |
303 | |
|
304 | |
public File getReportsDirectory() |
305 | |
{ |
306 | 0 | return reportsDirectory; |
307 | |
} |
308 | |
|
309 | |
public void setReportsDirectory( File reportsDirectory ) |
310 | |
{ |
311 | 0 | this.reportsDirectory = reportsDirectory; |
312 | 0 | } |
313 | |
|
314 | |
public String getTest() |
315 | |
{ |
316 | 0 | if ( StringUtils.isBlank( test ) ) |
317 | |
{ |
318 | 0 | return null; |
319 | |
} |
320 | 0 | String[] testArray = StringUtils.split( test, "," ); |
321 | 0 | StringBuilder tests = new StringBuilder(); |
322 | 0 | for ( String aTestArray : testArray ) |
323 | |
{ |
324 | 0 | String singleTest = aTestArray; |
325 | 0 | int index = singleTest.indexOf( '#' ); |
326 | 0 | if ( index >= 0 ) |
327 | |
{ |
328 | 0 | singleTest = singleTest.substring( 0, index ); |
329 | |
} |
330 | 0 | tests.append( singleTest ); |
331 | 0 | tests.append( "," ); |
332 | |
} |
333 | 0 | return tests.toString(); |
334 | |
} |
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
public String getTestMethod() |
340 | |
{ |
341 | 0 | if ( StringUtils.isBlank( test ) ) |
342 | |
{ |
343 | 0 | return null; |
344 | |
} |
345 | |
|
346 | 0 | int index = this.test.indexOf( '#' ); |
347 | 0 | int index2 = this.test.indexOf( "," ); |
348 | 0 | if ( index >= 0 ) |
349 | |
{ |
350 | 0 | if ( index2 < 0 ) |
351 | |
{ |
352 | 0 | String testStrAfterFirstSharp = this.test.substring( index + 1, this.test.length() ); |
353 | 0 | if ( !testStrAfterFirstSharp.contains( "+" ) ) |
354 | |
{ |
355 | 0 | return testStrAfterFirstSharp; |
356 | |
} |
357 | |
else |
358 | |
{ |
359 | 0 | return this.test; |
360 | |
} |
361 | |
} |
362 | |
else |
363 | |
{ |
364 | 0 | return this.test; |
365 | |
} |
366 | |
} |
367 | 0 | return null; |
368 | |
} |
369 | |
|
370 | |
public boolean isUseSystemClassLoader() |
371 | |
{ |
372 | 0 | return useSystemClassLoader; |
373 | |
} |
374 | |
|
375 | |
public void setUseSystemClassLoader( boolean useSystemClassLoader ) |
376 | |
{ |
377 | 0 | this.useSystemClassLoader = useSystemClassLoader; |
378 | 0 | } |
379 | |
|
380 | |
public boolean isUseManifestOnlyJar() |
381 | |
{ |
382 | 0 | return useManifestOnlyJar; |
383 | |
} |
384 | |
|
385 | |
public void setUseManifestOnlyJar( boolean useManifestOnlyJar ) |
386 | |
{ |
387 | 0 | this.useManifestOnlyJar = useManifestOnlyJar; |
388 | 0 | } |
389 | |
|
390 | |
public Boolean getFailIfNoSpecifiedTests() |
391 | |
{ |
392 | 0 | return failIfNoSpecifiedTests; |
393 | |
} |
394 | |
|
395 | |
public void setFailIfNoSpecifiedTests( Boolean failIfNoSpecifiedTests ) |
396 | |
{ |
397 | 0 | this.failIfNoSpecifiedTests = failIfNoSpecifiedTests; |
398 | 0 | } |
399 | |
|
400 | |
public boolean isPrintSummary() |
401 | |
{ |
402 | 0 | return printSummary; |
403 | |
} |
404 | |
|
405 | |
public void setPrintSummary( boolean printSummary ) |
406 | |
{ |
407 | 0 | this.printSummary = printSummary; |
408 | 0 | } |
409 | |
|
410 | |
public String getReportFormat() |
411 | |
{ |
412 | 0 | return reportFormat; |
413 | |
} |
414 | |
|
415 | |
public void setReportFormat( String reportFormat ) |
416 | |
{ |
417 | 0 | this.reportFormat = reportFormat; |
418 | 0 | } |
419 | |
|
420 | |
public boolean isUseFile() |
421 | |
{ |
422 | 0 | return useFile; |
423 | |
} |
424 | |
|
425 | |
public void setUseFile( boolean useFile ) |
426 | |
{ |
427 | 0 | this.useFile = useFile; |
428 | 0 | } |
429 | |
|
430 | |
public String getDebugForkedProcess() |
431 | |
{ |
432 | 0 | return debugForkedProcess; |
433 | |
} |
434 | |
|
435 | |
public void setDebugForkedProcess( String debugForkedProcess ) |
436 | |
{ |
437 | 0 | this.debugForkedProcess = debugForkedProcess; |
438 | 0 | } |
439 | |
|
440 | |
public int getForkedProcessTimeoutInSeconds() |
441 | |
{ |
442 | 0 | return forkedProcessTimeoutInSeconds; |
443 | |
} |
444 | |
|
445 | |
public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds ) |
446 | |
{ |
447 | 0 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; |
448 | 0 | } |
449 | |
|
450 | |
public int getParallelTestsTimeoutInSeconds() { |
451 | 0 | return parallelTestsTimeoutInSeconds; |
452 | |
} |
453 | |
|
454 | |
public void setParallelTestsTimeoutInSeconds( int parallelTestsTimeoutInSeconds ) { |
455 | 0 | this.parallelTestsTimeoutInSeconds = parallelTestsTimeoutInSeconds; |
456 | 0 | } |
457 | |
|
458 | |
public int getParallelTestsTimeoutForcedInSeconds() { |
459 | 0 | return parallelTestsTimeoutForcedInSeconds; |
460 | |
} |
461 | |
|
462 | |
public void setParallelTestsTimeoutForcedInSeconds( int parallelTestsTimeoutForcedInSeconds ) { |
463 | 0 | this.parallelTestsTimeoutForcedInSeconds = parallelTestsTimeoutForcedInSeconds; |
464 | 0 | } |
465 | |
|
466 | |
public void setTest( String test ) |
467 | |
{ |
468 | 0 | this.test = test; |
469 | 0 | } |
470 | |
|
471 | |
@Override |
472 | |
public List<String> getIncludes() |
473 | |
{ |
474 | 0 | return includes; |
475 | |
} |
476 | |
|
477 | |
@Override |
478 | |
public void setIncludes( List<String> includes ) |
479 | |
{ |
480 | 0 | this.includes = includes; |
481 | 0 | } |
482 | |
} |