Coverage Report - org.apache.maven.plugin.trac.TracMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
TracMojo
0%
0/57
0%
0/4
2.143
 
 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.net.MalformedURLException;
 23  
 import java.util.HashMap;
 24  
 import java.util.List;
 25  
 import java.util.Locale;
 26  
 import java.util.Map;
 27  
 import java.util.ResourceBundle;
 28  
 
 29  
 import org.apache.maven.plugin.changes.AbstractChangesReport;
 30  
 import org.apache.maven.plugin.changes.ProjectUtils;
 31  
 import org.apache.maven.plugin.issues.IssuesReportGenerator;
 32  
 import org.apache.maven.plugin.issues.IssuesReportHelper;
 33  
 import org.apache.maven.reporting.MavenReportException;
 34  
 import org.apache.xmlrpc.XmlRpcException;
 35  
 
 36  
 /**
 37  
  * Goal which downloads issues from the Issue Tracking System and generates a
 38  
  * report.
 39  
  *
 40  
  * @goal trac-report
 41  
  * @author Noriko Kinugasa
 42  
  * @version $Id: TracMojo.java 1098305 2011-05-01 14:01:11Z dennisl $
 43  
  * @since 2.1
 44  
  * @threadSafe
 45  
  */
 46  0
 public class TracMojo
 47  
     extends AbstractChangesReport
 48  
 {
 49  
     /**
 50  
      * Deprecated Trac columns.
 51  
      */
 52  0
     private static Map<String,Integer> DEPRECATED_TRAC_COLUMNS = new HashMap<String,Integer>();
 53  
 
 54  
     /**
 55  
      * Valid Trac columns.
 56  
      */
 57  0
     private static Map<String,Integer> TRAC_COLUMNS = new HashMap<String,Integer>();
 58  
 
 59  
     static
 60  
     {
 61  0
         DEPRECATED_TRAC_COLUMNS.put( "changed", new Integer( IssuesReportHelper.COLUMN_UPDATED ) );
 62  0
         DEPRECATED_TRAC_COLUMNS.put( "component", new Integer( IssuesReportHelper.COLUMN_COMPONENT ) );
 63  0
         DEPRECATED_TRAC_COLUMNS.put( "created", new Integer( IssuesReportHelper.COLUMN_CREATED ) );
 64  0
         DEPRECATED_TRAC_COLUMNS.put( "id", new Integer( IssuesReportHelper.COLUMN_ID ) );
 65  0
         DEPRECATED_TRAC_COLUMNS.put( "milestone", new Integer( IssuesReportHelper.COLUMN_FIX_VERSION ) );
 66  0
         DEPRECATED_TRAC_COLUMNS.put( "owner", new Integer( IssuesReportHelper.COLUMN_ASSIGNEE ) );
 67  0
         DEPRECATED_TRAC_COLUMNS.put( "priority", new Integer( IssuesReportHelper.COLUMN_PRIORITY ) );
 68  0
         DEPRECATED_TRAC_COLUMNS.put( "reporter", new Integer( IssuesReportHelper.COLUMN_REPORTER ) );
 69  0
         DEPRECATED_TRAC_COLUMNS.put( "resolution", new Integer( IssuesReportHelper.COLUMN_RESOLUTION ) );
 70  0
         DEPRECATED_TRAC_COLUMNS.put( "status", new Integer( IssuesReportHelper.COLUMN_STATUS ) );
 71  0
         DEPRECATED_TRAC_COLUMNS.put( "summary", new Integer( IssuesReportHelper.COLUMN_SUMMARY ) );
 72  0
         DEPRECATED_TRAC_COLUMNS.put( "type", new Integer( IssuesReportHelper.COLUMN_TYPE ) );
 73  
 
 74  0
         TRAC_COLUMNS.put( "Assignee", new Integer( IssuesReportHelper.COLUMN_ASSIGNEE ) );
 75  0
         TRAC_COLUMNS.put( "Component", new Integer( IssuesReportHelper.COLUMN_COMPONENT ) );
 76  0
         TRAC_COLUMNS.put( "Created", new Integer( IssuesReportHelper.COLUMN_CREATED ) );
 77  0
         TRAC_COLUMNS.put( "Fix Version", new Integer( IssuesReportHelper.COLUMN_FIX_VERSION ) );
 78  0
         TRAC_COLUMNS.put( "Id", new Integer( IssuesReportHelper.COLUMN_ID ) );
 79  0
         TRAC_COLUMNS.put( "Priority", new Integer( IssuesReportHelper.COLUMN_PRIORITY ) );
 80  0
         TRAC_COLUMNS.put( "Reporter", new Integer( IssuesReportHelper.COLUMN_REPORTER ) );
 81  0
         TRAC_COLUMNS.put( "Resolution", new Integer( IssuesReportHelper.COLUMN_RESOLUTION ) );
 82  0
         TRAC_COLUMNS.put( "Status", new Integer( IssuesReportHelper.COLUMN_STATUS ) );
 83  0
         TRAC_COLUMNS.put( "Summary", new Integer( IssuesReportHelper.COLUMN_SUMMARY ) );
 84  0
         TRAC_COLUMNS.put( "Type", new Integer( IssuesReportHelper.COLUMN_TYPE ) );
 85  0
         TRAC_COLUMNS.put( "Updated", new Integer( IssuesReportHelper.COLUMN_UPDATED ) );
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Sets the column names that you want to show in the report. The columns
 90  
      * will appear in the report in the same order as you specify them here.
 91  
      * Multiple values can be separated by commas.
 92  
      * <p>
 93  
      * Valid columns are: <code>Assignee</code>, <code>Component</code>,
 94  
      * <code>Created</code>, <code>Fix Version</code>, <code>Id</code>,
 95  
      * <code>Priority</code>, <code>Reporter</code>, <code>Resolution</code>,
 96  
      * <code>Status</code>, <code>Summary</code>, <code>Type</code> and
 97  
      * <code>Updated</code>.
 98  
      * </p>
 99  
      *
 100  
      * @parameter default-value="Id,Type,Summary,Assignee,Reporter,Priority,Status,Resolution,Created,Updated"
 101  
      * @since 2.2
 102  
      */
 103  
     private String columnNames;
 104  
 
 105  
     /**
 106  
      * Defines the Trac query for searching ticket.
 107  
      *
 108  
      * @parameter default-value="order=id"
 109  
      */
 110  
     private String query;
 111  
 
 112  
     /**
 113  
      * Defines the Trac password for authentication into a private Trac
 114  
      * installation.
 115  
      *
 116  
      * @parameter default-value=""
 117  
      */
 118  
     private String tracPassword;
 119  
 
 120  
     /**
 121  
      * Defines the Trac username for authentication into a private Trac
 122  
      * installation.
 123  
      *
 124  
      * @parameter default-value=""
 125  
      */
 126  
     private String tracUser;
 127  
 
 128  
     /* --------------------------------------------------------------------- */
 129  
     /* Public methods                                                        */
 130  
     /* --------------------------------------------------------------------- */
 131  
 
 132  
     /**
 133  
      * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
 134  
      */
 135  
     public boolean canGenerateReport()
 136  
     {
 137  0
         return ProjectUtils.validateIfIssueManagementComplete( project, "Trac", "Trac Report", getLog() );
 138  
     }
 139  
 
 140  
     public void executeReport( Locale locale )
 141  
         throws MavenReportException
 142  
     {
 143  
         // Validate parameters
 144  0
         List<Integer> columnIds = IssuesReportHelper.getColumnIds( columnNames, TRAC_COLUMNS, DEPRECATED_TRAC_COLUMNS,
 145  
                                                                    getLog() );
 146  0
         if ( columnIds.size() == 0 )
 147  
         {
 148  
             // This can happen if the user has configured column names and they are all invalid
 149  0
             throw new MavenReportException(
 150  
                 "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." );
 151  
         }
 152  
 
 153  
         try
 154  
         {
 155  
             // Download issues
 156  0
             TracDownloader issueDownloader = new TracDownloader();
 157  0
             configureIssueDownloader( issueDownloader );
 158  
 
 159  0
             List issueList = issueDownloader.getIssueList();
 160  
 
 161  
             // Generate the report
 162  0
             IssuesReportGenerator report = new IssuesReportGenerator( IssuesReportHelper.toIntArray( columnIds ) );
 163  
 
 164  0
             if ( issueList.isEmpty() )
 165  
             {
 166  0
                 report.doGenerateEmptyReport( getBundle( locale ), getSink() );
 167  0
                 getLog().warn( "No ticket has matched." );
 168  
             }
 169  
             else
 170  
             {
 171  0
                 report.doGenerateReport( getBundle( locale ), getSink(), issueList );
 172  
             }
 173  
         }
 174  0
         catch ( MalformedURLException e )
 175  
         {
 176  
             // Rethrow this error so that the build fails
 177  0
             throw new MavenReportException( "The Trac URL is incorrect." );
 178  
         }
 179  0
         catch ( XmlRpcException e )
 180  
         {
 181  
             // Rethrow this error so that the build fails
 182  0
             throw new MavenReportException( "XmlRpc Error.", e );
 183  
         }
 184  0
         catch ( Exception e )
 185  
         {
 186  0
             e.printStackTrace();
 187  0
         }
 188  0
     }
 189  
 
 190  
     public String getDescription( Locale locale )
 191  
     {
 192  0
         return getBundle( locale ).getString( "report.issues.description" );
 193  
     }
 194  
 
 195  
     public String getName( Locale locale )
 196  
     {
 197  0
         return getBundle( locale ).getString( "report.issues.name" );
 198  
     }
 199  
 
 200  
     public String getOutputName()
 201  
     {
 202  0
         return "trac-report";
 203  
     }
 204  
 
 205  
     /* --------------------------------------------------------------------- */
 206  
     /* Private methods                                                       */
 207  
     /* --------------------------------------------------------------------- */
 208  
 
 209  
     private ResourceBundle getBundle( Locale locale )
 210  
     {
 211  0
         return ResourceBundle.getBundle( "trac-report", locale, this.getClass().getClassLoader() );
 212  
     }
 213  
 
 214  
     private void configureIssueDownloader( TracDownloader issueDownloader )
 215  
     {
 216  0
         issueDownloader.setProject( project );
 217  
 
 218  0
         issueDownloader.setQuery( query );
 219  
 
 220  0
         issueDownloader.setTracPassword( tracPassword );
 221  
 
 222  0
         issueDownloader.setTracUser( tracUser );
 223  0
     }
 224  
 }