View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.report.projectinfo;
20  
21  import java.util.Locale;
22  
23  import org.apache.maven.doxia.sink.Sink;
24  import org.apache.maven.model.IssueManagement;
25  import org.apache.maven.model.Model;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.reporting.MavenReportException;
28  import org.codehaus.plexus.i18n.I18N;
29  
30  /**
31   * Generates the Project Issue Management report.
32   *
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
34   * @since 2.0
35   */
36  @Mojo(name = "issue-management")
37  public class IssueManagementReport extends AbstractProjectInfoReport {
38      // ----------------------------------------------------------------------
39      // Public methods
40      // ----------------------------------------------------------------------
41  
42      @Override
43      public boolean canGenerateReport() throws MavenReportException {
44          boolean result = super.canGenerateReport();
45          if (result && skipEmptyReport) {
46              result = getProject().getModel().getIssueManagement() != null;
47          }
48  
49          return result;
50      }
51  
52      @Override
53      public void executeReport(Locale locale) {
54          IssueManagementRenderer r =
55                  new IssueManagementRenderer(getSink(), getProject().getModel(), getI18N(locale), locale);
56  
57          r.render();
58      }
59  
60      /** {@inheritDoc} */
61      public String getOutputName() {
62          return "issue-management";
63      }
64  
65      @Override
66      protected String getI18Nsection() {
67          return "issue-management";
68      }
69  
70      // ----------------------------------------------------------------------
71      // Private
72      // ----------------------------------------------------------------------
73  
74      /**
75       * Internal renderer class
76       */
77      private static class IssueManagementRenderer extends AbstractProjectInfoRenderer {
78          private Model model;
79  
80          IssueManagementRenderer(Sink sink, Model model, I18N i18n, Locale locale) {
81              super(sink, i18n, locale);
82  
83              this.model = model;
84          }
85  
86          @Override
87          protected String getI18Nsection() {
88              return "issue-management";
89          }
90  
91          @Override
92          protected void renderBody() {
93              IssueManagement issueManagement = model.getIssueManagement();
94              if (issueManagement == null) {
95                  startSection(getTitle());
96  
97                  paragraph(getI18nString("noissueManagement"));
98  
99                  endSection();
100 
101                 return;
102             }
103 
104             String system = issueManagement.getSystem();
105             String url = issueManagement.getUrl();
106 
107             // Overview
108             startSection(getI18nString("overview.title"));
109 
110             if (isIssueManagementSystem(system, "jira")) {
111                 sink.paragraph();
112                 linkPatternedText(getI18nString("jira.intro"));
113                 sink.paragraph_();
114             } else if (isIssueManagementSystem(system, "bugzilla")) {
115                 sink.paragraph();
116                 linkPatternedText(getI18nString("bugzilla.intro"));
117                 sink.paragraph_();
118             } else if (isIssueManagementSystem(system, "scarab")) {
119                 sink.paragraph();
120                 linkPatternedText(getI18nString("scarab.intro"));
121                 sink.paragraph_();
122             } else if (system == null || "".equals(system.trim())) {
123                 paragraph(getI18nString("general.intro"));
124             } else {
125                 paragraph(getI18nString("custom.intro").replaceFirst("%issueManagementSystem%", system));
126             }
127 
128             endSection();
129 
130             // Connection
131             startSection(getTitle());
132 
133             paragraph(getI18nString("intro"));
134 
135             verbatimLink(url, url);
136 
137             endSection();
138         }
139 
140         /**
141          * Checks if a issue management system is Jira, bugzilla...
142          *
143          * @param system
144          * @param actual
145          * @return true if the issue management system is Jira, bugzilla, false otherwise.
146          */
147         private boolean isIssueManagementSystem(String system, String actual) {
148             if (system == null || system.isEmpty()) {
149                 return false;
150             }
151 
152             if (actual == null || actual.isEmpty()) {
153                 return false;
154             }
155 
156             return system.toLowerCase(Locale.ENGLISH).startsWith(actual.toLowerCase(Locale.ENGLISH));
157         }
158     }
159 }