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