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