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