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 System report.
35   *
36   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
37   * @version $Id: CimReport.html 935177 2015-01-05 21:05:55Z michaelo $
38   * @since 2.0
39   */
40  @Mojo( name = "cim" )
41  public class CimReport
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          CimRenderer r = new CimRenderer( getSink(), getProject().getModel(), getI18N( locale ), locale );
65  
66          r.render();
67      }
68  
69      /** {@inheritDoc} */
70      public String getOutputName()
71      {
72          return "integration";
73      }
74  
75      @Override
76      protected String getI18Nsection()
77      {
78          return "cim";
79      }
80  
81      // ----------------------------------------------------------------------
82      // Private
83      // ----------------------------------------------------------------------
84  
85      /**
86       * Internal renderer class
87       */
88      private static class CimRenderer
89          extends AbstractProjectInfoRenderer
90      {
91          private Model model;
92  
93          CimRenderer( Sink sink, Model model, I18N i18n, Locale locale )
94          {
95              super( sink, i18n, locale );
96  
97              this.model = model;
98          }
99  
100         @Override
101         protected String getI18Nsection()
102         {
103             return "cim";
104         }
105 
106         @Override
107         public void renderBody()
108         {
109             CiManagement cim = model.getCiManagement();
110             if ( cim == null )
111             {
112                 startSection( getTitle() );
113 
114                 paragraph( getI18nString( "nocim" ) );
115 
116                 endSection();
117 
118                 return;
119             }
120 
121             String system = cim.getSystem();
122             String url = cim.getUrl();
123             List<Notifier> notifiers = cim.getNotifiers();
124 
125             // Overview
126             startSection( getI18nString( "overview.title" ) );
127 
128             sink.paragraph();
129             if ( isCimSystem( system, "anthill" ) )
130             {
131                 linkPatternedText( getI18nString( "anthill.intro" ) );
132             }
133             else if ( isCimSystem( system, "bamboo" ) )
134             {
135                 linkPatternedText( getI18nString( "bamboo.intro" ) );
136             }
137             else if ( isCimSystem( system, "buildforge" ) )
138             {
139                 linkPatternedText( getI18nString( "buildforge.intro" ) );
140             }
141             else if ( isCimSystem( system, "continuum" ) )
142             {
143                 linkPatternedText( getI18nString( "continuum.intro" ) );
144             }
145             else if ( isCimSystem( system, "cruisecontrol" ) )
146             {
147                 linkPatternedText( getI18nString( "cruisecontrol.intro" ) );
148             }
149             else if ( isCimSystem( system, "hudson" ) )
150             {
151                 linkPatternedText( getI18nString( "hudson.intro" ) );
152             }
153             else if ( isCimSystem( system, "jenkins" ) )
154             {
155                 linkPatternedText( getI18nString( "jenkins.intro" ) );
156             }
157             else if ( isCimSystem( system, "luntbuild" ) )
158             {
159                 linkPatternedText( getI18nString( "luntbuild.intro" ) );
160             }
161             else if ( isCimSystem( system, "travis" ) )
162             {
163                 linkPatternedText( getI18nString( "travis.intro" ) );
164             }
165             else
166             {
167                 linkPatternedText( getI18nString( "general.intro" ) );
168             }
169             sink.paragraph_();
170 
171             endSection();
172 
173             // Access
174             startSection( getI18nString( "access" ) );
175 
176             if ( !StringUtils.isEmpty( url ) )
177             {
178                 paragraph( getI18nString( "url" ) );
179 
180                 verbatimLink( url, url );
181             }
182             else
183             {
184                 paragraph( getI18nString( "nourl" ) );
185             }
186 
187             endSection();
188 
189             // Notifiers
190             startSection( getI18nString( "notifiers.title" ) );
191 
192             if ( notifiers == null || notifiers.isEmpty() )
193             {
194                 paragraph( getI18nString( "notifiers.nolist" ) );
195             }
196             else
197             {
198                 sink.paragraph();
199                 sink.text( getI18nString( "notifiers.intro" ) );
200                 sink.paragraph_();
201 
202                 startTable();
203 
204                 String type = getI18nString( "notifiers.column.type" );
205                 String address = getI18nString( "notifiers.column.address" );
206                 String configuration = getI18nString( "notifiers.column.configuration" );
207 
208                 tableHeader( new String[]{type, address, configuration} );
209 
210                 for ( Notifier notifier : notifiers )
211                 {
212                     tableRow( new String[]{notifier.getType(),
213                         createLinkPatternedText( notifier.getAddress(), notifier.getAddress() ),
214                         propertiesToString( notifier.getConfiguration() )} );
215                 }
216 
217                 endTable();
218             }
219 
220             endSection();
221         }
222 
223         /**
224          * Checks if a CIM system is bugzilla, continuum...
225          *
226          * @param connection
227          * @param cim
228          * @return true if the CIM system is bugzilla, continuum..., false otherwise.
229          */
230         private boolean isCimSystem( String connection, String cim )
231         {
232             if ( StringUtils.isEmpty( connection ) )
233             {
234                 return false;
235             }
236 
237             if ( StringUtils.isEmpty( cim ) )
238             {
239                 return false;
240             }
241 
242             return connection.toLowerCase( Locale.ENGLISH ).startsWith( cim.toLowerCase( Locale.ENGLISH ) );
243         }
244     }
245 }