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  2
 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  2
         return "dev-activity";
 67  
     }
 68  
 
 69  
     /** {@inheritDoc} */
 70  
     protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
 71  
     {
 72  1
         sink.head();
 73  1
         sink.title();
 74  1
         sink.text( bundle.getString( "report.dev-activity.header" ) );
 75  1
         sink.title_();
 76  1
         sink.head_();
 77  
 
 78  1
         sink.body();
 79  1
         sink.section1();
 80  
 
 81  1
         sink.sectionTitle1();
 82  1
         sink.text( bundle.getString( "report.dev-activity.mainTitle" ) );
 83  1
         sink.sectionTitle1_();
 84  
 
 85  1
         sink.paragraph();
 86  1
         sink.text( "No sources found to create a report." );
 87  1
         sink.paragraph_();
 88  
 
 89  1
         sink.section1_();
 90  
 
 91  1
         sink.body_();
 92  1
         sink.flush();
 93  1
         sink.close();
 94  1
     }
 95  
 
 96  
     /** {@inheritDoc} */
 97  
     protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink )
 98  
     {
 99  1
         sink.head();
 100  1
         sink.title();
 101  1
         sink.text( bundle.getString( "report.dev-activity.header" ) );
 102  1
         sink.title_();
 103  1
         sink.head_();
 104  
 
 105  1
         sink.body();
 106  1
         sink.section1();
 107  1
         sink.sectionTitle1();
 108  1
         sink.text( bundle.getString( "report.dev-activity.mainTitle" ) );
 109  1
         sink.sectionTitle1_();
 110  
 
 111  1
         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  1
             for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); )
 120  
             {
 121  2
                 ChangeLogSet set = (ChangeLogSet) sets.next();
 122  2
                 doChangedSets( set, bundle, sink );
 123  2
             }
 124  
         }
 125  
 
 126  1
         sink.section1_();
 127  1
         sink.body_();
 128  1
         sink.flush();
 129  1
         sink.close();
 130  1
     }
 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  2
         sink.section2();
 142  
 
 143  2
         doChangeSetTitle( set, bundle, sink );
 144  
 
 145  2
         doSummary( set, bundle, sink );
 146  
 
 147  2
         sink.table();
 148  
 
 149  2
         sink.tableRow();
 150  2
         sink.tableHeaderCell();
 151  2
         sink.text( bundle.getString( "report.dev-activity.developer" ) );
 152  2
         sink.tableHeaderCell_();
 153  2
         sink.tableHeaderCell();
 154  2
         sink.text( bundle.getString( "report.TotalCommits" ) );
 155  2
         sink.tableHeaderCell_();
 156  2
         sink.tableHeaderCell();
 157  2
         sink.text( bundle.getString( "report.dev-activity.filesChanged" ) );
 158  2
         sink.tableHeaderCell_();
 159  2
         sink.tableRow_();
 160  
 
 161  2
         doDeveloperRows( set, sink );
 162  
 
 163  2
         sink.table_();
 164  
 
 165  2
         sink.section2_();
 166  2
     }
 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  2
         initDeveloperDetails( set );
 177  
 
 178  2
         for( Iterator i = commits.keySet().iterator(); i.hasNext(); )
 179  
         {
 180  2
             String author = (String) i.next();
 181  
 
 182  2
             LinkedList devCommits = (LinkedList) commits.get( author );
 183  2
             HashMap devFiles = (HashMap) files.get( author );
 184  
 
 185  2
             sink.tableRow();
 186  2
             sink.tableCell();
 187  
 
 188  2
             sinkAuthorDetails( sink, author );
 189  
 
 190  2
             sink.tableCell_();
 191  
 
 192  2
             sink.tableCell();
 193  2
             sink.text( "" + devCommits.size() );
 194  2
             sink.tableCell_();
 195  
 
 196  2
             sink.tableCell();
 197  2
             sink.text( "" + devFiles.size() );
 198  2
             sink.tableCell_();
 199  
 
 200  2
             sink.tableRow_();
 201  2
         }
 202  2
     }
 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  2
         commits = new HashMap();
 212  
 
 213  2
         files = new HashMap();
 214  
 
 215  2
         countDevCommits( set.getChangeSets() );
 216  
 
 217  2
         countDevFiles( set.getChangeSets() );
 218  2
     }
 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  2
         for ( Iterator i = entries.iterator(); i.hasNext(); )
 228  
         {
 229  4
             ChangeSet entry = (ChangeSet) i.next();
 230  
 
 231  4
             String developer = entry.getAuthor();
 232  
 
 233  
             LinkedList list;
 234  
 
 235  4
             if ( commits.containsKey( developer ) )
 236  
             {
 237  2
                 list = (LinkedList) commits.get( developer );
 238  
             }
 239  
             else
 240  
             {
 241  2
                 list = new LinkedList();
 242  
             }
 243  
 
 244  4
             list.add( entry );
 245  
 
 246  4
             commits.put( developer, list );
 247  4
         }
 248  2
     }
 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  2
         for ( Iterator i2 = entries.iterator(); i2.hasNext(); )
 258  
         {
 259  4
             ChangeSet entry = (ChangeSet) i2.next();
 260  
 
 261  4
             String developer = entry.getAuthor();
 262  
 
 263  
             HashMap filesMap;
 264  
 
 265  4
             if ( files.containsKey( developer ) )
 266  
             {
 267  2
                 filesMap = (HashMap) files.get( developer );
 268  
             }
 269  
             else
 270  
             {
 271  2
                 filesMap = new HashMap();
 272  
             }
 273  
 
 274  4
             for ( Iterator i3 = entry.getFiles().iterator(); i3.hasNext(); )
 275  
             {
 276  6
                 ChangeFile file = (ChangeFile) i3.next();
 277  
 
 278  6
                 filesMap.put( file.getName(), file );
 279  6
             }
 280  
 
 281  4
             files.put( developer, filesMap );
 282  4
         }
 283  2
     }
 284  
 }