1 | |
package org.apache.maven.plugins.surefire.report; |
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.ArrayList; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
import java.util.Locale; |
27 | |
import java.util.ResourceBundle; |
28 | |
|
29 | |
import org.apache.maven.doxia.siterenderer.Renderer; |
30 | |
import org.apache.maven.model.ReportPlugin; |
31 | |
import org.apache.maven.project.MavenProject; |
32 | |
import org.apache.maven.reporting.AbstractMavenReport; |
33 | |
import org.apache.maven.reporting.MavenReportException; |
34 | |
import org.codehaus.plexus.util.PathTool; |
35 | |
import org.codehaus.plexus.util.StringUtils; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class SurefireReportMojo |
47 | |
extends AbstractMavenReport |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private File outputDirectory; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
private Renderer siteRenderer; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
private MavenProject project; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
private boolean showSuccess; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
private File[] reportsDirectories; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
private File reportsDirectory; |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
private List reactorProjects; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
private String outputName; |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
private File xrefLocation; |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
private boolean linkXRef; |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
private boolean aggregate; |
131 | |
|
132 | |
|
133 | |
public void executeReport( Locale locale ) |
134 | |
throws MavenReportException |
135 | |
{ |
136 | 0 | if ( reportsDirectory != null ) |
137 | |
{ |
138 | 0 | if ( reportsDirectories == null ) |
139 | |
{ |
140 | 0 | reportsDirectories = new File[] { reportsDirectory }; |
141 | |
} |
142 | |
else |
143 | |
{ |
144 | 0 | File[] oldReports = reportsDirectories; |
145 | 0 | reportsDirectories = new File[oldReports.length+1]; |
146 | 0 | System.arraycopy( oldReports, 0, reportsDirectories, 0, oldReports.length ); |
147 | 0 | reportsDirectories[oldReports.length] = reportsDirectory; |
148 | |
} |
149 | |
} |
150 | 0 | if ( aggregate ) |
151 | |
{ |
152 | 0 | if ( !project.isExecutionRoot() ) return; |
153 | 0 | if ( reportsDirectories == null ) |
154 | |
{ |
155 | 0 | ArrayList reportsDirectoryList = new ArrayList(); |
156 | |
|
157 | 0 | for (Iterator i = reactorProjects.iterator(); i.hasNext();) |
158 | |
{ |
159 | 0 | MavenProject subProject = (MavenProject) i.next(); |
160 | 0 | if ( project.equals( subProject ) ) continue; |
161 | 0 | String buildDir = subProject.getBuild().getDirectory(); |
162 | 0 | File reportsDirectory = new File( buildDir + "/surefire-reports" ); |
163 | 0 | reportsDirectoryList.add( reportsDirectory ); |
164 | 0 | } |
165 | 0 | reportsDirectories = (File[]) reportsDirectoryList.toArray( new File[0] ); |
166 | 0 | } |
167 | |
} |
168 | |
else |
169 | |
{ |
170 | 0 | if ( reportsDirectories == null ) |
171 | |
{ |
172 | 0 | reportsDirectories = new File[] { new File( project.getBuild().getDirectory() + "/surefire-reports" ) }; |
173 | |
} |
174 | |
} |
175 | |
|
176 | |
|
177 | 0 | SurefireReportGenerator report = |
178 | |
new SurefireReportGenerator( reportsDirectories, locale, showSuccess, determineXrefLocation() ); |
179 | |
|
180 | 0 | report.doGenerateReport( getBundle( locale ), getSink() ); |
181 | 0 | } |
182 | |
|
183 | |
private String determineXrefLocation() |
184 | |
{ |
185 | 0 | String location = null; |
186 | |
|
187 | 0 | if ( linkXRef ) |
188 | |
{ |
189 | 0 | String relativePath = PathTool.getRelativePath( getOutputDirectory(), xrefLocation.getAbsolutePath() ); |
190 | 0 | if ( StringUtils.isEmpty( relativePath ) ) |
191 | |
{ |
192 | 0 | relativePath = "."; |
193 | |
} |
194 | 0 | relativePath = relativePath + "/" + xrefLocation.getName(); |
195 | 0 | if ( xrefLocation.exists() ) |
196 | |
{ |
197 | |
|
198 | 0 | location = relativePath; |
199 | |
} |
200 | |
else |
201 | |
{ |
202 | |
|
203 | 0 | for ( Iterator reports = project.getReportPlugins().iterator(); reports.hasNext(); ) |
204 | |
{ |
205 | 0 | ReportPlugin report = (ReportPlugin) reports.next(); |
206 | |
|
207 | 0 | String artifactId = report.getArtifactId(); |
208 | 0 | if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) ) |
209 | |
{ |
210 | 0 | location = relativePath; |
211 | |
} |
212 | 0 | } |
213 | |
} |
214 | |
|
215 | 0 | if ( location == null ) |
216 | |
{ |
217 | 0 | getLog().warn( "Unable to locate Test Source XRef to link to - DISABLED" ); |
218 | |
} |
219 | |
} |
220 | 0 | return location; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
public String getName( Locale locale ) |
225 | |
{ |
226 | 0 | return getBundle( locale ).getString( "report.surefire.name" ); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
public String getDescription( Locale locale ) |
231 | |
{ |
232 | 0 | return getBundle( locale ).getString( "report.surefire.description" ); |
233 | |
} |
234 | |
|
235 | |
|
236 | |
protected Renderer getSiteRenderer() |
237 | |
{ |
238 | 0 | return siteRenderer; |
239 | |
} |
240 | |
|
241 | |
|
242 | |
protected MavenProject getProject() |
243 | |
{ |
244 | 0 | return project; |
245 | |
} |
246 | |
|
247 | |
|
248 | |
public String getOutputName() |
249 | |
{ |
250 | 0 | return outputName; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
protected String getOutputDirectory() |
255 | |
{ |
256 | 0 | return outputDirectory.getAbsolutePath(); |
257 | |
} |
258 | |
|
259 | |
private ResourceBundle getBundle( Locale locale ) |
260 | |
{ |
261 | 0 | return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() ); |
262 | |
} |
263 | |
} |