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