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