View Javadoc
1   package org.apache.maven.report.projectinfo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.model.CiManagement;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.model.Notifier;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.codehaus.plexus.i18n.I18N;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  import java.util.List;
31  import java.util.Locale;
32  
33  /**
34   * Generates the Project Continuous Integration Management report.
35   *
36   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
37   * @version $Id: CiManagementReport.java 1732680 2016-02-27 23:31:53Z michaelo $
38   * @since 2.0
39   */
40  @Mojo( name = "cim" )
41  public class CiManagementReport
42      extends AbstractProjectInfoReport
43  {
44      // ----------------------------------------------------------------------
45      // Public methods
46      // ----------------------------------------------------------------------
47  
48      @Override
49      public boolean canGenerateReport()
50      {
51           boolean result = super.canGenerateReport();
52           if ( result && skipEmptyReport )
53           {
54               CiManagement cim = getProject().getModel().getCiManagement();
55               result = cim != null ;
56           }
57  
58           return result;
59      }
60  
61      @Override
62      public void executeReport( Locale locale )
63      {
64          CiManagementRenderer r = new CiManagementRenderer( getSink(), getProject().getModel(),
65                                                                getI18N( locale ), locale );
66  
67          r.render();
68      }
69  
70      /** {@inheritDoc} */
71      public String getOutputName()
72      {
73          return "integration";
74      }
75  
76      @Override
77      protected String getI18Nsection()
78      {
79          return "ci-management";
80      }
81  
82      // ----------------------------------------------------------------------
83      // Private
84      // ----------------------------------------------------------------------
85  
86      /**
87       * Internal renderer class
88       */
89      private static class CiManagementRenderer
90          extends AbstractProjectInfoRenderer
91      {
92          private Model model;
93  
94          CiManagementRenderer( Sink sink, Model model, I18N i18n, Locale locale )
95          {
96              super( sink, i18n, locale );
97  
98              this.model = model;
99          }
100 
101         @Override
102         protected String getI18Nsection()
103         {
104             return "ci-management";
105         }
106 
107         @Override
108         public void renderBody()
109         {
110             CiManagement cim = model.getCiManagement();
111             if ( cim == null )
112             {
113                 startSection( getTitle() );
114 
115                 paragraph( getI18nString( "nocim" ) );
116 
117                 endSection();
118 
119                 return;
120             }
121 
122             String system = cim.getSystem();
123             String url = cim.getUrl();
124             List<Notifier> notifiers = cim.getNotifiers();
125 
126             // Overview
127             startSection( getI18nString( "overview.title" ) );
128 
129             sink.paragraph();
130             if ( isCiManagementSystem( system, "anthill" ) )
131             {
132                 linkPatternedText( getI18nString( "anthill.intro" ) );
133             }
134             else if ( isCiManagementSystem( system, "bamboo" ) )
135             {
136                 linkPatternedText( getI18nString( "bamboo.intro" ) );
137             }
138             else if ( isCiManagementSystem( system, "buildforge" ) )
139             {
140                 linkPatternedText( getI18nString( "buildforge.intro" ) );
141             }
142             else if ( isCiManagementSystem( system, "continuum" ) )
143             {
144                 linkPatternedText( getI18nString( "continuum.intro" ) );
145             }
146             else if ( isCiManagementSystem( system, "cruisecontrol" ) )
147             {
148                 linkPatternedText( getI18nString( "cruisecontrol.intro" ) );
149             }
150             else if ( isCiManagementSystem( system, "hudson" ) )
151             {
152                 linkPatternedText( getI18nString( "hudson.intro" ) );
153             }
154             else if ( isCiManagementSystem( system, "jenkins" ) )
155             {
156                 linkPatternedText( getI18nString( "jenkins.intro" ) );
157             }
158             else if ( isCiManagementSystem( system, "luntbuild" ) )
159             {
160                 linkPatternedText( getI18nString( "luntbuild.intro" ) );
161             }
162             else if ( isCiManagementSystem( system, "travis" ) )
163             {
164                 linkPatternedText( getI18nString( "travis.intro" ) );
165             }
166             else
167             {
168                 linkPatternedText( getI18nString( "general.intro" ) );
169             }
170             sink.paragraph_();
171 
172             endSection();
173 
174             // Access
175             startSection( getI18nString( "access" ) );
176 
177             if ( !StringUtils.isEmpty( url ) )
178             {
179                 paragraph( getI18nString( "url" ) );
180 
181                 verbatimLink( url, url );
182             }
183             else
184             {
185                 paragraph( getI18nString( "nourl" ) );
186             }
187 
188             endSection();
189 
190             // Notifiers
191             startSection( getI18nString( "notifiers.title" ) );
192 
193             if ( notifiers == null || notifiers.isEmpty() )
194             {
195                 paragraph( getI18nString( "notifiers.nolist" ) );
196             }
197             else
198             {
199                 sink.paragraph();
200                 sink.text( getI18nString( "notifiers.intro" ) );
201                 sink.paragraph_();
202 
203                 startTable();
204 
205                 String type = getI18nString( "notifiers.column.type" );
206                 String address = getI18nString( "notifiers.column.address" );
207                 String configuration = getI18nString( "notifiers.column.configuration" );
208 
209                 tableHeader( new String[]{type, address, configuration} );
210 
211                 for ( Notifier notifier : notifiers )
212                 {
213                     tableRow( new String[]{notifier.getType(),
214                         createLinkPatternedText( notifier.getAddress(), notifier.getAddress() ),
215                         propertiesToString( notifier.getConfiguration() )} );
216                 }
217 
218                 endTable();
219             }
220 
221             endSection();
222         }
223 
224         /**
225          * Checks if a CI management system is bugzilla, continuum...
226          *
227          * @return true if the CI management system is bugzilla, continuum..., false otherwise.
228          */
229         private boolean isCiManagementSystem( String system, String actual )
230         {
231             if ( StringUtils.isEmpty( system ) )
232             {
233                 return false;
234             }
235 
236             if ( StringUtils.isEmpty( actual ) )
237             {
238                 return false;
239             }
240 
241             return system.toLowerCase( Locale.ENGLISH ).startsWith( actual.toLowerCase( Locale.ENGLISH ) );
242         }
243     }
244 }