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