View Javadoc

1   package org.apache.maven.report.projectinfo;
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 org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.model.IssueManagement;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.reporting.AbstractMavenReportRenderer;
26  import org.codehaus.plexus.i18n.I18N;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.util.Locale;
30  
31  /**
32   * Generates the Project Issue Tracking report.
33   *
34   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
35   * @version $Id: IssueTrackingReport.java 728546 2008-12-21 22:56:51Z bentmann $
36   * @since 2.0
37   * @goal issue-tracking
38   */
39  public class IssueTrackingReport
40      extends AbstractProjectInfoReport
41  {
42      // ----------------------------------------------------------------------
43      // Public methods
44      // ----------------------------------------------------------------------
45  
46      /** {@inheritDoc} */
47      public String getName( Locale locale )
48      {
49          return i18n.getString( "project-info-report", locale, "report.issuetracking.name" );
50      }
51  
52      /** {@inheritDoc} */
53      public String getDescription( Locale locale )
54      {
55          return i18n.getString( "project-info-report", locale, "report.issuetracking.description" );
56      }
57  
58      /** {@inheritDoc} */
59      public void executeReport( Locale locale )
60      {
61          IssueTrackingRenderer r = new IssueTrackingRenderer( getSink(), getProject().getModel(), i18n, locale );
62  
63          r.render();
64      }
65  
66      /** {@inheritDoc} */
67      public String getOutputName()
68      {
69          return "issue-tracking";
70      }
71  
72      // ----------------------------------------------------------------------
73      // Private
74      // ----------------------------------------------------------------------
75  
76      /**
77       * Internal renderer class
78       */
79      private static class IssueTrackingRenderer
80          extends AbstractMavenReportRenderer
81      {
82          private Model model;
83  
84          private I18N i18n;
85  
86          private Locale locale;
87  
88          IssueTrackingRenderer( Sink sink, Model model, I18N i18n, Locale locale )
89          {
90              super( sink );
91  
92              this.model = model;
93  
94              this.i18n = i18n;
95  
96              this.locale = locale;
97          }
98  
99          /** {@inheritDoc} */
100         public String getTitle()
101         {
102             return i18n.getString( "project-info-report", locale, "report.issuetracking.title" );
103         }
104 
105         /** {@inheritDoc} */
106         public void renderBody()
107         {
108             IssueManagement issueManagement = model.getIssueManagement();
109             if ( issueManagement == null )
110             {
111                 startSection( getTitle() );
112 
113                 paragraph( i18n.getString( "project-info-report", locale, "report.issuetracking.noissueManagement" ) );
114 
115                 endSection();
116 
117                 return;
118             }
119 
120             String system = issueManagement.getSystem();
121             String url = issueManagement.getUrl();
122 
123             // Overview
124             startSection( i18n.getString( "project-info-report", locale, "report.issuetracking.overview.title" ) );
125 
126             if ( isIssueManagementSystem( system, "jira" ) )
127             {
128                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.issuetracking.jira.intro" ) );
129             }
130             else if ( isIssueManagementSystem( system, "bugzilla" ) )
131             {
132                 linkPatternedText(
133                     i18n.getString( "project-info-report", locale, "report.issuetracking.bugzilla.intro" ) );
134             }
135             else if ( isIssueManagementSystem( system, "scarab" ) )
136             {
137                 linkPatternedText(
138                     i18n.getString( "project-info-report", locale, "report.issuetracking.scarab.intro" ) );
139             }
140             else if ( system == null || "".equals( system.trim() ) )
141             {
142                 paragraph( i18n.getString( "project-info-report", locale, "report.issuetracking.general.intro" ) );
143             }
144             else
145             {
146                 paragraph(
147                     i18n.getString( "project-info-report", locale, "report.issuetracking.custom.intro" ).replaceFirst(
148                         "%issueManagementSystem%", system ) );
149             }
150 
151             endSection();
152 
153             // Connection
154             startSection( getTitle() );
155 
156             paragraph( i18n.getString( "project-info-report", locale, "report.issuetracking.intro" ) );
157 
158             verbatimLink( url, url );
159 
160             endSection();
161         }
162 
163         /**
164          * Checks if a issue management system is Jira, bugzilla...
165          *
166          * @param system
167          * @param im
168          * @return true if the issue management system is Jira, bugzilla, false otherwise.
169          */
170         private boolean isIssueManagementSystem( String system, String im )
171         {
172             if ( StringUtils.isEmpty( system ) )
173             {
174                 return false;
175             }
176 
177             if ( StringUtils.isEmpty( im ) )
178             {
179                 return false;
180             }
181 
182             return system.toLowerCase( Locale.ENGLISH ).startsWith( im.toLowerCase( Locale.ENGLISH ) );
183         }
184     }
185 }