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