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