1
package org.apache.maven.plugins.surefire.report;
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
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;
29
import org.apache.maven.model.ReportPlugin;
30
import org.apache.maven.project.MavenProject;
31
import org.apache.maven.reporting.AbstractMavenReport;
32
import org.apache.maven.reporting.MavenReportException;
33
import org.codehaus.doxia.site.renderer.SiteRenderer;
34
import org.codehaus.plexus.util.PathTool;
35
import org.codehaus.plexus.util.StringUtils;
39
* Creates a nicely formatted Surefire Test Report in html format.
41
* @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
42
* @version $Id: SurefireReportMojo.java 635090 2008-03-08 21:28:16Z hboutemy $
44
* @execute phase="test" lifecycle="surefire"
46
public class SurefireReportMojo
47
extends AbstractMavenReport
50
* Location where generated html will be created.
52
* @parameter expression="${project.reporting.outputDirectory}"
54
private File outputDirectory;
59
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
62
private SiteRenderer siteRenderer;
67
* @parameter expression="${project}"
70
private MavenProject project;
73
* If set to false, only failures are shown.
75
* @parameter expression="${showSuccess}" default-value="true"
78
private boolean showSuccess;
81
* Directories containing the XML Report files that will be parsed and rendered to HTML format.
85
private File[] reportsDirectories;
88
* (Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.
93
private File reportsDirectory;
97
* The projects in the reactor for aggregation report.
99
* @parameter expression="${reactorProjects}"
102
private List reactorProjects;
105
* The filename to use for the report.
107
* @parameter expression="${outputName}" default-value="surefire-report"
110
private String outputName;
113
* Location of the Xrefs to link.
115
* @parameter default-value="${project.reporting.outputDirectory}/xref-test"
117
private File xrefLocation;
120
* Whether to link the XRef if found.
122
* @parameter expression="${linkXRef}" default-value="true"
124
private boolean linkXRef;
127
* Whether to build an aggregated report at the root, or build individual reports.
129
* @parameter expression="${aggregate}" default-value="false"
131
private boolean aggregate;
133
public void executeReport( Locale locale )
134
throws MavenReportException
136
if ( reportsDirectory != null )
138
if ( reportsDirectories == null )
140
reportsDirectories = new File[] { reportsDirectory };
144
File[] oldReports = reportsDirectories;
145
reportsDirectories = new File[oldReports.length+1];
146
System.arraycopy( oldReports, 0, reportsDirectories, 0, oldReports.length );
147
reportsDirectories[oldReports.length] = reportsDirectory;
152
if ( !project.isExecutionRoot() ) return;
153
if ( reportsDirectories == null )
155
ArrayList reportsDirectoryList = new ArrayList();
156
// TODO guess the real location
157
for (Iterator i = reactorProjects.iterator(); i.hasNext();)
159
MavenProject subProject = (MavenProject) i.next();
160
if ( project.equals( subProject ) ) continue;
161
String buildDir = subProject.getBuild().getDirectory();
162
File reportsDirectory = new File( buildDir + "/surefire-reports" );
163
reportsDirectoryList.add( reportsDirectory );
165
reportsDirectories = (File[]) reportsDirectoryList.toArray( new File[0] );
170
if ( reportsDirectories == null )
172
reportsDirectories = new File[] { new File( project.getBuild().getDirectory() + "/surefire-reports" ) };
177
SurefireReportGenerator report =
178
new SurefireReportGenerator( reportsDirectories, locale, showSuccess, determineXrefLocation() );
180
report.doGenerateReport( getBundle( locale ), getSink() );
183
private String determineXrefLocation()
185
String location = null;
189
String relativePath = PathTool.getRelativePath( getOutputDirectory(), xrefLocation.getAbsolutePath() );
190
if ( StringUtils.isEmpty( relativePath ) )
194
relativePath = relativePath + "/" + xrefLocation.getName();
195
if ( xrefLocation.exists() )
197
// XRef was already generated by manual execution of a lifecycle binding
198
location = relativePath;
202
// Not yet generated - check if the report is on its way
203
for ( Iterator reports = project.getReportPlugins().iterator(); reports.hasNext(); )
205
ReportPlugin report = (ReportPlugin) reports.next();
207
String artifactId = report.getArtifactId();
208
if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) )
210
location = relativePath;
215
if ( location == null )
217
getLog().warn( "Unable to locate Test Source XRef to link to - DISABLED" );
223
public String getName( Locale locale )
225
return getBundle( locale ).getString( "report.surefire.name" );
228
public String getDescription( Locale locale )
230
return getBundle( locale ).getString( "report.surefire.description" );
233
protected SiteRenderer getSiteRenderer()
238
protected MavenProject getProject()
243
public String getOutputName()
248
protected String getOutputDirectory()
250
return outputDirectory.getAbsolutePath();
253
private ResourceBundle getBundle( Locale locale )
255
return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() );