Coverage Report - org.apache.maven.plugin.changelog.FileActivityReport
 
Classes in this File Line Coverage Branch Coverage Complexity
FileActivityReport
93%
87/94
83%
10/12
1,875
 
 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.Collections;
 29  
 import java.util.HashMap;
 30  
 import java.util.Iterator;
 31  
 import java.util.LinkedList;
 32  
 import java.util.List;
 33  
 import java.util.Locale;
 34  
 import java.util.Map;
 35  
 import java.util.ResourceBundle;
 36  
 
 37  
 /**
 38  
  * Generate a file activity report.
 39  
  *
 40  
  * @version $Id: FileActivityReport.java 803834 2009-08-13 10:32:13Z vsiveton $
 41  
  * @goal file-activity
 42  
  */
 43  8
 public class FileActivityReport
 44  
     extends ChangeLogReport
 45  
 {
 46  
     /** {@inheritDoc} */
 47  
     public String getDescription( Locale locale )
 48  
     {
 49  0
         return getBundle( locale ).getString( "report.file-activity.description" );
 50  
     }
 51  
 
 52  
     /** {@inheritDoc} */
 53  
     public String getName( Locale locale )
 54  
     {
 55  0
         return getBundle( locale ).getString( "report.file-activity.name" );
 56  
     }
 57  
 
 58  
     /** {@inheritDoc} */
 59  
     public String getOutputName()
 60  
     {
 61  8
         return "file-activity";
 62  
     }
 63  
 
 64  
     /** {@inheritDoc} */
 65  
     protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
 66  
     {
 67  4
         sink.head();
 68  4
         sink.title();
 69  4
         sink.text( bundle.getString( "report.file-activity.header" ) );
 70  4
         sink.title_();
 71  4
         sink.head_();
 72  
 
 73  4
         sink.body();
 74  4
         sink.section1();
 75  
 
 76  4
         sink.sectionTitle1();
 77  4
         sink.text( bundle.getString( "report.file-activity.mainTitle" ) );
 78  4
         sink.sectionTitle1_();
 79  
 
 80  4
         sink.paragraph();
 81  4
         sink.text( "No sources found to create a report." );
 82  4
         sink.paragraph_();
 83  
 
 84  4
         sink.section1_();
 85  
 
 86  4
         sink.body_();
 87  4
         sink.flush();
 88  4
         sink.close();
 89  4
     }
 90  
 
 91  
     /** {@inheritDoc} */
 92  
     protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink )
 93  
     {
 94  4
         sink.head();
 95  4
         sink.title();
 96  4
         sink.text( bundle.getString( "report.file-activity.header" ) );
 97  4
         sink.title_();
 98  4
         sink.head_();
 99  
 
 100  4
         sink.body();
 101  4
         sink.section1();
 102  4
         sink.sectionTitle1();
 103  4
         sink.text( bundle.getString( "report.file-activity.mainTitle" ) );
 104  4
         sink.sectionTitle1_();
 105  
 
 106  4
         for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); )
 107  
         {
 108  8
             ChangeLogSet set = (ChangeLogSet) sets.next();
 109  8
             doChangedSets( set, bundle, sink );
 110  8
         }
 111  
 
 112  4
         sink.section1_();
 113  4
         sink.body_();
 114  
 
 115  4
         sink.flush();
 116  4
         sink.close();
 117  4
     }
 118  
 
 119  
     /**
 120  
      * generates a section of the report referring to a changeset
 121  
      *
 122  
      * @param set    the current ChangeSet to generate this section of the report
 123  
      * @param bundle the resource bundle to retrieve report phrases from
 124  
      * @param sink   the report formatting tool
 125  
      */
 126  
     private void doChangedSets( ChangeLogSet set, ResourceBundle bundle, Sink sink )
 127  
     {
 128  8
         sink.section2();
 129  
 
 130  8
         doChangeSetTitle( set, bundle, sink );
 131  
 
 132  8
         doSummary( set, bundle, sink );
 133  
 
 134  8
         sink.table();
 135  
 
 136  8
         sink.tableRow();
 137  8
         sink.tableHeaderCell();
 138  8
         sink.text( bundle.getString( "report.file-activity.filename" ) );
 139  8
         sink.tableHeaderCell_();
 140  8
         sink.tableHeaderCell();
 141  8
         sink.text( bundle.getString( "report.file-activity.timesChanged" ) );
 142  8
         sink.tableHeaderCell_();
 143  8
         sink.tableRow_();
 144  
 
 145  8
         doRows( set, sink );
 146  
 
 147  8
         sink.table_();
 148  
 
 149  8
         sink.section2_();
 150  8
     }
 151  
 
 152  
     /**
 153  
      * generates the row details for the file activity report
 154  
      *
 155  
      * @param set  the changelog set to generate a report with
 156  
      * @param sink the report formatting tool
 157  
      */
 158  
     private void doRows( ChangeLogSet set, Sink sink )
 159  
     {
 160  8
         List list = getOrderedFileList( set.getChangeSets() );
 161  
 
 162  8
         initReportUrls();
 163  
 
 164  8
         for ( Iterator i = list.iterator(); i.hasNext(); )
 165  
         {
 166  16
             List revision = (List) i.next();
 167  16
             ChangeFile file = (ChangeFile) revision.get( 0 );
 168  
 
 169  16
             sink.tableRow();
 170  16
             sink.tableCell();
 171  
 
 172  
             try
 173  
             {
 174  16
                 generateLinks( getConnection(), file.getName(), sink );
 175  
             }
 176  0
             catch ( Exception e )
 177  
             {
 178  0
                 if ( getLog().isDebugEnabled() )
 179  
                 {
 180  0
                     getLog().error( e.getMessage(), e );
 181  
                 }
 182  
                 else
 183  
                 {
 184  0
                     getLog().error( e.getMessage() );
 185  
                 }
 186  
 
 187  0
                 sink.text( file.getName() );
 188  16
             }
 189  16
             sink.tableCell_();
 190  
 
 191  16
             sink.tableCell();
 192  16
             sink.text( "" + revision.size() );
 193  
 
 194  16
             sink.tableCell_();
 195  16
             sink.tableRow_();
 196  16
         }
 197  8
     }
 198  
 
 199  
     /**
 200  
      * reads the change log entries and generates a list of files changed order by the number of times edited. This
 201  
      * used the FileActivityComparator Object to sort the list
 202  
      *
 203  
      * @param entries the changelog entries to generate the report
 204  
      * @return list of changed files within the SCM with the number of times changed in descending order
 205  
      */
 206  
     private List getOrderedFileList( Collection entries )
 207  
     {
 208  8
         List list = new LinkedList();
 209  
 
 210  8
         Map map = new HashMap();
 211  
 
 212  8
         for ( Iterator i = entries.iterator(); i.hasNext(); )
 213  
         {
 214  16
             ChangeSet entry = (ChangeSet) i.next();
 215  
 
 216  16
             for ( Iterator j = entry.getFiles().iterator(); j.hasNext(); )
 217  
             {
 218  24
                 ChangeFile file = (ChangeFile) j.next();
 219  
 
 220  
                 List revisions;
 221  
 
 222  24
                 if ( map.containsKey( file.getName() ) )
 223  
                 {
 224  8
                     revisions = (List) map.get( file.getName() );
 225  
                 }
 226  
                 else
 227  
                 {
 228  16
                     revisions = new LinkedList();
 229  
                 }
 230  
 
 231  24
                 revisions.add( file );
 232  
 
 233  24
                 map.put( file.getName(), revisions );
 234  24
             }
 235  16
         }
 236  
 
 237  8
         list.addAll( map.values() );
 238  
 
 239  8
         Collections.sort( list, new FileActivityComparator() );
 240  
 
 241  8
         return list;
 242  
     }
 243  
 }