~ubuntu-branches/ubuntu/precise/surefire/precise

« back to all changes in this revision

Viewing changes to .pc/doxia_1.1.patch/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2011-10-10 20:42:16 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20111010204216-cemva69wkagf4fay
Tags: 2.10-1
* Team upload.
* New upstream release.
* Refresh and remove unneccesary patches.
* Add Build-Depends on libsurefire-java and
  libmaven-common-artifact-filters-java.
* Drop outdated Maven artifact surefire-junit.
* Provide new Maven artifacts: surefire-junit3, maven-surefire-common,
  common-junit3, common-junit4, surefire-junit47 and surefire-testng-utils.
* Fix clean target to allow "two in a row" builds.
* Update Vcs-Browser field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.maven.plugins.surefire.report;
2
 
 
3
 
/*
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
11
 
 *
12
 
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 
 *
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
19
 
 * under the License.
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.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;
36
 
 
37
 
 
38
 
/**
39
 
 * Creates a nicely formatted Surefire Test Report in html format.
40
 
 *
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 $
43
 
 * @goal report
44
 
 * @execute phase="test" lifecycle="surefire"
45
 
 */
46
 
public class SurefireReportMojo
47
 
    extends AbstractMavenReport
48
 
{
49
 
    /**
50
 
     * Location where generated html will be created.
51
 
     *
52
 
     * @parameter expression="${project.reporting.outputDirectory}"
53
 
     */
54
 
    private File outputDirectory;
55
 
 
56
 
    /**
57
 
     * Doxia Site Renderer
58
 
     *
59
 
     * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
60
 
     * @required @readonly
61
 
     */
62
 
    private SiteRenderer siteRenderer;
63
 
 
64
 
    /**
65
 
     * Maven Project
66
 
     *
67
 
     * @parameter expression="${project}"
68
 
     * @required @readonly
69
 
     */
70
 
    private MavenProject project;
71
 
 
72
 
    /**
73
 
     * If set to false, only failures are shown.
74
 
     *
75
 
     * @parameter expression="${showSuccess}" default-value="true"
76
 
     * @required
77
 
     */
78
 
    private boolean showSuccess;
79
 
 
80
 
    /**
81
 
     * Directories containing the XML Report files that will be parsed and rendered to HTML format.
82
 
     *
83
 
     * @parameter
84
 
     */
85
 
    private File[] reportsDirectories;
86
 
 
87
 
    /**
88
 
     * (Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.
89
 
     *
90
 
     * @deprecated
91
 
     * @parameter
92
 
     */
93
 
    private File reportsDirectory;
94
 
 
95
 
    
96
 
    /**
97
 
     * The projects in the reactor for aggregation report.
98
 
     *
99
 
     * @parameter expression="${reactorProjects}"
100
 
     * @readonly
101
 
     */
102
 
    private List reactorProjects;
103
 
    
104
 
    /**
105
 
     * The filename to use for the report.
106
 
     *
107
 
     * @parameter expression="${outputName}" default-value="surefire-report"
108
 
     * @required
109
 
     */
110
 
    private String outputName;
111
 
 
112
 
    /**
113
 
     * Location of the Xrefs to link.
114
 
     *
115
 
     * @parameter default-value="${project.reporting.outputDirectory}/xref-test"
116
 
     */
117
 
    private File xrefLocation;
118
 
 
119
 
    /**
120
 
     * Whether to link the XRef if found.
121
 
     *
122
 
     * @parameter expression="${linkXRef}" default-value="true"
123
 
     */
124
 
    private boolean linkXRef;
125
 
    
126
 
    /**
127
 
     * Whether to build an aggregated report at the root, or build individual reports.
128
 
     *
129
 
     * @parameter expression="${aggregate}" default-value="false"
130
 
     */
131
 
    private boolean aggregate;
132
 
 
133
 
    public void executeReport( Locale locale )
134
 
        throws MavenReportException
135
 
    {
136
 
        if ( reportsDirectory != null )
137
 
        {
138
 
            if ( reportsDirectories == null )
139
 
            {
140
 
                reportsDirectories = new File[] { reportsDirectory };
141
 
            }
142
 
            else
143
 
            {
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;
148
 
            }
149
 
        }
150
 
        if ( aggregate )
151
 
        {
152
 
            if ( !project.isExecutionRoot() ) return;
153
 
            if ( reportsDirectories == null )
154
 
            {
155
 
                ArrayList reportsDirectoryList = new ArrayList(); 
156
 
                // TODO guess the real location
157
 
                for (Iterator i = reactorProjects.iterator(); i.hasNext();)
158
 
                {
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 );
164
 
                }
165
 
                reportsDirectories = (File[]) reportsDirectoryList.toArray( new File[0] );
166
 
            }
167
 
        }
168
 
        else
169
 
        {
170
 
            if ( reportsDirectories == null )
171
 
            {
172
 
                reportsDirectories = new File[] { new File( project.getBuild().getDirectory() + "/surefire-reports" ) };
173
 
            }
174
 
        }
175
 
        
176
 
        
177
 
        SurefireReportGenerator report =
178
 
            new SurefireReportGenerator( reportsDirectories, locale, showSuccess, determineXrefLocation() );
179
 
 
180
 
        report.doGenerateReport( getBundle( locale ), getSink() );
181
 
    }
