Coverage Report - org.apache.maven.plugin.trac.TracReportGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
TracReportGenerator
0%
0/128
0%
0/46
4,364
 
 1  
 package org.apache.maven.plugin.trac;
 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.text.SimpleDateFormat;
 23  
 import java.util.ArrayList;
 24  
 import java.util.List;
 25  
 import java.util.ResourceBundle;
 26  
 
 27  
 import org.apache.maven.doxia.sink.Sink;
 28  
 import org.apache.maven.reporting.MavenReportException;
 29  
 
 30  
 /**
 31  
  * Generates a Trac report.
 32  
  *
 33  
  * @author Noriko Kinugasa
 34  
  * @version $Id: org.apache.maven.plugin.trac.TracReportGenerator.html 816592 2012-05-08 12:40:21Z hboutemy $
 35  
  */
 36  
 public class TracReportGenerator
 37  
 {
 38  
     private static final int COLUMN_ID = 0;
 39  
     private static final int COLUMN_TYPE = 1;
 40  
     private static final int COLUMN_SUMMARY = 2;
 41  
     private static final int COLUMN_STATUS = 3;
 42  
     private static final int COLUMN_RESOLUTION = 4;
 43  
     private static final int COLUMN_MILESTONE = 5;
 44  
     private static final int COLUMN_OWNER = 6;
 45  
     private static final int COLUMN_PRIORITY = 7;
 46  
     private static final int COLUMN_REPORTER = 8;
 47  
     private static final int COLUMN_COMPONENT = 9;
 48  
     private static final int COLUMN_CREATED = 10;
 49  
     private static final int COLUMN_CHANGED = 11;
 50  
 
 51  
     /**
 52  
      * Valid Trac columns.
 53  
      */
 54  0
     private static final String[] TRAC_COLUMNS = {
 55  
             /* 0 */ "id",
 56  
             /* 1 */ "type",
 57  
             /* 2 */ "summary",
 58  
             /* 3 */ "status",
 59  
             /* 4 */ "resolution",
 60  
             /* 5 */ "milestone",
 61  
             /* 6 */ "owner",
 62  
             /* 7 */ "priority",
 63  
             /* 8 */ "reporter",
 64  
             /* 9 */ "component",
 65  
             /* 10 */ "created",
 66  
             /* 11 */ "changed"
 67  
     };
 68  
 
 69  
     private int[] columnOrder;
 70  
 
 71  
     public TracReportGenerator( String columnNames )
 72  
         throws MavenReportException
 73  0
     {
 74  0
         String[] columnNamesArray = columnNames.split( "," );
 75  0
         int validColumnNames = 0;
 76  0
         columnOrder = new int[columnNamesArray.length];
 77  0
         for ( int i = 0; i < columnOrder.length; i++ )
 78  
         {
 79  
             // Default to -1, indicating that the column should not be included in the report
 80  0
             columnOrder[i] = -1;
 81  0
             for ( int columnIndex = 0; columnIndex < TRAC_COLUMNS.length; columnIndex++ )
 82  
             {
 83  0
                 String columnName = columnNamesArray[i].trim();
 84  0
                 if ( TRAC_COLUMNS[columnIndex].equalsIgnoreCase( columnName ) )
 85  
                 {
 86  
                     // Found a valid column name - add it
 87  0
                     columnOrder[i] = columnIndex;
 88  0
                     validColumnNames++;
 89  0
                     break;
 90  
                 }
 91  
             }
 92  
         }
 93  0
         if ( validColumnNames == 0 )
 94  
         {
 95  
             // This can happen if the user has configured column names and they are all invalid
 96  0
             throw new MavenReportException(
 97  
                 "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." );
 98  
         }
 99  0
     }
 100  
 
 101  
     public void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
 102  
     {
 103  0
         sinkBeginReport( sink, bundle );
 104  
 
 105  0
         sink.paragraph();
 106  
 
 107  0
         sink.text( bundle.getString( "report.trac.error" ) );
 108  
 
 109  0
         sink.paragraph_();
 110  
 
 111  0
         sinkEndReport( sink );
 112  0
     }
 113  
 
 114  
     public void doGenerateReport( ResourceBundle bundle, Sink sink, ArrayList ticketList )
 115  
     {
 116  
 
 117  0
         sinkBeginReport( sink, bundle );
 118  
 
 119  0
         constructHeaderRow( sink, ticketList, bundle );
 120  
 
 121  0
         constructDetailRows( sink, ticketList, bundle );
 122  
 
 123  0
         sinkEndReport( sink );
 124  0
     }
 125  
 
 126  
     private void constructHeaderRow( Sink sink, List ticketList, ResourceBundle bundle )
 127  
     {
 128  0
         if ( ticketList == null )
 129  
         {
 130  0
             return;
 131  
         }
 132  
 
 133  0
         sink.table();
 134  
 
 135  0
         sink.tableRow();
 136  
 
 137  0
         for ( int columnIndex = 0; columnIndex < columnOrder.length; columnIndex++ )
 138  
         {
 139  0
             switch ( columnOrder[columnIndex] )
 140  
             {
 141  
                 case COLUMN_ID:
 142  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.id" ) );
 143  0
                     break;
 144  
                 case COLUMN_TYPE:
 145  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.type" ) );
 146  0
                     break;
 147  
                 case COLUMN_SUMMARY:
 148  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.summary" ) );
 149  0
                     break;
 150  
                 case COLUMN_OWNER:
 151  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.owner" ) );
 152  0
                     break;
 153  
                 case COLUMN_REPORTER:
 154  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.reporter" ) );
 155  0
                     break;
 156  
                 case COLUMN_PRIORITY:
 157  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.priority" ) );
 158  0
                     break;
 159  
                 case COLUMN_STATUS:
 160  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.status" ) );
 161  0
                     break;
 162  
                 case COLUMN_RESOLUTION:
 163  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.resolution" ) );
 164  0
                     break;
 165  
                 case COLUMN_CREATED:
 166  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.created" ) );
 167  0
                     break;
 168  
                 case COLUMN_CHANGED:
 169  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.changed" ) );
 170  0
                     break;
 171  
                 case COLUMN_MILESTONE:
 172  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.milestone" ) );
 173  0
                     break;
 174  
                 case COLUMN_COMPONENT:
 175  0
                     sinkHeader( sink, bundle.getString( "report.trac.label.component" ) );
 176  0
                     break;
 177  
                 default:
 178  
                     // Do not add a header for this column
 179  
                     break;
 180  
             }
 181  
         }
 182  
 
 183  0
         sink.tableRow_();
 184  0
     }
 185  
 
 186  
     private void constructDetailRows( Sink sink, List ticketList, ResourceBundle bundle )
 187  
     {
 188  0
         if ( ticketList == null )
 189  
         {
 190  0
             return;
 191  
         }
 192  
 
 193  0
         for ( int idx = 0; idx < ticketList.size(); idx++ )
 194  
         {
 195  0
             SimpleDateFormat sdf = new SimpleDateFormat( bundle.getString( "report.trac.dateformat" ) );
 196  
 
 197  0
             TracTicket ticket = (TracTicket) ticketList.get( idx );
 198  
 
 199  0
             sink.tableRow();
 200  
 
 201  0
             for ( int columnIndex = 0; columnIndex < columnOrder.length; columnIndex++ )
 202  
             {
 203  0
                 switch ( columnOrder[columnIndex] )
 204  
                 {
 205  
                     case COLUMN_ID:
 206  0
                         sink.tableCell();
 207  0
                         sink.link( ticket.getLink() );
 208  0
                         sink.text( ticket.getId() );
 209  0
                         sink.link_();
 210  0
                         sink.tableCell_();
 211  0
                         break;
 212  
                     case COLUMN_TYPE:
 213  0
                         sinkCell( sink, ticket.getType() );
 214  0
                         break;
 215  
                     case COLUMN_SUMMARY:
 216  0
                         sinkCell( sink, ticket.getSummary() );
 217  0
                         break;
 218  
                     case COLUMN_OWNER:
 219  0
                         sinkCell( sink, ticket.getOwner() );
 220  0
                         break;
 221  
                     case COLUMN_REPORTER:
 222  0
                         sinkCell( sink, ticket.getReporter() );
 223  0
                         break;
 224  
                     case COLUMN_PRIORITY:
 225  0
                         sinkCell( sink, ticket.getPriority() );
 226  0
                         break;
 227  
                     case COLUMN_STATUS:
 228  0
                         sinkCell( sink, ticket.getStatus() );
 229  0
                         break;
 230  
                     case COLUMN_RESOLUTION:
 231  0
                         sinkCell( sink, ticket.getResolution() );
 232  0
                         break;
 233  
                     case COLUMN_CREATED:
 234  0
                         sinkCell( sink, sdf.format( ticket.getTimeCreated() ) );
 235  0
                         break;
 236  
                     case COLUMN_CHANGED:
 237  0
                         sinkCell( sink, sdf.format( ticket.getTimeChanged() ) );
 238  0
                         break;
 239  
                     case COLUMN_MILESTONE:
 240  0
                         sinkCell( sink, ticket.getMilestone() );
 241  0
                         break;
 242  
                     case COLUMN_COMPONENT:
 243  0
                         sinkCell( sink, ticket.getComponent() );
 244  0
                         break;
 245  
                     default:
 246  
                         // Do not add details for this column
 247  
                         break;
 248  
                 }
 249  
             }
 250  
 
 251  0
             sink.tableRow_();
 252  
         }
 253  
 
 254  0
         sink.table_();
 255  0
     }
 256  
 
 257  
     private void sinkBeginReport( Sink sink, ResourceBundle bundle )
 258  
     {
 259  0
         sink.head();
 260  
 
 261  0
         sink.text( bundle.getString( "report.trac.header" ) );
 262  
 
 263  0
         sink.head_();
 264  
 
 265  0
         sink.body();
 266  
 
 267  0
         sink.section1();
 268  
 
 269  0
         sinkSectionTitle1( sink, bundle.getString( "report.trac.header" ) );
 270  
 
 271  0
     }
 272  
 
 273  
     private void sinkEndReport( Sink sink )
 274  
     {
 275  0
         sink.section1_();
 276  
 
 277  0
         sink.body_();
 278  
 
 279  0
         sink.flush();
 280  
 
 281  0
         sink.close();
 282  0
     }
 283  
 
 284  
     private void sinkFigure( Sink sink, String image )
 285  
     {
 286  0
         sink.figure();
 287  
 
 288  0
         sink.figureGraphics( image );
 289  
 
 290  0
         sink.figure_();
 291  0
     }
 292  
 
 293  
     private void sinkHeader( Sink sink, String header )
 294  
     {
 295  0
         sink.tableHeaderCell();
 296  
 
 297  0
         sink.text( header );
 298  
 
 299  0
         sink.tableHeaderCell_();
 300  0
     }
 301  
 
 302  
     private void sinkCell( Sink sink, String text )
 303  
     {
 304  0
         sink.tableCell();
 305  
 
 306  0
         if ( text != null )
 307  
         {
 308  0
             sink.rawText( text );
 309  
         }
 310  
         else
 311  
         {
 312  0
             sink.rawText( "&nbsp;" );
 313  
         }
 314  
 
 315  0
         sink.tableCell_();
 316  0
     }
 317  
 
 318  
     private void sinkSectionTitle1( Sink sink, String text )
 319  
     {
 320  0
         sink.sectionTitle1();
 321  
 
 322  0
         sink.text( text );
 323  
 
 324  0
         sink.sectionTitle1_();
 325  0
     }
 326  
 }