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.reporting.AbstractMavenReportRenderer;
27  import org.codehaus.plexus.i18n.I18N;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Locale;
33  
34  /**
35   * Generates the Project Continuous Integration System report.
36   *
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
38   * @version $Id: CimReport.java 728546 2008-12-21 22:56:51Z bentmann $
39   * @since 2.0
40   * @goal cim
41   */
42  public class CimReport
43      extends AbstractProjectInfoReport
44  {
45      // ----------------------------------------------------------------------
46      // Public methods
47      // ----------------------------------------------------------------------
48  
49      /** {@inheritDoc} */
50      public String getName( Locale locale )
51      {
52          return i18n.getString( "project-info-report", locale, "report.cim.name" );
53      }
54  
55      /** {@inheritDoc} */
56      public String getDescription( Locale locale )
57      {
58          return i18n.getString( "project-info-report", locale, "report.cim.description" );
59      }
60  
61      /** {@inheritDoc} */
62      public void executeReport( Locale locale )
63      {
64          CimRenderer r = new CimRenderer( getSink(), getProject().getModel(), i18n, locale );
65  
66          r.render();
67      }
68  
69      /** {@inheritDoc} */
70      public String getOutputName()
71      {
72          return "integration";
73      }
74  
75      // ----------------------------------------------------------------------
76      // Private
77      // ----------------------------------------------------------------------
78  
79      /**
80       * Internal renderer class
81       */
82      private static class CimRenderer
83          extends AbstractMavenReportRenderer
84      {
85          private Model model;
86  
87          private I18N i18n;
88  
89          private Locale locale;
90  
91          CimRenderer( Sink sink, Model model, I18N i18n, Locale locale )
92          {
93              super( sink );
94  
95              this.model = model;
96  
97              this.i18n = i18n;
98  
99              this.locale = locale;
100         }
101 
102         /** {@inheritDoc} */
103         public String getTitle()
104         {
105             return i18n.getString( "project-info-report", locale, "report.cim.title" );
106         }
107 
108         /** {@inheritDoc} */
109         public void renderBody()
110         {
111             CiManagement cim = model.getCiManagement();
112             if ( cim == null )
113             {
114                 startSection( getTitle() );
115 
116                 paragraph( i18n.getString( "project-info-report", locale, "report.cim.nocim" ) );
117 
118                 endSection();
119 
120                 return;
121             }
122 
123             String system = cim.getSystem();
124             String url = cim.getUrl();
125             List notifiers = cim.getNotifiers();
126 
127             // Overview
128             startSection( i18n.getString( "project-info-report", locale, "report.cim.overview.title" ) );
129 
130             if ( isCimSystem( system, "anthill" ) )
131             {
132                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.anthill.intro" ) );
133             }
134             else if ( isCimSystem( system, "buildforge" ) )
135             {
136                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.buildforge.intro" ) );
137             }
138             else if ( isCimSystem( system, "continuum" ) )
139             {
140                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.continuum.intro" ) );
141             }
142             else if ( isCimSystem( system, "cruisecontrol" ) )
143             {
144                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.cruisecontrol.intro" ) );
145             }
146             else if ( isCimSystem( system, "hudson" ) )
147             {
148                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.hudson.intro" ) );
149             }
150             else if ( isCimSystem( system, "luntbuild" ) )
151             {
152                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.luntbuild.intro" ) );
153             }
154             else
155             {
156                 linkPatternedText( i18n.getString( "project-info-report", locale, "report.cim.general.intro" ) );
157             }
158 
159             endSection();
160 
161             // Access
162             startSection( i18n.getString( "project-info-report", locale, "report.cim.access" ) );
163 
164             if ( !StringUtils.isEmpty( url ) )
165             {
166                 paragraph( i18n.getString( "project-info-report", locale, "report.cim.url" ) );
167 
168                 verbatimLink( url, url );
169             }
170             else
171             {
172                 paragraph( i18n.getString( "project-info-report", locale, "report.cim.nourl" ) );
173             }
174 
175             endSection();
176 
177             // Notifiers
178             startSection( i18n.getString( "project-info-report", locale, "report.cim.notifiers.title" ) );
179 
180             if ( notifiers == null || notifiers.isEmpty() )
181             {
182                 paragraph( i18n.getString( "project-info-report", locale, "report.cim.notifiers.nolist" ) );
183             }
184             else
185             {
186                 sink.paragraph();
187                 sink.text( i18n.getString( "project-info-report", locale, "report.cim.notifiers.intro" ) );
188                 sink.paragraph_();
189 
190                 startTable();
191 
192                 String type = i18n.getString( "project-info-report", locale, "report.cim.notifiers.column.type" );
193                 String address = i18n.getString( "project-info-report", locale, "report.cim.notifiers.column.address" );
194                 String configuration =
195                     i18n.getString( "project-info-report", locale, "report.cim.notifiers.column.configuration" );
196 
197                 tableHeader( new String[]{type, address, configuration} );
198 
199                 for ( Iterator i = notifiers.iterator(); i.hasNext(); )
200                 {
201                     Notifier notifier = (Notifier) i.next();
202 
203                     tableRow( new String[]{notifier.getType(),
204                         createLinkPatternedText( notifier.getAddress(), notifier.getAddress() ),
205                         propertiesToString( notifier.getConfiguration() )} );
206                 }
207 
208                 endTable();
209             }
210 
211             endSection();
212         }
213 
214         /**
215          * Checks if a CIM system is bugzilla, continium...
216          *
217          * @param connection
218          * @param cim
219          * @return true if the CIM system is bugzilla, continium..., false otherwise.
220          */
221         private boolean isCimSystem( String connection, String cim )
222         {
223             if ( StringUtils.isEmpty( connection ) )
224             {
225                 return false;
226             }
227 
228             if ( StringUtils.isEmpty( cim ) )
229             {
230                 return false;
231             }
232 
233             return connection.toLowerCase( Locale.ENGLISH ).startsWith( cim.toLowerCase( Locale.ENGLISH ) );
234         }
235     }
236 }