Coverage Report - org.apache.maven.plugin.issues.IssuesReportHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
IssuesReportHelper
48%
15/31
40%
8/20
3.5
 
 1  
 package org.apache.maven.plugin.issues;
 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.commons.collections.bidimap.DualHashBidiMap;
 23  
 import org.apache.maven.plugin.logging.Log;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.Iterator;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * A helper class for generation of reports based on issues.
 32  
  *
 33  
  * @author Dennis Lundberg
 34  
  * @version $Id: IssuesReportHelper.java 1098344 2011-05-01 14:49:27Z dennisl $
 35  
  * @since 2.4
 36  
  */
 37  0
 public class IssuesReportHelper
 38  
 {
 39  
     public static final int COLUMN_ASSIGNEE = 0;
 40  
 
 41  
     public static final int COLUMN_COMPONENT = 1;
 42  
 
 43  
     public static final int COLUMN_CREATED = 2;
 44  
 
 45  
     public static final int COLUMN_FIX_VERSION = 3;
 46  
 
 47  
     public static final int COLUMN_ID = 4;
 48  
 
 49  
     public static final int COLUMN_KEY = 5;
 50  
 
 51  
     public static final int COLUMN_PRIORITY = 6;
 52  
 
 53  
     public static final int COLUMN_REPORTER = 7;
 54  
 
 55  
     public static final int COLUMN_RESOLUTION = 8;
 56  
 
 57  
     public static final int COLUMN_STATUS = 9;
 58  
 
 59  
     public static final int COLUMN_SUMMARY = 10;
 60  
 
 61  
     public static final int COLUMN_TYPE = 11;
 62  
 
 63  
     public static final int COLUMN_UPDATED = 12;
 64  
 
 65  
     public static final int COLUMN_VERSION = 13;
 66  
 
 67  
     /**
 68  
      * Get a list of id:s for the columns that are to be included in the report.
 69  
      *
 70  
      * @param columnNames The names of the columns
 71  
      * @param allColumns A mapping from column name to column id
 72  
      * @return A List of column id:s
 73  
      */
 74  
     public static List<Integer> getColumnIds( String columnNames, Map<String,Integer> allColumns )
 75  
     {
 76  1
         return getColumnIds( columnNames, allColumns, null, null );
 77  
     }
 78  
 
 79  
     /**
 80  
      * Get a list of id:s for the columns that are to be included in the report.
 81  
      * This method also handles deprecated column names, which will still work.
 82  
      * If deprecated column names are used they generate a warning, indicating
 83  
      * the replacement column name.
 84  
      *
 85  
      * @param columnNames The names of the columns
 86  
      * @param allColumns A mapping from column name to column id
 87  
      * @param deprecatedColumns A mapping from deprecated column name to column id
 88  
      * @param log A log
 89  
      * @return A List of column id:s
 90  
      */
 91  
     public static List<Integer> getColumnIds( String columnNames, Map<String,Integer> allColumns,
 92  
                                               Map<String,Integer> deprecatedColumns, Log log )
 93  
     {
 94  1
         DualHashBidiMap bidiColumns = null;
 95  1
         List<Integer> columnIds = new ArrayList<Integer>();
 96  1
         String[] columnNamesArray = columnNames.split( "," );
 97  
 
 98  1
         if ( deprecatedColumns != null )
 99  
         {
 100  0
             bidiColumns = new DualHashBidiMap( allColumns );
 101  
         }
 102  
 
 103  
         // Loop through the names of the columns, to validate each of them and add their id to the list
 104  7
         for ( int i = 0; i < columnNamesArray.length; i++ )
 105  
         {
 106  6
             String columnName = columnNamesArray[i].trim();
 107  6
             if ( allColumns.containsKey( columnName ) )
 108  
             {
 109  5
                 columnIds.add( allColumns.get( columnName ) );
 110  
             }
 111  1
             else if ( deprecatedColumns != null && deprecatedColumns.containsKey( columnName ) )
 112  
             {
 113  0
                 Integer columnId = deprecatedColumns.get( columnName );
 114  0
                 columnIds.add( columnId );
 115  0
                 if ( log != null )
 116  
                 {
 117  0
                     log.warn( "The columnName '" + columnName + "' has been deprecated." + " Please use "
 118  
                         + "the columnName '" + bidiColumns.getKey( columnId ) + "' instead." );
 119  
                 }
 120  
             }
 121  
         }
 122  1
         return columnIds;
 123  
     }
 124  
 
 125  
     /**
 126  
      * Print a list of values separated by commas.
 127  
      *
 128  
      * @param values The values to print
 129  
      * @return A nicely formatted string of values.
 130  
      */
 131  
     public static String printValues( List<String> values )
 132  
     {
 133  0
         StringBuffer sb = new StringBuffer();
 134  0
         if ( values != null )
 135  
         {
 136  0
             Iterator<String> iterator = values.iterator();
 137  0
             while ( iterator.hasNext() )
 138  
             {
 139  0
                 String value = iterator.next();
 140  0
                 sb.append( value );
 141  0
                 if ( iterator.hasNext() )
 142  
                 {
 143  0
                     sb.append( ", " );
 144  
                 }
 145  0
             }
 146  
         }
 147  0
         return sb.toString();
 148  
     }
 149  
 
 150  
     /**
 151  
      * Convert a List of Integers to an int array.
 152  
      *
 153  
      * @param list The List to convert
 154  
      * @return An in array
 155  
      */
 156  
     public static int[] toIntArray( List<Integer> list )
 157  
     {
 158  1
         int[] intArray = new int[list.size()];
 159  6
         for ( int j = 0; j < intArray.length; j++ )
 160  
         {
 161  5
             intArray[j] = ( list.get( j ) ).intValue();
 162  
         }
 163  1
         return intArray;
 164  
     }
 165  
 }