001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.mavenplugins.testsuite.report;
017:
018: import org.apache.maven.artifact.handler.ArtifactHandler;
019: import org.apache.maven.model.ReportPlugin;
020: import org.apache.maven.project.MavenProject;
021: import org.apache.maven.reporting.AbstractMavenReport;
022: import org.apache.maven.reporting.MavenReportException;
023: import org.codehaus.doxia.site.renderer.SiteRenderer;
024: import org.codehaus.plexus.util.PathTool;
025: import org.codehaus.plexus.util.StringUtils;
026:
027: import java.io.File;
028: import java.util.Iterator;
029: import java.util.Locale;
030: import java.util.ResourceBundle;
031:
032: /**
033: * Creates a nicely formatted Surefire Test Report in html format.
034: *
035: * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
036: * @version $Id: SurefireReportMojo.java 514085 2007-03-03 06:09:54Z jdillon $
037: * @goal generate-surefire-report
038: */
039: public class SurefireReportMojo extends AbstractMavenReport {
040: /**
041: * Location where generated html will be created.
042: *
043: * @parameter expression="${project.build.directory}/site"
044: */
045: private String outputDirectory;
046:
047: /**
048: * Doxia Site Renderer
049: *
050: * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
051: * @required @readonly
052: */
053: private SiteRenderer siteRenderer;
054:
055: /**
056: * Maven Project
057: *
058: * @parameter expression="${project}"
059: * @required @readonly
060: */
061: private MavenProject project;
062:
063: /**
064: * If set to false, only failures are shown.
065: *
066: * @parameter expression="${showSuccess}" default-value="true"
067: * @required
068: */
069: private boolean showSuccess;
070:
071: /**
072: * This directory contains the XML Report files that will be parsed and rendered to HTML format.
073: *
074: * @parameter expression="${project.build.directory}/surefire-reports"
075: * @required
076: */
077: private File reportsDirectory;
078:
079: /**
080: * The filename to use for the report.
081: *
082: * @parameter expression="${outputName}" default-value="surefire-report"
083: * @required
084: */
085: private String outputName;
086:
087: /**
088: * Location of the Xrefs to link.
089: *
090: * @parameter default-value="${project.reporting.outputDirectory}/xref-test"
091: */
092: private File xrefLocation;
093:
094: /**
095: * Whether to link the XRef if found.
096: *
097: * @parameter expression="${linkXRef}" default-value="true"
098: */
099: private boolean linkXRef;
100:
101: public void executeReport(Locale locale)
102: throws MavenReportException {
103: /*
104: if ( !"pom".equalsIgnoreCase(project.getPackaging()) ) {
105: System.out.println("Not a pom packaging.");
106: return;
107: }
108: */
109:
110: SurefireReportGenerator report = new SurefireReportGenerator(
111: reportsDirectory, locale, showSuccess,
112: determineXrefLocation());
113:
114: report.doGenerateReport(getBundle(locale), getSink());
115:
116: System.out.println("surefire-report.html generated.");
117: }
118:
119: private String determineXrefLocation() {
120: String location = null;
121:
122: if (linkXRef) {
123: String relativePath = PathTool.getRelativePath(
124: outputDirectory, xrefLocation.getAbsolutePath());
125: if (StringUtils.isEmpty(relativePath)) {
126: relativePath = ".";
127: }
128: relativePath = relativePath + "/" + xrefLocation.getName();
129: if (xrefLocation.exists()) {
130: // XRef was already generated by manual execution of a lifecycle binding
131: location = relativePath;
132: } else {
133: // Not yet generated - check if the report is on its way
134: for (Iterator reports = project.getReportPlugins()
135: .iterator(); reports.hasNext();) {
136: ReportPlugin report = (ReportPlugin) reports.next();
137:
138: String artifactId = report.getArtifactId();
139: if ("maven-jxr-plugin".equals(artifactId)
140: || "jxr-maven-plugin".equals(artifactId)) {
141: location = relativePath;
142: }
143: }
144: }
145:
146: if (location == null) {
147: getLog()
148: .warn(
149: "Unable to locate Test Source XRef to link to - DISABLED");
150: }
151: }
152: return location;
153: }
154:
155: public String getName(Locale locale) {
156: return getBundle(locale).getString("report.surefire.name");
157: }
158:
159: public String getDescription(Locale locale) {
160: return getBundle(locale).getString(
161: "report.surefire.description");
162: }
163:
164: protected SiteRenderer getSiteRenderer() {
165: return siteRenderer;
166: }
167:
168: protected MavenProject getProject() {
169: return project;
170: }
171:
172: public String getOutputName() {
173: return outputName;
174: }
175:
176: protected String getOutputDirectory() {
177: return outputDirectory;
178: }
179:
180: private ResourceBundle getBundle(Locale locale) {
181: return ResourceBundle.getBundle("surefire-report", locale, this
182: .getClass().getClassLoader());
183: }
184:
185: /**
186: * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
187: */
188: public boolean canGenerateReport() {
189: // Only execute reports for "pom" projects
190: return "pom".equalsIgnoreCase(project.getPackaging());
191: }
192: }
|