182
 
 
183
 
    private String determineXrefLocation()
184
 
    {
185
 
        String location = null;
186
 
 
187
 
        if ( linkXRef )
188
 
        {
189
 
            String relativePath = PathTool.getRelativePath( getOutputDirectory(), xrefLocation.getAbsolutePath() );
190
 
            if ( StringUtils.isEmpty( relativePath ) )
191
 
            {
192
 
                relativePath = ".";
193
 
            }
194
 
            relativePath = relativePath + "/" + xrefLocation.getName();
195
 
            if ( xrefLocation.exists() )
196
 
            {
197
 
                // XRef was already generated by manual execution of a lifecycle binding
198
 
                location = relativePath;
199
 
            }
200
 
            else
201
 
            {
202
 
                // Not yet generated - check if the report is on its way
203
 
                for ( Iterator reports = project.getReportPlugins().iterator(); reports.hasNext(); )
204
 
                {
205
 
                    ReportPlugin report = (ReportPlugin) reports.next();
206
 
 
207
 
                    String artifactId = report.getArtifactId();
208
 
                    if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) )
209
 
                    {
210
 
                        location = relativePath;
211
 
                    }
212
 
                }
213
 
            }
214
 
 
215
 
            if ( location == null )
216
 
            {
217
 
                getLog().warn( "Unable to locate Test Source XRef to link to - DISABLED" );
218
 
            }
219
 
        }
220
 
        return location;
221
 
    }
222
 
 
223
 
    public String getName( Locale locale )
224
 
    {
225
 
        return getBundle( locale ).getString( "report.surefire.name" );
226
 
    }
227
 
 
228
 
    public String getDescription( Locale locale )
229
 
    {
230
 
        return getBundle( locale ).getString( "report.surefire.description" );
231
 
    }
232
 
 
233
 
    protected SiteRenderer getSiteRenderer()
234
 
    {
235
 
        return siteRenderer;
236
 
    }
237
 
 
238
 
    protected MavenProject getProject()
239
 
    {
240
 
        return project;
241
 
    }
242
 
 
243
 
    public String getOutputName()
244
 
    {
245
 
        return outputName;
246
 
    }
247
 
 
248
 
    protected String getOutputDirectory()
249
 
    {
250
 
        return outputDirectory.getAbsolutePath();
251
 
    }
252
 
 
253
 
    private ResourceBundle getBundle( Locale locale )
254
 
    {
255
 
        return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() );
256
 
    }
257
 
 
258
 
}