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 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Parameter |
157 | |
private List<String> includes; |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
@Parameter( property = "failsafe.useSystemClassLoader", defaultValue = "true" ) |
167 | |
private boolean useSystemClassLoader; |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
@Parameter( property = "failsafe.useManifestOnlyJar", defaultValue = "true" ) |
180 | |
private boolean useManifestOnlyJar; |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
@Parameter( property = "encoding", defaultValue = "${project.reporting.outputEncoding}" ) |
186 | |
private String encoding; |
187 | |
|
188 | |
protected void handleSummary( RunResult summary, NestedCheckedException firstForkException ) |
189 | |
throws MojoExecutionException, MojoFailureException |
190 | |
{ |
191 | 0 | writeSummary( summary, firstForkException ); |
192 | 0 | } |
193 | |
|
194 | |
@SuppressWarnings( "unchecked" ) |
195 | |
private void writeSummary( RunResult summary, NestedCheckedException firstForkException ) |
196 | |
throws MojoExecutionException |
197 | |
{ |
198 | 0 | File summaryFile = getSummaryFile(); |
199 | 0 | if ( !summaryFile.getParentFile().isDirectory() ) |
200 | |
{ |
201 | |
|
202 | 0 | summaryFile.getParentFile().mkdirs(); |
203 | |
} |
204 | |
|
205 | 0 | FileOutputStream fout = null; |
206 | 0 | FileInputStream fin = null; |
207 | |
try |
208 | |
{ |
209 | 0 | Object token = getPluginContext().get( FAILSAFE_IN_PROGRESS_CONTEXT_KEY ); |
210 | 0 | summary.writeSummary( summaryFile, token != null, getEncodingOrDefault() ); |
211 | |
} |
212 | 0 | catch ( IOException e ) |
213 | |
{ |
214 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
215 | |
} |
216 | |
finally |
217 | |
{ |
218 | 0 | close( fin ); |
219 | 0 | close( fout ); |
220 | 0 | } |
221 | |
|
222 | 0 | getPluginContext().put( FAILSAFE_IN_PROGRESS_CONTEXT_KEY, FAILSAFE_IN_PROGRESS_CONTEXT_KEY ); |
223 | 0 | } |
224 | |
|
225 | |
private String getEncodingOrDefault() |
226 | |
{ |
227 | 0 | if ( StringUtils.isEmpty( encoding ) ) |
228 | |
{ |
229 | 0 | getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + |
230 | |
", i.e. build is platform dependent!" ); |
231 | 0 | return ReaderFactory.FILE_ENCODING; |
232 | |
} |
233 | |
else |
234 | |
{ |
235 | 0 | return encoding; |
236 | |
} |
237 | |
} |
238 | |
|
239 | |
@SuppressWarnings( "deprecation" ) |
240 | |
protected boolean isSkipExecution() |
241 | |
{ |
242 | 0 | return isSkip() || isSkipTests() || isSkipITs() || isSkipExec(); |
243 | |
} |
244 | |
|
245 | |
protected String getPluginName() |
246 | |
{ |
247 | 0 | return "failsafe"; |
248 | |
} |
249 | |
|
250 | |
protected String[] getDefaultIncludes() |
251 | |
{ |
252 | 0 | return new String[]{ "**/IT*.java", "**/*IT.java", "**/*ITCase.java" }; |
253 | |
} |
254 | |
|
255 | |
public boolean isSkipTests() |
256 | |
{ |
257 | 0 | return skipTests; |
258 | |
} |
259 | |
|
260 | |
public void setSkipTests( boolean skipTests ) |
261 | |
{ |
262 | 0 | this.skipTests = skipTests; |
263 | 0 | } |
264 | |
|
265 | |
public boolean isSkipITs() |
266 | |
{ |
267 | 0 | return skipITs; |
268 | |
} |
269 | |
|
270 | |
public void setSkipITs( boolean skipITs ) |
271 | |
{ |
272 | 0 | this.skipITs = skipITs; |
273 | 0 | } |
274 | |
|
275 | |
@SuppressWarnings( "deprecation" ) |
276 | |
@Deprecated |
277 | |
public boolean isSkipExec() |
278 | |
{ |
279 | 0 | return skipExec; |
280 | |
} |
281 | |
|
282 | |
@SuppressWarnings( "deprecation" ) |
283 | |
@Deprecated |
284 | |
public void setSkipExec( boolean skipExec ) |
285 | |
{ |
286 | 0 | this.skipExec = skipExec; |
287 | 0 | } |
288 | |
|
289 | |
public boolean isSkip() |
290 | |
{ |
291 | 0 | return skip; |
292 | |
} |
293 | |
|
294 | |
public void setSkip( boolean skip ) |
295 | |
{ |
296 | 0 | this.skip = skip; |
297 | 0 | } |
298 | |
|
299 | |
public File getBasedir() |
300 | |
{ |
301 | 0 | return basedir; |
302 | |
} |
303 | |
|
304 | |
public void setBasedir( File basedir ) |
305 | |
{ |
306 | 0 | this.basedir = basedir; |
307 | 0 | } |
308 | |
|
309 | |
public File getTestClassesDirectory() |
310 | |
{ |
311 | 0 | return testClassesDirectory; |
312 | |
} |
313 | |
|
314 | |
public void setTestClassesDirectory( File testClassesDirectory ) |
315 | |
{ |
316 | 0 | this.testClassesDirectory = testClassesDirectory; |
317 | 0 | } |
318 | |
|
319 | |
public File getClassesDirectory() |
320 | |
{ |
321 | 0 | return classesDirectory; |
322 | |
} |
323 | |
|
324 | |
public void setClassesDirectory( File classesDirectory ) |
325 | |
{ |
326 | 0 | this.classesDirectory = classesDirectory; |
327 | 0 | } |
328 | |
|
329 | |
public File getReportsDirectory() |
330 | |
{ |
331 | 0 | return reportsDirectory; |
332 | |
} |
333 | |
|
334 | |
public void setReportsDirectory( File reportsDirectory ) |
335 | |
{ |
336 | 0 | this.reportsDirectory = reportsDirectory; |
337 | 0 | } |
338 | |
|
339 | |
public String getTest() |
340 | |
{ |
341 | 0 | if ( StringUtils.isBlank( test ) ) |
342 | |
{ |
343 | 0 | return null; |
344 | |
} |
345 | 0 | int index = test.indexOf( '#' ); |
346 | 0 | if ( index >= 0 ) |
347 | |
{ |
348 | 0 | return test.substring( 0, index ); |
349 | |
} |
350 | 0 | return test; |
351 | |
} |
352 | |
|
353 | |
public void setTest( String test ) |
354 | |
{ |
355 | 0 | this.test = test; |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
public String getTestMethod() |
362 | |
{ |
363 | 0 | if ( StringUtils.isBlank( test ) ) |
364 | |
{ |
365 | 0 | return null; |
366 | |
} |
367 | 0 | int index = this.test.indexOf( '#' ); |
368 | 0 | if ( index >= 0 ) |
369 | |
{ |
370 | 0 | return this.test.substring( index + 1, this.test.length() ); |
371 | |
} |
372 | 0 | return null; |
373 | |
} |
374 | |
|
375 | |
|
376 | |
public File getSummaryFile() |
377 | |
{ |
378 | 0 | return summaryFile; |
379 | |
} |
380 | |
|
381 | |
public void setSummaryFile( File summaryFile ) |
382 | |
{ |
383 | 0 | this.summaryFile = summaryFile; |
384 | 0 | } |
385 | |
|
386 | |
public boolean isPrintSummary() |
387 | |
{ |
388 | 0 | return printSummary; |
389 | |
} |
390 | |
|
391 | |
public void setPrintSummary( boolean printSummary ) |
392 | |
{ |
393 | 0 | this.printSummary = printSummary; |
394 | 0 | } |
395 | |
|
396 | |
public String getReportFormat() |
397 | |
{ |
398 | 0 | return reportFormat; |
399 | |
} |
400 | |
|
401 | |
public void setReportFormat( String reportFormat ) |
402 | |
{ |
403 | 0 | this.reportFormat = reportFormat; |
404 | 0 | } |
405 | |
|
406 | |
public boolean isUseFile() |
407 | |
{ |
408 | 0 | return useFile; |
409 | |
} |
410 | |
|
411 | |
public void setUseFile( boolean useFile ) |
412 | |
{ |
413 | 0 | this.useFile = useFile; |
414 | 0 | } |
415 | |
|
416 | |
public String getDebugForkedProcess() |
417 | |
{ |
418 | 0 | return debugForkedProcess; |
419 | |
} |
420 | |
|
421 | |
public void setDebugForkedProcess( String debugForkedProcess ) |
422 | |
{ |
423 | 0 | this.debugForkedProcess = debugForkedProcess; |
424 | 0 | } |
425 | |
|
426 | |
public int getForkedProcessTimeoutInSeconds() |
427 | |
{ |
428 | 0 | return forkedProcessTimeoutInSeconds; |
429 | |
} |
430 | |
|
431 | |
public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds ) |
432 | |
{ |
433 | 0 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; |
434 | 0 | } |
435 | |
|
436 | |
public boolean isUseSystemClassLoader() |
437 | |
{ |
438 | 0 | return useSystemClassLoader; |
439 | |
} |
440 | |
|
441 | |
public void setUseSystemClassLoader( boolean useSystemClassLoader ) |
442 | |
{ |
443 | 0 | this.useSystemClassLoader = useSystemClassLoader; |
444 | 0 | } |
445 | |
|
446 | |
public boolean isUseManifestOnlyJar() |
447 | |
{ |
448 | 0 | return useManifestOnlyJar; |
449 | |
} |
450 | |
|
451 | |
public void setUseManifestOnlyJar( boolean useManifestOnlyJar ) |
452 | |
{ |
453 | 0 | this.useManifestOnlyJar = useManifestOnlyJar; |
454 | 0 | } |
455 | |
|
456 | |
|
457 | |
|
458 | |
public boolean isTestFailureIgnore() |
459 | |
{ |
460 | 0 | return true; |
461 | |
} |
462 | |
|
463 | |
public void setTestFailureIgnore( boolean testFailureIgnore ) |
464 | |
{ |
465 | |
|
466 | 0 | } |
467 | |
|
468 | |
protected void addPluginSpecificChecksumItems( ChecksumCalculator checksum ) |
469 | |
{ |
470 | 0 | checksum.add( skipITs ); |
471 | 0 | checksum.add( summaryFile ); |
472 | 0 | } |
473 | |
|
474 | |
public Boolean getFailIfNoSpecifiedTests() |
475 | |
{ |
476 | 0 | return failIfNoSpecifiedTests; |
477 | |
} |
478 | |
|
479 | |
public void setFailIfNoSpecifiedTests( Boolean failIfNoSpecifiedTests ) |
480 | |
{ |
481 | 0 | this.failIfNoSpecifiedTests = failIfNoSpecifiedTests; |
482 | 0 | } |
483 | |
|
484 | |
@Override |
485 | |
public List<String> getIncludes() |
486 | |
{ |
487 | 0 | return includes; |
488 | |
} |
489 | |
|
490 | |
@Override |
491 | |
public void setIncludes( List<String> includes ) |
492 | |
{ |
493 | 0 | this.includes = includes; |
494 | 0 | } |
495 | |
} |