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