KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mavenplugins > testsuite > report > SurefireReportMojo


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17  
18 package org.apache.geronimo.mavenplugins.testsuite.report;
19
20 import org.apache.maven.artifact.handler.ArtifactHandler;
21 import org.apache.maven.model.ReportPlugin;
22 import org.apache.maven.project.MavenProject;
23 import org.apache.maven.reporting.AbstractMavenReport;
24 import org.apache.maven.reporting.MavenReportException;
25 import org.codehaus.doxia.site.renderer.SiteRenderer;
26 import org.codehaus.plexus.util.PathTool;
27 import org.codehaus.plexus.util.StringUtils;
28
29 import java.io.File JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Locale JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33
34
35 /**
36  * Creates a nicely formatted Surefire Test Report in html format.
37  *
38  * @author <a HREF="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
39  * @version $Id: SurefireReportMojo.java 433277 2006-08-21 16:28:06Z vsiveton $
40  * @goal generate-surefire-report
41  */

42 public class SurefireReportMojo
43     extends AbstractMavenReport
44 {
45     /**
46      * Location where generated html will be created.
47      *
48      * @parameter expression="${project.build.directory}/site"
49      */

50     private String JavaDoc outputDirectory;
51
52     /**
53      * Doxia Site Renderer
54      *
55      * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
56      * @required @readonly
57      */

58     private SiteRenderer siteRenderer;
59
60     /**
61      * Maven Project
62      *
63      * @parameter expression="${project}"
64      * @required @readonly
65      */

66     private MavenProject project;
67
68     /**
69      * If set to false, only failures are shown.
70      *
71      * @parameter expression="${showSuccess}" default-value="true"
72      * @required
73      */

74     private boolean showSuccess;
75
76     /**
77      * This directory contains the XML Report files that will be parsed and rendered to HTML format.
78      *
79      * @parameter expression="${project.build.directory}/surefire-reports"
80      * @required
81      */

82     private File JavaDoc reportsDirectory;
83
84     /**
85      * The filename to use for the report.
86      *
87      * @parameter expression="${outputName}" default-value="surefire-report"
88      * @required
89      */

90     private String JavaDoc outputName;
91
92     /**
93      * Location of the Xrefs to link.
94      *
95      * @parameter default-value="${project.reporting.outputDirectory}/xref-test"
96      */

97     private File JavaDoc xrefLocation;
98
99     /**
100      * Whether to link the XRef if found.
101      *
102      * @parameter expression="${linkXRef}" default-value="true"
103      */

104     private boolean linkXRef;
105
106     public void executeReport( Locale JavaDoc locale )
107         throws MavenReportException
108     {
109         /*
110         if ( !"pom".equalsIgnoreCase(project.getPackaging()) ) {
111             System.out.println("Not a pom packaging.");
112             return;
113         }
114         */

115
116         SurefireReportGenerator report =
117             new SurefireReportGenerator( reportsDirectory, locale, showSuccess, determineXrefLocation() );
118
119         report.doGenerateReport( getBundle( locale ), getSink() );
120
121         System.out.println("surefire-report.html generated.");
122     }
123
124     private String JavaDoc determineXrefLocation()
125     {
126         String JavaDoc location = null;
127
128         if ( linkXRef )
129         {
130             String JavaDoc relativePath = PathTool.getRelativePath( outputDirectory, xrefLocation.getAbsolutePath() );
131             if ( StringUtils.isEmpty( relativePath ) )
132             {
133                 relativePath = ".";
134             }
135             relativePath = relativePath + "/" + xrefLocation.getName();
136             if ( xrefLocation.exists() )
137             {
138                 // XRef was already generated by manual execution of a lifecycle binding
139
location = relativePath;
140             }
141             else
142             {
143                 // Not yet generated - check if the report is on its way
144
for ( Iterator JavaDoc reports = project.getReportPlugins().iterator(); reports.hasNext(); )
145                 {
146                     ReportPlugin report = (ReportPlugin) reports.next();
147
148                     String JavaDoc artifactId = report.getArtifactId();
149                     if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) )
150                     {
151                         location = relativePath;
152                     }
153                 }
154             }
155
156             if ( location == null )
157             {
158                 getLog().warn( "Unable to locate Test Source XRef to link to - DISABLED" );
159             }
160         }
161         return location;
162     }
163
164     public String JavaDoc getName( Locale JavaDoc locale )
165     {
166         return getBundle( locale ).getString( "report.surefire.name" );
167     }
168
169     public String JavaDoc getDescription( Locale JavaDoc locale )
170     {
171         return getBundle( locale ).getString( "report.surefire.description" );
172     }
173
174     protected SiteRenderer getSiteRenderer()
175     {
176         return siteRenderer;
177     }
178
179     protected MavenProject getProject()
180     {
181         return project;
182     }
183
184     public String JavaDoc getOutputName()
185     {
186         return outputName;
187     }
188
189     protected String JavaDoc getOutputDirectory()
190     {
191         return outputDirectory;
192     }
193
194     private ResourceBundle JavaDoc getBundle( Locale JavaDoc locale )
195     {
196         return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() );
197     }
198
199     /**
200      * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
201      */

202     public boolean canGenerateReport()
203     {
204         // Only execute reports for "pom" projects
205
return "pom".equalsIgnoreCase(project.getPackaging());
206     }
207 }
208
Popular Tags