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  2
 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  2
         return "file-activity";
 62  
     }
 63  
 
 64  
     /** {@inheritDoc} */
 65  
     protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
 66  
     {
 67  1
         sink.head();
 68  1
         sink.title();
 69  1
         sink.text( bundle.getString( "report.file-activity.header" ) );
 70  1
         sink.title_();
 71  1
         sink.head_();
 72  
 
 73  1
         sink.body();
 74  1
         sink.section1();
 75  
 
 76  1
         sink.sectionTitle1();
 77  1
         sink.text( bundle.getString( "report.file-activity.mainTitle" ) );
 78  1
         sink.sectionTitle1_();
 79  
 
 80  1
         sink.paragraph();
 81  1
         sink.text( "No sources found to create a report." );
 82  1
         sink.paragraph_();
 83  
 
 84  1
         sink.section1_();
 85  
 
 86  1
         sink.body_();
 87  1
         sink.flush();
 88  1
         sink.close();
 89  1
     }
 90  
 
 91  
     /** {@inheritDoc} */
 92  
     protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink )
 93  
     {
 94  1
         sink.head();
 95  1
         sink.title();
 96  1
         sink.text( bundle.getString( "report.file-activity.header" ) );
 97  1
         sink.title_();
 98  1
         sink.head_();
 99  
 
 100  1
         sink.body();
 101  1
         sink.section1();
 102  1
         sink.sectionTitle1();
 103  1
         sink.text( bundle.getString( "report.file-activity.mainTitle" ) );
 104  1
         sink.sectionTitle1_();
 105  
 
 106  1
         for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); )
 107  
         {
 108  2
             ChangeLogSet set = (ChangeLogSet) sets.next();
 109  2
             doChangedSets( set, bundle, sink );
 110  2
         }
 111  
 
 112  1
         sink.section1_();
 113  1
         sink.body_();
 114  
 
 115  1
         sink.flush();
 116  1
         sink.close();
 117  1
     }
 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  2
         sink.section2();
 129  
 
 130  2
         doChangeSetTitle( set, bundle, sink );
 131  
 
 132  2
         doSummary( set, bundle, sink );
 133  
 
 134  2
         sink.table();
 135  
 
 136  2
         sink.tableRow();
 137  2
         sink.tableHeaderCell();
 138  2
         sink.text( bundle.getString( "report.file-activity.filename" ) );
 139  2
         sink.tableHeaderCell_();
 140  2
         sink.tableHeaderCell();
 141  2
         sink.text( bundle.getString( "report.file-activity.timesChanged" ) );
 142  2
         sink.tableHeaderCell_();
 143  2
         sink.tableRow_();
 144  
 
 145  2
         doRows( set, sink );
 146  
 
 147  2
         sink.table_();
 148  
 
 149  2
         sink.section2_();
 150  2
     }
 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  2
         List list = getOrderedFileList( set.getChangeSets() );
 161  
 
 162  2
         initReportUrls();
 163  
 
 164  2
         for ( Iterator i = list.iterator(); i.hasNext(); )
 165  
         {
 166  4
             List revision = (List) i.next();
 167  4
             ChangeFile file = (ChangeFile) revision.get( 0 );
 168  
 
 169  4
             sink.tableRow();
 170  4
             sink.tableCell();
 171  
 
 172  
             try
 173  
             {
 174  4
                 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  4
             }
 189  4
             sink.tableCell_();
 190  
 
 191  4
             sink.tableCell();
 192  4
             sink.text( "" + revision.size() );
 193  
 
 194  4
             sink.tableCell_();
 195  4
             sink.tableRow_();
 196  4
         }
 197  2
     }
 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  2
         List list = new LinkedList();
 209  
 
 210  2
         Map map = new HashMap();
 211  
 
 212  2
         for ( Iterator i = entries.iterator(); i.hasNext(); )
 213  
         {
 214  4
             ChangeSet entry = (ChangeSet) i.next();
 215  
 
 216  4
             for ( Iterator j = entry.getFiles().iterator(); j.hasNext(); )
 217  
             {
 218  6
                 ChangeFile file = (ChangeFile) j.next();
 219  
 
 220  
                 List revisions;
 221  
 
 222  6
                 if ( map.containsKey( file.getName() ) )
 223  
                 {
 224  2
                     revisions = (List) map.get( file.getName() );
 225  
                 }
 226  
                 else
 227  
                 {
 228  4
                     revisions = new LinkedList();
 229  
                 }
 230  
 
 231  6
                 revisions.add( file );
 232  
 
 233  6
                 map.put( file.getName(), revisions );
 234  6
             }
 235  4
         }
 236  
 
 237  2
         list.addAll( map.values() );
 238  
 
 239  2
         Collections.sort( list, new FileActivityComparator() );
 240  
 
 241  2
         return list;
 242  
     }
 243  
 }