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