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