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