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