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.Arrays;
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Locale;
25  import java.util.Set;
26  
27  import org.apache.maven.doxia.sink.Sink;
28  import org.apache.maven.model.CiManagement;
29  import org.apache.maven.model.Model;
30  import org.apache.maven.model.Notifier;
31  import org.apache.maven.plugins.annotations.Mojo;
32  import org.apache.maven.reporting.MavenReportException;
33  import org.codehaus.plexus.i18n.I18N;
34  
35  /**
36   * Generates the Project Continuous Integration Management report.
37   *
38   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
39   * @since 2.0
40   */
41  @Mojo(name = "ci-management")
42  public class CiManagementReport extends AbstractProjectInfoReport {
43      // ----------------------------------------------------------------------
44      // Public methods
45      // ----------------------------------------------------------------------
46  
47      @Override
48      public boolean canGenerateReport() throws MavenReportException {
49          boolean result = super.canGenerateReport();
50          if (result && skipEmptyReport) {
51              CiManagement cim = getProject().getModel().getCiManagement();
52              result = cim != null;
53          }
54  
55          return result;
56      }
57  
58      @Override
59      public void executeReport(Locale locale) {
60          CiManagementRenderer r =
61                  new CiManagementRenderer(getSink(), getProject().getModel(), getI18N(locale), locale);
62  
63          r.render();
64      }
65  
66      /** {@inheritDoc} */
67      public String getOutputName() {
68          return "ci-management";
69      }
70  
71      @Override
72      protected String getI18Nsection() {
73          return "ci-management";
74      }
75  
76      // ----------------------------------------------------------------------
77      // Private
78      // ----------------------------------------------------------------------
79  
80      /**
81       * Internal renderer class
82       */
83      private static class CiManagementRenderer extends AbstractProjectInfoRenderer {
84  
85          private static final Set<String> SYSTEMS = new HashSet<>(Arrays.asList(
86                  "anthill",
87                  "bamboo",
88                  "buildforge",
89                  "continuum",
90                  "cruisecontrol",
91                  "github",
92                  "hudson",
93                  "jenkins",
94                  "luntbuild",
95                  "teamcity",
96                  "travis"));
97  
98          private Model model;
99  
100         CiManagementRenderer(Sink sink, Model model, I18N i18n, Locale locale) {
101             super(sink, i18n, locale);
102 
103             this.model = model;
104         }
105 
106         @Override
107         protected String getI18Nsection() {
108             return "ci-management";
109         }
110 
111         @Override
112         protected void renderBody() {
113             CiManagement cim = model.getCiManagement();
114             if (cim == null) {
115                 startSection(getTitle());
116 
117                 paragraph(getI18nString("nocim"));
118 
119                 endSection();
120 
121                 return;
122             }
123 
124             String system = cim.getSystem();
125             String url = cim.getUrl();
126             List<Notifier> notifiers = cim.getNotifiers();
127 
128             // Overview
129             startSection(getI18nString("overview.title"));
130 
131             sink.paragraph();
132             linkPatternedText(getIntroForCiManagementSystem(system));
133             sink.paragraph_();
134 
135             endSection();
136 
137             // Access
138             startSection(getI18nString("access"));
139 
140             if (!(url == null || url.isEmpty())) {
141                 paragraph(getI18nString("url"));
142 
143                 verbatimLink(url, url);
144             } else {
145                 paragraph(getI18nString("nourl"));
146             }
147 
148             endSection();
149 
150             // Notifiers
151             startSection(getI18nString("notifiers.title"));
152 
153             if (notifiers == null || notifiers.isEmpty()) {
154                 paragraph(getI18nString("notifiers.nolist"));
155             } else {
156                 sink.paragraph();
157                 sink.text(getI18nString("notifiers.intro"));
158                 sink.paragraph_();
159 
160                 startTable();
161 
162                 String type = getI18nString("notifiers.column.type");
163                 String address = getI18nString("notifiers.column.address");
164                 String configuration = getI18nString("notifiers.column.configuration");
165 
166                 tableHeader(new String[] {type, address, configuration});
167 
168                 for (Notifier notifier : notifiers) {
169                     tableRow(new String[] {
170                         notifier.getType(),
171                         createLinkPatternedText(notifier.getAddress(), notifier.getAddress()),
172                         propertiesToString(notifier.getConfiguration())
173                     });
174                 }
175 
176                 endTable();
177             }
178 
179             endSection();
180         }
181 
182         /**
183          * Search system description.
184          *
185          * @param system a system for description
186          * @return system description from properties
187          */
188         private String getIntroForCiManagementSystem(String system) {
189             if (system == null || system.isEmpty()) {
190                 return getI18nString("general.intro");
191             }
192 
193             String systemLowerCase = system.toLowerCase(Locale.ENGLISH);
194 
195             for (String systemName : SYSTEMS) {
196                 if (systemLowerCase.startsWith(systemName)) {
197                     return getI18nString(systemName + ".intro");
198                 }
199             }
200 
201             return getI18nString("general.intro");
202         }
203     }
204 }