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