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