Coverage Report - org.apache.maven.plugin.changelog.DeveloperActivityReport
 
Classes in this File Line Coverage Branch Coverage Complexity
DeveloperActivityReport
95%
105/110
94%
15/16
1,8
 
 1  
 package org.apache.maven.plugin.changelog;
 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.scm.ChangeFile;
 24  
 import org.apache.maven.scm.ChangeSet;
 25  
 import org.apache.maven.scm.command.changelog.ChangeLogSet;
 26  
 
 27  
 import java.util.Collection;
 28  
 import java.util.HashMap;
 29  
 import java.util.Iterator;
 30  
 import java.util.LinkedList;
 31  
 import java.util.List;
 32  
 import java.util.Locale;
 33  
 import java.util.ResourceBundle;
 34  
 
 35  
 /**
 36  
  * Generate a developer activity report.
 37  
  *
 38  
  * @version $Id: DeveloperActivityReport.java 939126 2010-04-28 22:52:04Z dennisl $
 39  
  * @goal dev-activity
 40  
  */
 41  8
 public class DeveloperActivityReport
 42  
     extends ChangeLogReport
 43  
 {
 44  
     /**
 45  
      * Used to hold data while creating the report
 46  
      */
 47  
     private HashMap commits;
 48  
 
 49  
     private HashMap files;
 50  
 
 51  
     /** {@inheritDoc} */
 52  
     public String getDescription( Locale locale )
 53  
     {
 54  0
         return getBundle( locale ).getString( "report.dev-activity.description" );
 55  
     }
 56  
 
 57  
     /** {@inheritDoc} */
 58  
     public String getName( Locale locale )
 59  
     {
 60  0
         return getBundle( locale ).getString( "report.dev-activity.name" );
 61  
     }
 62  
 
 63  
     /** {@inheritDoc} */
 64  
     public String getOutputName()
 65  
     {
 66  8
         return "dev-activity";
 67  
     }
 68  
 
 69  
     /** {@inheritDoc} */
 70  
     protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
 71  
     {
 72  4
         sink.head();
 73  4
         sink.title();
 74  4
         sink.text( bundle.getString( "report.dev-activity.header" ) );
 75  4
         sink.title_();
 76  4
         sink.head_();
 77  
 
 78  4
         sink.body();
 79  4
         sink.section1();
 80  
 
 81  4
         sink.sectionTitle1();
 82  4
         sink.text( bundle.getString( "report.dev-activity.mainTitle" ) );
 83  4
         sink.sectionTitle1_();
 84  
 
 85  4
         sink.paragraph();
 86  4
         sink.text( "No sources found to create a report." );
 87  4
         sink.paragraph_();
 88  
 
 89  4
         sink.section1_();
 90  
 
 91  4
         sink.body_();
 92  4
         sink.flush();
 93  4
         sink.close();
 94  4
     }
 95  
 
 96  
     /** {@inheritDoc} */
 97  
     protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink )
 98  
     {
 99  4
         sink.head();
 100  4
         sink.title();
 101  4
         sink.text( bundle.getString( "report.dev-activity.header" ) );
 102  4
         sink.title_();
 103  4
         sink.head_();
 104  
 
 105  4
         sink.body();
 106  4
         sink.section1();
 107  4
         sink.sectionTitle1();
 108  4
         sink.text( bundle.getString( "report.dev-activity.mainTitle" ) );
 109  4
         sink.sectionTitle1_();
 110  
 
 111  4
         if ( developers.isEmpty() )
 112  
         {
 113  0
             sink.paragraph();
 114  0
             sink.text( bundle.getString( "report.dev-activity.noDevelopers" ) );
 115  0
             sink.paragraph_();
 116  
         }
 117  
         else
 118  
         {
 119  4
             for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); )
 120  
             {
 121  8
                 ChangeLogSet set = (ChangeLogSet) sets.next();
 122  8
                 doChangedSets( set, bundle, sink );
 123  8
             }
 124  
         }
 125  
 
 126  4
         sink.section1_();
 127  4
         sink.body_();
 128  4
         sink.flush();
 129  4
         sink.close();
 130  4
     }
 131  
 
 132  
     /**
 133  
      * generates a section of the report referring to a changeset
 134  
      *
 135  
      * @param set    the current ChangeSet to generate this section of the report
 136  
      * @param bundle the resource bundle to retrieve report phrases from
 137  
      * @param sink   the report formatting tool
 138  
      */
 139  
     private void doChangedSets( ChangeLogSet set, ResourceBundle bundle, Sink sink )
 140  
     {
 141  8
         sink.section2();
 142  
 
 143  8
         doChangeSetTitle( set, bundle, sink );
 144  
 
 145  8
         doSummary( set, bundle, sink );
 146  
 
 147  8
         sink.table();
 148  
 
 149  8
         sink.tableRow();
 150  8
         sink.tableHeaderCell();
 151  8
         sink.text( bundle.getString( "report.dev-activity.developer" ) );
 152  8
         sink.tableHeaderCell_();
 153  8
         sink.tableHeaderCell();
 154  8
         sink.text( bundle.getString( "report.TotalCommits" ) );
 155  8
         sink.tableHeaderCell_();
 156  8
         sink.tableHeaderCell();
 157  8
         sink.text( bundle.getString( "report.dev-activity.filesChanged" ) );
 158  8
         sink.tableHeaderCell_();
 159  8
         sink.tableRow_();
 160  
 
 161  8
         doDeveloperRows( set, sink );
 162  
 
 163  8
         sink.table_();
 164  
 
 165  8
         sink.section2_();
 166  8
     }
 167  
 
 168  
     /**
 169  
      * generates the report section table of the developers
 170  
      *
 171  
      * @param set  change log set generate the developer activity
 172  
      * @param sink the report formatting tool
 173  
      */
 174  
     private void doDeveloperRows( ChangeLogSet set, Sink sink )
 175  
     {
 176  8
         initDeveloperDetails( set );
 177  
 
 178  8
         for( Iterator i = commits.keySet().iterator(); i.hasNext(); )
 179  
         {
 180  8
             String author = (String) i.next();
 181  
 
 182  8
             LinkedList devCommits = (LinkedList) commits.get( author );
 183  8
             HashMap devFiles = (HashMap) files.get( author );
 184  
 
 185  8
             sink.tableRow();
 186  8
             sink.tableCell();
 187  
 
 188  8
             sinkAuthorDetails( sink, author );
 189  
 
 190  8
             sink.tableCell_();
 191  
 
 192  8
             sink.tableCell();
 193  8
             sink.text( "" + devCommits.size() );
 194  8
             sink.tableCell_();
 195  
 
 196  8
             sink.tableCell();
 197  8
             sink.text( "" + devFiles.size() );
 198  8
             sink.tableCell_();
 199  
 
 200  8
             sink.tableRow_();
 201  8
         }
 202  8
     }
 203  
 
 204  
     /**
 205  
      * counts the number of commits and files changed for each developer
 206  
      *
 207  
      * @param set the change log set to generate the developer details from
 208  
      */
 209  
     private void initDeveloperDetails( ChangeLogSet set )
 210  
     {
 211  8
         commits = new HashMap();
 212  
 
 213  8
         files = new HashMap();
 214  
 
 215  8
         countDevCommits( set.getChangeSets() );
 216  
 
 217  8
         countDevFiles( set.getChangeSets() );
 218  8
     }
 219  
 
 220  
     /**
 221  
      * counts the number of commits of each developer
 222  
      *
 223  
      * @param entries the change log entries used to search and count developer commits
 224  
      */
 225  
     private void countDevCommits( Collection entries )
 226  
     {
 227  8
         for ( Iterator i = entries.iterator(); i.hasNext(); )
 228  
         {
 229  16
             ChangeSet entry = (ChangeSet) i.next();
 230  
 
 231  16
             String developer = entry.getAuthor();
 232  
 
 233  
             LinkedList list;
 234  
 
 235  16
             if ( commits.containsKey( developer ) )
 236  
             {
 237  8
                 list = (LinkedList) commits.get( developer );
 238  
             }
 239  
             else
 240  
             {
 241  8
                 list = new LinkedList();
 242  
             }
 243  
 
 244  16
             list.add( entry );
 245  
 
 246  16
             commits.put( developer, list );
 247  16
         }
 248  8
     }
 249  
 
 250  
     /**
 251  
      * counts the number of files changed by each developer
 252  
      *
 253  
      * @param entries the change log entries used to search and count file changes
 254  
      */
 255  
     private void countDevFiles( Collection entries )
 256  
     {
 257  8
         for ( Iterator i2 = entries.iterator(); i2.hasNext(); )
 258  
         {
 259  16
             ChangeSet entry = (ChangeSet) i2.next();
 260  
 
 261  16
             String developer = entry.getAuthor();
 262  
 
 263  
             HashMap filesMap;
 264  
 
 265  16
             if ( files.containsKey( developer ) )
 266  
             {
 267  8
                 filesMap = (HashMap) files.get( developer );
 268  
             }
 269  
             else
 270  
             {
 271  8
                 filesMap = new HashMap();
 272  
             }
 273  
 
 274  16
             for ( Iterator i3 = entry.getFiles().iterator(); i3.hasNext(); )
 275  
             {
 276  24
                 ChangeFile file = (ChangeFile) i3.next();
 277  
 
 278  24
                 filesMap.put( file.getName(), file );
 279  24
             }
 280  
 
 281  16
             files.put( developer, filesMap );
 282  16
         }
 283  8
     }
 284  
 }