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.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Properties;
27
28 import org.apache.maven.artifact.factory.ArtifactFactory;
29 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
30 import org.apache.maven.artifact.repository.ArtifactRepository;
31 import org.apache.maven.artifact.resolver.ArtifactResolver;
32 import org.apache.maven.execution.MavenSession;
33 import org.apache.maven.plugin.MojoExecutionException;
34 import org.apache.maven.plugin.MojoFailureException;
35 import org.apache.maven.plugin.surefire.booterclient.ChecksumCalculator;
36 import org.apache.maven.project.MavenProject;
37 import org.apache.maven.surefire.suite.RunResult;
38 import org.apache.maven.toolchain.ToolchainManager;
39 import org.codehaus.plexus.util.StringUtils;
40
41
42
43
44
45
46
47
48
49
50
51
52 public class SurefirePlugin
53 extends AbstractSurefireMojo
54 implements SurefireReportParameters
55 {
56
57
58
59
60
61
62
63
64 private boolean skipTests;
65
66
67
68
69
70
71
72
73 private boolean skipExec;
74
75
76
77
78
79
80
81
82 private boolean skip;
83
84
85
86
87
88
89
90 private boolean testFailureIgnore;
91
92
93
94
95
96
97
98 private File basedir;
99
100
101
102
103
104
105
106 private File testClassesDirectory;
107
108
109
110
111
112
113
114 private File classesDirectory;
115
116
117
118
119
120
121
122 private MavenProject project;
123
124
125
126
127
128
129
130
131 private List classpathDependencyExcludes;
132
133
134
135
136
137
138
139
140
141
142
143
144
145 private String classpathDependencyScopeExclude;
146
147
148
149
150
151
152
153 private List additionalClasspathElements;
154
155
156
157
158
159
160 private File reportsDirectory;
161
162
163
164
165
166
167
168
169 private File testSourceDirectory;
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 private String test;
185
186
187
188
189
190
191
192
193
194
195
196
197
198 private List includes;
199
200
201
202
203
204
205
206
207
208
209
210
211 private List excludes;
212
213
214
215
216
217
218
219
220
221 private ArtifactRepository localRepository;
222
223
224
225
226
227
228
229 private Properties systemProperties;
230
231
232
233
234
235
236
237 private Map systemPropertyVariables;
238
239
240
241
242
243
244
245 private File systemPropertiesFile;
246
247
248
249
250
251
252
253
254 private Properties properties;
255
256
257
258
259
260
261
262
263 private Map pluginArtifactMap;
264
265
266
267
268
269
270
271
272 private Map projectArtifactMap;
273
274
275
276
277
278
279 private boolean printSummary;
280
281
282
283
284
285
286 private String reportFormat;
287
288
289
290
291
292
293
294
295
296 private String reportNameSuffix;
297
298
299
300
301
302
303 private boolean useFile;
304
305
306
307
308
309
310
311
312 private boolean redirectTestOutputToFile;
313
314
315
316
317
318
319
320 private Boolean failIfNoTests;
321
322
323
324
325
326
327
328
329 private String forkMode;
330
331
332
333
334
335
336
337
338
339 private String jvm;
340
341
342
343
344
345
346
347 private String argLine;
348
349
350
351
352
353
354
355
356
357
358 private String debugForkedProcess;
359
360
361
362
363
364
365
366
367 private int forkedProcessTimeoutInSeconds;
368
369
370
371
372
373
374
375 private Map environmentVariables = new HashMap();
376
377
378
379
380
381
382
383 private File workingDirectory;
384
385
386
387
388
389
390
391
392
393
394 private boolean childDelegation;
395
396
397
398
399
400
401
402
403
404 private String groups;
405
406
407
408
409
410
411
412
413
414 private String excludedGroups;
415
416
417
418
419
420
421
422
423
424
425
426 private File[] suiteXmlFiles;
427
428
429
430
431
432
433
434 private String junitArtifactName;
435
436
437
438
439
440
441
442 private String testNGArtifactName;
443
444
445
446
447
448
449
450
451 private int threadCount;
452
453
454
455
456
457
458
459 private boolean perCoreThreadCount;
460
461
462
463
464
465
466
467
468
469 private boolean useUnlimitedThreads;
470
471
472
473
474
475
476
477
478
479
480
481
482 private String parallel;
483
484
485
486
487
488
489
490 private boolean trimStackTrace;
491
492
493
494
495
496
497 private ArtifactResolver artifactResolver;
498
499
500
501
502
503
504 private ArtifactFactory artifactFactory;
505
506
507
508
509
510
511
512 private List remoteRepositories;
513
514
515
516
517
518
519 private ArtifactMetadataSource metadataSource;
520
521 private Properties originalSystemProperties;
522
523
524
525
526 private Properties internalSystemProperties = new Properties();
527
528
529
530
531
532
533
534 private boolean disableXmlReport;
535
536
537
538
539
540
541
542
543
544 private boolean useSystemClassLoader;
545
546
547
548
549
550
551
552
553
554
555
556
557 private boolean useManifestOnlyJar;
558
559
560
561
562
563
564
565
566 private boolean enableAssertions;
567
568
569
570
571
572
573
574
575 private MavenSession session;
576
577
578
579
580
581
582
583 private String objectFactory;
584
585
586
587
588
589
590 private Boolean parallelMavenExecution;
591
592
593
594
595
596
597
598
599
600
601
602
603 private String runOrder;
604
605
606
607
608 private ToolchainManager toolchainManager;
609
610 protected void handleSummary( Summary summary )
611 throws MojoExecutionException, MojoFailureException
612 {
613 assertNoException( summary );
614 assertNoFailureOrTimeout( summary );
615 writeSummary( summary );
616 }
617
618 private void assertNoException( Summary summary )
619 throws MojoExecutionException
620 {
621 if ( !summary.isErrorFree() )
622 {
623 Exception cause = summary.getFirstException();
624 throw new MojoExecutionException( cause.getMessage(), cause );
625 }
626 }
627
628 private void assertNoFailureOrTimeout( Summary summary )
629 throws MojoExecutionException
630 {
631 if ( summary.isFailureOrTimeout() )
632 {
633 throw new MojoExecutionException( "Failure or timeout" );
634 }
635 }
636
637 private void writeSummary( Summary summary )
638 throws MojoFailureException
639 {
640 RunResult result = summary.getResultOfLastSuccessfulRun();
641 SurefireHelper.reportExecution( this, result, getLog() );
642 }
643
644 protected boolean isSkipExecution()
645 {
646 return isSkip() || isSkipTests() || isSkipExec();
647 }
648
649 protected String getPluginName()
650 {
651 return "surefire";
652 }
653
654 protected String[] getDefaultIncludes()
655 {
656 return new String[]{"**/Test*.java", "**/*Test.java", "**/*TestCase.java"};
657 }
658
659
660
661 public boolean isSkipTests()
662 {
663 return skipTests;
664 }
665
666 public void setSkipTests( boolean skipTests )
667 {
668 this.skipTests = skipTests;
669 }
670
671
672
673
674 public boolean isSkipExec()
675 {
676 return skipExec;
677 }
678
679
680
681
682 public void setSkipExec( boolean skipExec )
683 {
684 this.skipExec = skipExec;
685 }
686
687 public boolean isSkip()
688 {
689 return skip;
690 }
691
692 public void setSkip( boolean skip )
693 {
694 this.skip = skip;
695 }
696
697 public boolean isTestFailureIgnore()
698 {
699 return testFailureIgnore;
700 }
701
702 public void setTestFailureIgnore( boolean testFailureIgnore )
703 {
704 this.testFailureIgnore = testFailureIgnore;
705 }
706
707 public File getBasedir()
708 {
709 return basedir;
710 }
711
712 public void setBasedir( File basedir )
713 {
714 this.basedir = basedir;
715 }
716
717 public File getTestClassesDirectory()
718 {
719 return testClassesDirectory;
720 }
721
722 public void setTestClassesDirectory( File testClassesDirectory )
723 {
724 this.testClassesDirectory = testClassesDirectory;
725 }
726
727 public File getClassesDirectory()
728 {
729 return classesDirectory;
730 }
731
732 public void setClassesDirectory( File classesDirectory )
733 {
734 this.classesDirectory = classesDirectory;
735 }
736
737 public MavenProject getProject()
738 {
739 return project;
740 }
741
742 public void setProject( MavenProject project )
743 {
744 this.project = project;
745 }
746
747 public List getClasspathDependencyExcludes()
748 {
749 return classpathDependencyExcludes;
750 }
751
752 public void setClasspathDependencyExcludes( List classpathDependencyExcludes )
753 {
754 this.classpathDependencyExcludes = classpathDependencyExcludes;
755 }
756
757 public String getClasspathDependencyScopeExclude()
758 {
759 return classpathDependencyScopeExclude;
760 }
761
762 public void setClasspathDependencyScopeExclude( String classpathDependencyScopeExclude )
763 {
764 this.classpathDependencyScopeExclude = classpathDependencyScopeExclude;
765 }
766
767 public List getAdditionalClasspathElements()
768 {
769 return additionalClasspathElements;
770 }
771
772 public void setAdditionalClasspathElements( List additionalClasspathElements )
773 {
774 this.additionalClasspathElements = additionalClasspathElements;
775 }
776
777 public File getReportsDirectory()
778 {
779 return reportsDirectory;
780 }
781
782 public void setReportsDirectory( File reportsDirectory )
783 {
784 this.reportsDirectory = reportsDirectory;
785 }
786
787 public File getTestSourceDirectory()
788 {
789 return testSourceDirectory;
790 }
791
792 public void setTestSourceDirectory( File testSourceDirectory )
793 {
794 this.testSourceDirectory = testSourceDirectory;
795 }
796
797 public String getTest()
798 {
799 if ( StringUtils.isBlank( test ) )
800 {
801 return null;
802 }
803 int index = test.indexOf( '#' );
804 if ( index >= 0 )
805 {
806 return test.substring( 0, index );
807 }
808 return test;
809 }
810
811
812
813
814 public String getTestMethod()
815 {
816 if ( StringUtils.isBlank( test ) )
817 {
818 return null;
819 }
820 int index = this.test.indexOf( '#' );
821 if ( index >= 0 )
822 {
823 return this.test.substring( index + 1, this.test.length() );
824 }
825 return null;
826 }
827
828 public void setTest( String test )
829 {
830 this.test = test;
831 }
832
833 public List getIncludes()
834 {
835 return includes;
836 }
837
838 public void setIncludes( List includes )
839 {
840 this.includes = includes;
841 }
842
843 public List getExcludes()
844 {
845 return excludes;
846 }
847
848 public void setExcludes( List excludes )
849 {
850 this.excludes = excludes;
851 }
852
853 public ArtifactRepository getLocalRepository()
854 {
855 return localRepository;
856 }
857
858 public void setLocalRepository( ArtifactRepository localRepository )
859 {
860 this.localRepository = localRepository;
861 }
862
863
864
865
866 public Properties getSystemProperties()
867 {
868 return systemProperties;
869 }
870
871
872
873
874 public void setSystemProperties( Properties systemProperties )
875 {
876 this.systemProperties = systemProperties;
877 }
878
879 public Map getSystemPropertyVariables()
880 {
881 return systemPropertyVariables;
882 }
883
884 public void setSystemPropertyVariables( Map systemPropertyVariables )
885 {
886 this.systemPropertyVariables = systemPropertyVariables;
887 }
888
889 public File getSystemPropertiesFile()
890 {
891 return systemPropertiesFile;
892 }
893
894 public void setSystemPropertiesFile( File systemPropertiesFile )
895 {
896 this.systemPropertiesFile = systemPropertiesFile;
897 }
898
899 public Properties getProperties()
900 {
901 return properties;
902 }
903
904 public void setProperties( Properties properties )
905 {
906 this.properties = properties;
907 }
908
909 public Map getPluginArtifactMap()
910 {
911 return pluginArtifactMap;
912 }
913
914 public void setPluginArtifactMap( Map pluginArtifactMap )
915 {
916 this.pluginArtifactMap = pluginArtifactMap;
917 }
918
919 public Map getProjectArtifactMap()
920 {
921 return projectArtifactMap;
922 }
923
924 public void setProjectArtifactMap( Map projectArtifactMap )
925 {
926 this.projectArtifactMap = projectArtifactMap;
927 }
928
929 public boolean isPrintSummary()
930 {
931 return printSummary;
932 }
933
934 public void setPrintSummary( boolean printSummary )
935 {
936 this.printSummary = printSummary;
937 }
938
939 public String getReportFormat()
940 {
941 return reportFormat;
942 }
943
944 public void setReportFormat( String reportFormat )
945 {
946 this.reportFormat = reportFormat;
947 }
948
949 public String getReportNameSuffix()
950 {
951 return reportNameSuffix;
952 }
953
954 public void setReportNameSuffix( String reportNameSuffix )
955 {
956 this.reportNameSuffix = reportNameSuffix;
957 }
958
959 public boolean isUseFile()
960 {
961 return useFile;
962 }
963
964 public void setUseFile( boolean useFile )
965 {
966 this.useFile = useFile;
967 }
968
969 public boolean isRedirectTestOutputToFile()
970 {
971 return redirectTestOutputToFile;
972 }
973
974 public void setRedirectTestOutputToFile( boolean redirectTestOutputToFile )
975 {
976 this.redirectTestOutputToFile = redirectTestOutputToFile;
977 }
978
979 public Boolean getFailIfNoTests()
980 {
981 return failIfNoTests;
982 }
983
984 public void setFailIfNoTests( Boolean failIfNoTests )
985 {
986 this.failIfNoTests = failIfNoTests;
987 }
988
989 public String getForkMode()
990 {
991 return forkMode;
992 }
993
994 public void setForkMode( String forkMode )
995 {
996 this.forkMode = forkMode;
997 }
998
999 public String getJvm()
1000 {
1001 return jvm;
1002 }
1003
1004 public void setJvm( String jvm )
1005 {
1006 this.jvm = jvm;
1007 }
1008
1009 public String getArgLine()
1010 {
1011 return argLine;
1012 }
1013
1014 public void setArgLine( String argLine )
1015 {
1016 this.argLine = argLine;
1017 }
1018
1019 public String getDebugForkedProcess()
1020 {
1021 return debugForkedProcess;
1022 }
1023
1024 public void setDebugForkedProcess( String debugForkedProcess )
1025 {
1026 this.debugForkedProcess = debugForkedProcess;
1027 }
1028
1029 public int getForkedProcessTimeoutInSeconds()
1030 {
1031 return forkedProcessTimeoutInSeconds;
1032 }
1033
1034 public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds )
1035 {
1036 this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds;
1037 }
1038
1039 public Map getEnvironmentVariables()
1040 {
1041 return environmentVariables;
1042 }
1043
1044 public void setEnvironmentVariables( Map environmentVariables )
1045 {
1046 this.environmentVariables = environmentVariables;
1047 }
1048
1049 public File getWorkingDirectory()
1050 {
1051 return workingDirectory;
1052 }
1053
1054 public void setWorkingDirectory( File workingDirectory )
1055 {
1056 this.workingDirectory = workingDirectory;
1057 }
1058
1059 public boolean isChildDelegation()
1060 {
1061 return childDelegation;
1062 }
1063
1064 public void setChildDelegation( boolean childDelegation )
1065 {
1066 this.childDelegation = childDelegation;
1067 }
1068
1069 public String getGroups()
1070 {
1071 return groups;
1072 }
1073
1074 public void setGroups( String groups )
1075 {
1076 this.groups = groups;
1077 }
1078
1079 public String getExcludedGroups()
1080 {
1081 return excludedGroups;
1082 }
1083
1084 public void setExcludedGroups( String excludedGroups )
1085 {
1086 this.excludedGroups = excludedGroups;
1087 }
1088
1089 public File[] getSuiteXmlFiles()
1090 {
1091 return suiteXmlFiles;
1092 }
1093
1094 public void setSuiteXmlFiles( File[] suiteXmlFiles )
1095 {
1096 this.suiteXmlFiles = suiteXmlFiles;
1097 }
1098
1099 public String getJunitArtifactName()
1100 {
1101 return junitArtifactName;
1102 }
1103
1104 public void setJunitArtifactName( String junitArtifactName )
1105 {
1106 this.junitArtifactName = junitArtifactName;
1107 }
1108
1109 public String getTestNGArtifactName()
1110 {
1111 return testNGArtifactName;
1112 }
1113
1114 public void setTestNGArtifactName( String testNGArtifactName )
1115 {
1116 this.testNGArtifactName = testNGArtifactName;
1117 }
1118
1119 public int getThreadCount()
1120 {
1121 return threadCount;
1122 }
1123
1124 public void setThreadCount( int threadCount )
1125 {
1126 this.threadCount = threadCount;
1127 }
1128
1129 public boolean getPerCoreThreadCount()
1130 {
1131 return perCoreThreadCount;
1132 }
1133
1134 public void setPerCoreThreadCount( boolean perCoreThreadCount )
1135 {
1136 this.perCoreThreadCount = perCoreThreadCount;
1137 }
1138
1139 public boolean getUseUnlimitedThreads()
1140 {
1141 return useUnlimitedThreads;
1142 }
1143
1144 public void setUseUnlimitedThreads( boolean useUnlimitedThreads )
1145 {
1146 this.useUnlimitedThreads = useUnlimitedThreads;
1147 }
1148
1149 public String getParallel()
1150 {
1151 return parallel;
1152 }
1153
1154 public void setParallel( String parallel )
1155 {
1156 this.parallel = parallel;
1157 }
1158
1159 public boolean isTrimStackTrace()
1160 {
1161 return trimStackTrace;
1162 }
1163
1164 public void setTrimStackTrace( boolean trimStackTrace )
1165 {
1166 this.trimStackTrace = trimStackTrace;
1167 }
1168
1169 public ArtifactResolver getArtifactResolver()
1170 {
1171 return artifactResolver;
1172 }
1173
1174 public void setArtifactResolver( ArtifactResolver artifactResolver )
1175 {
1176 this.artifactResolver = artifactResolver;
1177 }
1178
1179 public ArtifactFactory getArtifactFactory()
1180 {
1181 return artifactFactory;
1182 }
1183
1184 public void setArtifactFactory( ArtifactFactory artifactFactory )
1185 {
1186 this.artifactFactory = artifactFactory;
1187 }
1188
1189 public List getRemoteRepositories()
1190 {
1191 return remoteRepositories;
1192 }
1193
1194 public void setRemoteRepositories( List remoteRepositories )
1195 {
1196 this.remoteRepositories = remoteRepositories;
1197 }
1198
1199 public ArtifactMetadataSource getMetadataSource()
1200 {
1201 return metadataSource;
1202 }
1203
1204 public void setMetadataSource( ArtifactMetadataSource metadataSource )
1205 {
1206 this.metadataSource = metadataSource;
1207 }
1208
1209 public Properties getOriginalSystemProperties()
1210 {
1211 return originalSystemProperties;
1212 }
1213
1214 public void setOriginalSystemProperties( Properties originalSystemProperties )
1215 {
1216 this.originalSystemProperties = originalSystemProperties;
1217 }
1218
1219 public Properties getInternalSystemProperties()
1220 {
1221 return internalSystemProperties;
1222 }
1223
1224 public void setInternalSystemProperties( Properties internalSystemProperties )
1225 {
1226 this.internalSystemProperties = internalSystemProperties;
1227 }
1228
1229 public boolean isDisableXmlReport()
1230 {
1231 return disableXmlReport;
1232 }
1233
1234 public void setDisableXmlReport( boolean disableXmlReport )
1235 {
1236 this.disableXmlReport = disableXmlReport;
1237 }
1238
1239 public boolean isUseSystemClassLoader()
1240 {
1241 return useSystemClassLoader;
1242 }
1243
1244 public void setUseSystemClassLoader( boolean useSystemClassLoader )
1245 {
1246 this.useSystemClassLoader = useSystemClassLoader;
1247 }
1248
1249 public boolean isUseManifestOnlyJar()
1250 {
1251 return useManifestOnlyJar;
1252 }
1253
1254 public void setUseManifestOnlyJar( boolean useManifestOnlyJar )
1255 {
1256 this.useManifestOnlyJar = useManifestOnlyJar;
1257 }
1258
1259 public boolean isEnableAssertions()
1260 {
1261 return enableAssertions;
1262 }
1263
1264 public void setEnableAssertions( boolean enableAssertions )
1265 {
1266 this.enableAssertions = enableAssertions;
1267 }
1268
1269 public MavenSession getSession()
1270 {
1271 return session;
1272 }
1273
1274 public void setSession( MavenSession session )
1275 {
1276 this.session = session;
1277 }
1278
1279 public String getObjectFactory()
1280 {
1281 return objectFactory;
1282 }
1283
1284 public void setObjectFactory( String objectFactory )
1285 {
1286 this.objectFactory = objectFactory;
1287 }
1288
1289 public ToolchainManager getToolchainManager()
1290 {
1291 return toolchainManager;
1292 }
1293
1294 public void setToolchainManager( ToolchainManager toolchainManager )
1295 {
1296 this.toolchainManager = toolchainManager;
1297 }
1298
1299 public boolean isMavenParallel()
1300 {
1301 return parallelMavenExecution != null && parallelMavenExecution.booleanValue();
1302 }
1303
1304 public String getRunOrder()
1305 {
1306 return runOrder;
1307 }
1308
1309 public void setRunOrder( String runOrder )
1310 {
1311 this.runOrder = runOrder;
1312 }
1313
1314 protected void addPluginSpecificChecksumItems( ChecksumCalculator checksum )
1315 {
1316 }
1317
1318 }