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