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 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
@Parameter |
139 | |
private List<String> includes; |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@Parameter( property = "surefire.useSystemClassLoader", defaultValue = "true" ) |
149 | |
private boolean useSystemClassLoader; |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
@Parameter( property = "surefire.useManifestOnlyJar", defaultValue = "true" ) |
162 | |
private boolean useManifestOnlyJar; |
163 | |
|
164 | |
protected void handleSummary( RunResult summary, NestedCheckedException firstForkException ) |
165 | |
throws MojoExecutionException, MojoFailureException |
166 | |
{ |
167 | 0 | assertNoException( firstForkException ); |
168 | |
|
169 | 0 | SurefireHelper.reportExecution( this, summary, getLog() ); |
170 | 0 | } |
171 | |
|
172 | |
private void assertNoException( NestedCheckedException firstForkException ) |
173 | |
throws MojoFailureException |
174 | |
{ |
175 | 0 | if ( firstForkException != null ) |
176 | |
{ |
177 | 0 | throw new MojoFailureException( firstForkException.getMessage(), firstForkException ); |
178 | |
} |
179 | 0 | } |
180 | |
|
181 | |
private void assertNoFailureOrTimeout( NestedCheckedException summary ) |
182 | |
throws MojoFailureException |
183 | |
{ |
184 | 0 | if ( summary != null ) |
185 | |
{ |
186 | 0 | throw new MojoFailureException( "Failure or timeout" ); |
187 | |
} |
188 | 0 | } |
189 | |
|
190 | |
protected boolean isSkipExecution() |
191 | |
{ |
192 | 0 | return isSkip() || isSkipTests() || isSkipExec(); |
193 | |
} |
194 | |
|
195 | |
protected String getPluginName() |
196 | |
{ |
197 | 0 | return "surefire"; |
198 | |
} |
199 | |
|
200 | |
protected String[] getDefaultIncludes() |
201 | |
{ |
202 | 0 | return new String[]{ "**/Test*.java", "**/*Test.java", "**/*TestCase.java" }; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
public boolean isSkipTests() |
208 | |
{ |
209 | 0 | return skipTests; |
210 | |
} |
211 | |
|
212 | |
public void setSkipTests( boolean skipTests ) |
213 | |
{ |
214 | 0 | this.skipTests = skipTests; |
215 | 0 | } |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public boolean isSkipExec() |
221 | |
{ |
222 | 0 | return skipExec; |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public void setSkipExec( boolean skipExec ) |
229 | |
{ |
230 | 0 | this.skipExec = skipExec; |
231 | 0 | } |
232 | |
|
233 | |
public boolean isSkip() |
234 | |
{ |
235 | 0 | return skip; |
236 | |
} |
237 | |
|
238 | |
public void setSkip( boolean skip ) |
239 | |
{ |
240 | 0 | this.skip = skip; |
241 | 0 | } |
242 | |
|
243 | |
public boolean isTestFailureIgnore() |
244 | |
{ |
245 | 0 | return testFailureIgnore; |
246 | |
} |
247 | |
|
248 | |
public void setTestFailureIgnore( boolean testFailureIgnore ) |
249 | |
{ |
250 | 0 | this.testFailureIgnore = testFailureIgnore; |
251 | 0 | } |
252 | |
|
253 | |
public File getBasedir() |
254 | |
{ |
255 | 0 | return basedir; |
256 | |
} |
257 | |
|
258 | |
public void setBasedir( File basedir ) |
259 | |
{ |
260 | 0 | this.basedir = basedir; |
261 | 0 | } |
262 | |
|
263 | |
public File getTestClassesDirectory() |
264 | |
{ |
265 | 0 | return testClassesDirectory; |
266 | |
} |
267 | |
|
268 | |
public void setTestClassesDirectory( File testClassesDirectory ) |
269 | |
{ |
270 | 0 | this.testClassesDirectory = testClassesDirectory; |
271 | 0 | } |
272 | |
|
273 | |
public File getClassesDirectory() |
274 | |
{ |
275 | 0 | return classesDirectory; |
276 | |
} |
277 | |
|
278 | |
public void setClassesDirectory( File classesDirectory ) |
279 | |
{ |
280 | 0 | this.classesDirectory = classesDirectory; |
281 | 0 | } |
282 | |
|
283 | |
public File getReportsDirectory() |
284 | |
{ |
285 | 0 | return reportsDirectory; |
286 | |
} |
287 | |
|
288 | |
public void setReportsDirectory( File reportsDirectory ) |
289 | |
{ |
290 | 0 | this.reportsDirectory = reportsDirectory; |
291 | 0 | } |
292 | |
|
293 | |
public String getTest() |
294 | |
{ |
295 | 0 | if ( StringUtils.isBlank( test ) ) |
296 | |
{ |
297 | 0 | return null; |
298 | |
} |
299 | 0 | String[] testArray = StringUtils.split( test, "," ); |
300 | 0 | StringBuilder tests = new StringBuilder(); |
301 | 0 | for ( String aTestArray : testArray ) |
302 | |
{ |
303 | 0 | String singleTest = aTestArray; |
304 | 0 | int index = singleTest.indexOf( '#' ); |
305 | 0 | if ( index >= 0 ) |
306 | |
{ |
307 | 0 | singleTest = singleTest.substring( 0, index ); |
308 | |
} |
309 | 0 | tests.append( singleTest ); |
310 | 0 | tests.append( "," ); |
311 | |
} |
312 | 0 | return tests.toString(); |
313 | |
} |
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
public String getTestMethod() |
319 | |
{ |
320 | 0 | if ( StringUtils.isBlank( test ) ) |
321 | |
{ |
322 | 0 | return null; |
323 | |
} |
324 | |
|
325 | 0 | int index = this.test.indexOf( '#' ); |
326 | 0 | int index2 = this.test.indexOf( "," ); |
327 | 0 | if ( index >= 0 ) |
328 | |
{ |
329 | 0 | if ( index2 < 0 ) |
330 | |
{ |
331 | 0 | String testStrAfterFirstSharp = this.test.substring( index + 1, this.test.length() ); |
332 | 0 | if ( !testStrAfterFirstSharp.contains( "+" ) ) |
333 | |
{ |
334 | 0 | return testStrAfterFirstSharp; |
335 | |
} |
336 | |
else |
337 | |
{ |
338 | 0 | return this.test; |
339 | |
} |
340 | |
} |
341 | |
else |
342 | |
{ |
343 | 0 | return this.test; |
344 | |
} |
345 | |
} |
346 | 0 | return null; |
347 | |
} |
348 | |
|
349 | |
public boolean isUseSystemClassLoader() |
350 | |
{ |
351 | 0 | return useSystemClassLoader; |
352 | |
} |
353 | |
|
354 | |
public void setUseSystemClassLoader( boolean useSystemClassLoader ) |
355 | |
{ |
356 | 0 | this.useSystemClassLoader = useSystemClassLoader; |
357 | 0 | } |
358 | |
|
359 | |
public boolean isUseManifestOnlyJar() |
360 | |
{ |
361 | 0 | return useManifestOnlyJar; |
362 | |
} |
363 | |
|
364 | |
public void setUseManifestOnlyJar( boolean useManifestOnlyJar ) |
365 | |
{ |
366 | 0 | this.useManifestOnlyJar = useManifestOnlyJar; |
367 | 0 | } |
368 | |
|
369 | |
public Boolean getFailIfNoSpecifiedTests() |
370 | |
{ |
371 | 0 | return failIfNoSpecifiedTests; |
372 | |
} |
373 | |
|
374 | |
public void setFailIfNoSpecifiedTests( Boolean failIfNoSpecifiedTests ) |
375 | |
{ |
376 | 0 | this.failIfNoSpecifiedTests = failIfNoSpecifiedTests; |
377 | 0 | } |
378 | |
|
379 | |
public boolean isPrintSummary() |
380 | |
{ |
381 | 0 | return printSummary; |
382 | |
} |
383 | |
|
384 | |
public void setPrintSummary( boolean printSummary ) |
385 | |
{ |
386 | 0 | this.printSummary = printSummary; |
387 | 0 | } |
388 | |
|
389 | |
public String getReportFormat() |
390 | |
{ |
391 | 0 | return reportFormat; |
392 | |
} |
393 | |
|
394 | |
public void setReportFormat( String reportFormat ) |
395 | |
{ |
396 | 0 | this.reportFormat = reportFormat; |
397 | 0 | } |
398 | |
|
399 | |
public boolean isUseFile() |
400 | |
{ |
401 | 0 | return useFile; |
402 | |
} |
403 | |
|
404 | |
public void setUseFile( boolean useFile ) |
405 | |
{ |
406 | 0 | this.useFile = useFile; |
407 | 0 | } |
408 | |
|
409 | |
public String getDebugForkedProcess() |
410 | |
{ |
411 | 0 | return debugForkedProcess; |
412 | |
} |
413 | |
|
414 | |
public void setDebugForkedProcess( String debugForkedProcess ) |
415 | |
{ |
416 | 0 | this.debugForkedProcess = debugForkedProcess; |
417 | 0 | } |
418 | |
|
419 | |
public int getForkedProcessTimeoutInSeconds() |
420 | |
{ |
421 | 0 | return forkedProcessTimeoutInSeconds; |
422 | |
} |
423 | |
|
424 | |
public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds ) |
425 | |
{ |
426 | 0 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; |
427 | 0 | } |
428 | |
|
429 | |
public void setTest( String test ) |
430 | |
{ |
431 | 0 | this.test = test; |
432 | 0 | } |
433 | |
|
434 | |
@Override |
435 | |
public List<String> getIncludes() |
436 | |
{ |
437 | 0 | return includes; |
438 | |
} |
439 | |
|
440 | |
@Override |
441 | |
public void setIncludes( List<String> includes ) |
442 | |
{ |
443 | 0 | this.includes = includes; |
444 | 0 | } |
445 | |
} |