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