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.MailingList;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.reporting.AbstractMavenReportRenderer;
26  import org.codehaus.plexus.i18n.I18N;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.util.ArrayList;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Locale;
33  
34  /**
35   * Generates the Mailing List report.
36   *
37   * @author <a href="mailto:brett@apache.org">Brett Porter </a>
38   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
39   * @version $Id: MailingListsReport.java 728546 2008-12-21 22:56:51Z bentmann $
40   * @since 2.0
41   * @goal mailing-list
42   */
43  public class MailingListsReport
44      extends AbstractProjectInfoReport
45  {
46      // ----------------------------------------------------------------------
47      // Public methods
48      // ----------------------------------------------------------------------
49  
50      /** {@inheritDoc} */
51      public String getName( Locale locale )
52      {
53          return i18n.getString( "project-info-report", locale, "report.mailing-lists.name" );
54      }
55  
56      /** {@inheritDoc} */
57      public String getDescription( Locale locale )
58      {
59          return i18n.getString( "project-info-report", locale, "report.mailing-lists.description" );
60      }
61  
62      /** {@inheritDoc} */
63      public void executeReport( Locale locale )
64      {
65          MailingListsRenderer r = new MailingListsRenderer( getSink(), getProject().getModel(), i18n, locale );
66  
67          r.render();
68      }
69  
70      /** {@inheritDoc} */
71      public String getOutputName()
72      {
73          return "mail-lists";
74      }
75  
76      // ----------------------------------------------------------------------
77      // Private
78      // ----------------------------------------------------------------------
79  
80      /**
81       * Internal renderer class
82       */
83      protected static class MailingListsRenderer
84          extends AbstractMavenReportRenderer
85      {
86          private Model model;
87  
88          private I18N i18n;
89  
90          private Locale locale;
91  
92          private static final String[] EMPTY_STRING_ARRAY = new String[0];
93  
94          MailingListsRenderer( Sink sink, Model model, I18N i18n, Locale locale )
95          {
96              super( sink );
97  
98              this.model = model;
99  
100             this.i18n = i18n;
101 
102             this.locale = locale;
103         }
104 
105         /** {@inheritDoc} */
106         public String getTitle()
107         {
108             return i18n.getString( "project-info-report", locale, "report.mailing-lists.title" );
109         }
110 
111         /** {@inheritDoc} */
112         public void renderBody()
113         {
114             List mailingLists = model.getMailingLists();
115 
116             if ( mailingLists == null || mailingLists.isEmpty() )
117             {
118                 startSection( getTitle() );
119 
120                 // TODO: should the report just be excluded?
121                 paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.nolist" ) );
122 
123                 endSection();
124 
125                 return;
126             }
127 
128             startSection( getTitle() );
129 
130             paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.intro" ) );
131 
132             startTable();
133 
134             // To beautify the display with other archives
135             boolean otherArchives = false;
136             for ( Iterator i = mailingLists.iterator(); i.hasNext(); )
137             {
138                 MailingList m = (MailingList) i.next();
139 
140                 if ( m.getOtherArchives() != null && !m.getOtherArchives().isEmpty() )
141                 {
142                     otherArchives = true;
143                 }
144             }
145 
146             String name = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.name" );
147             String subscribe = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.subscribe" );
148             String unsubscribe =
149                 i18n.getString( "project-info-report", locale, "report.mailing-lists.column.unsubscribe" );
150             String post = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.post" );
151             String archive = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.archive" );
152             String archivesOther =
153                 i18n.getString( "project-info-report", locale, "report.mailing-lists.column.otherArchives" );
154 
155             if ( otherArchives )
156             {
157                 tableHeader( new String[]{name, subscribe, unsubscribe, post, archive, archivesOther} );
158             }
159             else
160             {
161                 tableHeader( new String[]{name, subscribe, unsubscribe, post, archive} );
162             }
163 
164             for ( Iterator i = model.getMailingLists().iterator(); i.hasNext(); )
165             {
166                 MailingList mailingList = (MailingList) i.next();
167 
168                 List textRow = new ArrayList();
169 
170                 // Validate here subsribe/unsubsribe lists and archives?
171                 textRow.add( mailingList.getName() );
172 
173                 textRow.add( createLinkPatternedText( subscribe, mailingList.getSubscribe() ) );
174 
175                 textRow.add( createLinkPatternedText( unsubscribe, mailingList.getUnsubscribe() ) );
176 
177                 if ( mailingList.getPost() != null && mailingList.getPost().length() > 0 )
178                 {
179                     textRow.add( createLinkPatternedText( post, mailingList.getPost() ) );
180                 }
181                 else
182                 {
183                     textRow.add( "-" );
184                 }
185 
186                 if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 )
187                 {
188                     textRow.add( createLinkPatternedText( getArchiveServer( mailingList.getArchive() ),
189                                                           mailingList.getArchive() ) );
190                 }
191                 else
192                 {
193                     textRow.add( "-" );
194                 }
195 
196                 if ( mailingList.getOtherArchives() != null && !mailingList.getOtherArchives().isEmpty() )
197                 {
198                     // For the first line
199                     Iterator it = mailingList.getOtherArchives().iterator();
200                     String otherArchive = it.next().toString();
201 
202                     textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
203 
204                     tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
205 
206                     // Other lines...
207                     while ( it.hasNext() )
208                     {
209                         otherArchive = (String) it.next();
210 
211                         // Reinit the list to beautify the display
212                         textRow = new ArrayList();
213 
214                         // Name
215                         textRow.add( " " );
216 
217                         // Subscribe
218                         textRow.add( " " );
219 
220                         // UnSubscribe
221                         textRow.add( " " );
222 
223                         // Post
224                         textRow.add( " " );
225 
226                         // Archive
227                         textRow.add( " " );
228 
229                         textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
230 
231                         tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
232                     }
233                 }
234                 else
235                 {
236                     if ( otherArchives )
237                     {
238                         textRow.add( null );
239                     }
240 
241                     tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
242                 }
243             }
244 
245             endTable();
246 
247             endSection();
248         }
249 
250         /**
251          * Convenience method to return the name of a web-based mailing list archive
252          * server. <br>
253          * For instance, if the archive uri is
254          * <code>http://www.mail-archive.com/dev@maven.apache.org</code>, this
255          * method return <code>www.mail-archive.com</code>
256          *
257          * @param uri
258          * @return the server name of a web-based mailing list archive server
259          */
260         private static String getArchiveServer( String uri )
261         {
262             if ( StringUtils.isEmpty( uri ) )
263             {
264                 return "???UNKNOWN???";
265             }
266 
267             int at = uri.indexOf( "//" );
268             int fromIndex;
269             if ( at >= 0 )
270             {
271                 fromIndex = uri.lastIndexOf( "/", at - 1 ) >= 0 ? 0 : at + 2;
272             }
273             else
274             {
275                 fromIndex = 0;
276             }
277 
278             int from = uri.indexOf( "/", fromIndex );
279 
280             if ( from == -1 )
281             {
282                 return uri.substring( at + 2 );
283             }
284 
285             return uri.substring( at + 2, from );
286         }
287     }
288 }