1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.invoker;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.Reader;
24
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader;
32 import org.codehaus.plexus.util.ReaderFactory;
33 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
34
35
36
37
38
39
40
41 @Mojo(name = "verify", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
42 public class VerifyMojo extends AbstractMojo {
43
44
45
46
47
48
49 @Parameter(property = "invoker.skip", defaultValue = "false")
50 private boolean skipInvocation;
51
52
53
54
55
56
57 @Parameter(property = "invoker.reportsDirectory", defaultValue = "${project.build.directory}/invoker-reports")
58 private File reportsDirectory;
59
60
61
62
63
64
65
66 @Parameter(property = "maven.test.failure.ignore", defaultValue = "false")
67 private boolean ignoreFailures;
68
69
70
71
72
73
74 @Parameter(defaultValue = "false")
75 private boolean suppressSummaries;
76
77
78
79
80
81
82 @Parameter(property = "invoker.failIfNoProjects")
83 private Boolean failIfNoProjects;
84
85
86
87
88
89
90 @Parameter(property = "invoker.streamLogsOnFailures", defaultValue = "false")
91 private boolean streamLogsOnFailures;
92
93
94
95
96
97
98
99 public void execute() throws MojoExecutionException, MojoFailureException {
100 if (skipInvocation) {
101 getLog().info("Skipping invocation per configuration."
102 + " If this is incorrect, ensure the skipInvocation parameter is not set to true.");
103 return;
104 }
105
106 File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory);
107 if (reportFiles.length <= 0) {
108 if (Boolean.TRUE.equals(failIfNoProjects)) {
109 throw new MojoFailureException("No projects to invoke!");
110 }
111 getLog().info("No invoker report files found, nothing to check.");
112 return;
113 }
114
115 BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
116
117 InvokerSession invokerSession = new InvokerSession();
118
119 for (File reportFile : reportFiles) {
120 try (Reader xmlReader = ReaderFactory.newXmlReader(reportFile)) {
121 invokerSession.addJob(reader.read(xmlReader));
122 } catch (XmlPullParserException e) {
123 throw new MojoExecutionException("Failed to parse report file: " + reportFile, e);
124 } catch (IOException e) {
125 throw new MojoExecutionException("Failed to read report file: " + reportFile, e);
126 }
127 }
128
129 if (streamLogsOnFailures) {
130 invokerSession.logFailedBuildLog(getLog(), ignoreFailures);
131 }
132
133 if (!suppressSummaries) {
134 invokerSession.logSummary(getLog(), ignoreFailures);
135 }
136
137 invokerSession.handleFailures(getLog(), ignoreFailures);
138 }
139 }