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