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