You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2011/01/03 21:36:52 UTC
svn commit: r1054737 - in
/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira:
JiraMojo.java JiraReportGenerator.java
Author: dennisl
Date: Mon Jan 3 20:36:52 2011
New Revision: 1054737
URL: http://svn.apache.org/viewvc?rev=1054737&view=rev
Log:
Refactoring: Move all the column name/id/index voodoo from the ReportGenerator to the Mojo, and rewrite it to use Collections instead of arrays.
Modified:
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java
Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1054737&r1=1054736&r2=1054737&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java Mon Jan 3 20:36:52 2011
@@ -20,8 +20,11 @@ package org.apache.maven.plugin.jira;
*/
import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
import org.apache.maven.plugin.changes.AbstractChangesReport;
@@ -39,19 +42,34 @@ import org.apache.maven.settings.Setting
public class JiraMojo
extends AbstractChangesReport
{
- private static final String[] JIRA_COLUMNS = new String[] {
- /* 0 */ "Key",
- /* 1 */ "Summary",
- /* 2 */ "Status",
- /* 3 */ "Resolution",
- /* 4 */ "Assignee",
- /* 5 */ "Reporter",
- /* 6 */ "Type",
- /* 7 */ "Priority",
- /* 8 */ "Version",
- /* 9 */ "Fix Version",
- /* 10 */ "Component"
- };
+ static final int COLUMN_KEY = 0;
+ static final int COLUMN_SUMMARY = 1;
+ static final int COLUMN_STATUS = 2;
+ static final int COLUMN_RESOLUTION = 3;
+ static final int COLUMN_ASSIGNEE = 4;
+ static final int COLUMN_REPORTER = 5;
+ static final int COLUMN_TYPE = 6;
+ static final int COLUMN_PRIORITY = 7;
+ static final int COLUMN_VERSION = 8;
+ static final int COLUMN_FIX_VERSION = 9;
+ static final int COLUMN_COMPONENT = 10;
+
+ private static Map JIRA_COLUMNS = new HashMap();
+
+ static
+ {
+ JIRA_COLUMNS.put( "Key", new Integer( COLUMN_KEY ) );
+ JIRA_COLUMNS.put( "Summary", new Integer( COLUMN_SUMMARY ) );
+ JIRA_COLUMNS.put( "Status", new Integer( COLUMN_STATUS ) );
+ JIRA_COLUMNS.put( "Resolution", new Integer( COLUMN_RESOLUTION ) );
+ JIRA_COLUMNS.put( "Assignee", new Integer( COLUMN_ASSIGNEE ) );
+ JIRA_COLUMNS.put( "Reporter", new Integer( COLUMN_REPORTER ) );
+ JIRA_COLUMNS.put( "Type", new Integer( COLUMN_TYPE ) );
+ JIRA_COLUMNS.put( "Priority", new Integer( COLUMN_PRIORITY ) );
+ JIRA_COLUMNS.put( "Version", new Integer( COLUMN_VERSION ) );
+ JIRA_COLUMNS.put( "Fix Version", new Integer( COLUMN_FIX_VERSION ) );
+ JIRA_COLUMNS.put( "Component", new Integer( COLUMN_COMPONENT ) );
+ }
/**
* Path to the JIRA XML file, which will be parsed.
@@ -274,7 +292,7 @@ public class JiraMojo
JiraXML jira = new JiraXML( jiraXmlPath, jiraXmlEncoding );
List issueList = jira.getIssueList();
- report = new JiraReportGenerator( columnNames, JIRA_COLUMNS );
+ report = new JiraReportGenerator( toIntArray( getColumnIds( columnNames, JIRA_COLUMNS ) ) );
if ( onlyCurrentVersion )
{
@@ -303,6 +321,45 @@ public class JiraMojo
}
}
+ /**
+ * Get a list of id:s for the columns that are to be included in the report.
+ *
+ * @param columnNames The names of the columns
+ * @param allColumns A mapping from column name to column id
+ * @return A List of column id:s
+ */
+ private List getColumnIds( String columnNames, Map allColumns )
+ {
+ List columnIds = new ArrayList();
+ String[] columnNamesArray = columnNames.split( "," );
+ // Loop through the names of the columns, to validate each of them and add their id to the list
+ for ( int i = 0; i < columnNamesArray.length; i++ )
+ {
+ String columnName = columnNamesArray[i].trim();
+ if ( allColumns.containsKey( columnName ) )
+ {
+ columnIds.add( (Integer) allColumns.get( columnName ) );
+ }
+ }
+ return columnIds;
+ }
+
+ /**
+ * Convert a List of Integers to an int array.
+ *
+ * @param list The List to convert
+ * @return An in array
+ */
+ private int[] toIntArray( List list )
+ {
+ int[] intArray = new int[list.size()];
+ for ( int j = 0; j < intArray.length; j++ )
+ {
+ intArray[j] = ( (Integer) list.get( j ) ).intValue();
+ }
+ return intArray;
+ }
+
public String getName( Locale locale )
{
return getBundle( locale ).getString( "report.jira.name" );
Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java?rev=1054737&r1=1054736&r2=1054737&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java Mon Jan 3 20:36:52 2011
@@ -34,23 +34,11 @@ import java.util.ResourceBundle;
*/
public class JiraReportGenerator
{
- private static final int COLUMN_KEY = 0;
- private static final int COLUMN_SUMMARY = 1;
- private static final int COLUMN_STATUS = 2;
- private static final int COLUMN_RESOLUTION = 3;
- private static final int COLUMN_ASSIGNEE = 4;
- private static final int COLUMN_REPORTER = 5;
- private static final int COLUMN_TYPE = 6;
- private static final int COLUMN_PRIORITY = 7;
- private static final int COLUMN_VERSION = 8;
- private static final int COLUMN_FIX_VERSION = 9;
- private static final int COLUMN_COMPONENT = 10;
-
/**
* Holds the id:s for the columns to include in the report, in the order
* that they should appear in the report.
*/
- private int[] columnOrder;
+ private int[] columns;
public JiraReportGenerator()
{
@@ -58,38 +46,12 @@ public class JiraReportGenerator
}
/**
- * @param columnNames The names of the columns to include in the report
- * @param columns All column names available to this issue management system
+ * @param includedColumns The id:s of the columns to include in the report
*/
- public JiraReportGenerator( String columnNames, String[] columns )
+ public JiraReportGenerator( int[] includedColumns )
throws MavenReportException
{
- String[] columnNamesArray = columnNames.split( "," );
- int validColumnNames = 0;
- columnOrder = new int[columnNamesArray.length];
- for ( int i = 0; i < columnOrder.length; i++ )
- {
- // Default to -1, indicating that the column should not be included in the report
- columnOrder[i] = -1;
- // Loop through the names of all columns
- for ( int columnIndex = 0; columnIndex < columns.length; columnIndex++ )
- {
- String columnName = columnNamesArray[i].trim();
- if ( columns[columnIndex].equalsIgnoreCase( columnName ) )
- {
- // Found a valid column name - add it
- columnOrder[i] = columnIndex;
- validColumnNames++;
- break;
- }
- }
- }
- if ( validColumnNames == 0 )
- {
- // This can happen if the user has configured column names and they are all invalid
- throw new MavenReportException(
- "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." );
- }
+ this.columns = includedColumns;
}
public void doGenerateEmptyReport( ResourceBundle bundle, Sink sink )
@@ -127,51 +89,51 @@ public class JiraReportGenerator
sink.tableRow();
- for ( int columnIndex = 0; columnIndex < columnOrder.length; columnIndex++ )
+ for ( int columnIndex = 0; columnIndex < columns.length; columnIndex++ )
{
- switch ( columnOrder[columnIndex] )
+ switch ( columns[columnIndex] )
{
- case COLUMN_KEY:
+ case JiraMojo.COLUMN_KEY:
sinkHeader( sink, bundle.getString( "report.jira.label.key" ) );
break;
- case COLUMN_SUMMARY:
+ case JiraMojo.COLUMN_SUMMARY:
sinkHeader( sink, bundle.getString( "report.jira.label.summary" ) );
break;
- case COLUMN_STATUS:
+ case JiraMojo.COLUMN_STATUS:
sinkHeader( sink, bundle.getString( "report.jira.label.status" ) );
break;
- case COLUMN_RESOLUTION:
+ case JiraMojo.COLUMN_RESOLUTION:
sinkHeader( sink, bundle.getString( "report.jira.label.resolution" ) );
break;
- case COLUMN_ASSIGNEE:
+ case JiraMojo.COLUMN_ASSIGNEE:
sinkHeader( sink, bundle.getString( "report.jira.label.by" ) );
break;
- case COLUMN_REPORTER:
+ case JiraMojo.COLUMN_REPORTER:
sinkHeader( sink, bundle.getString( "report.jira.label.reporter" ) );
break;
- case COLUMN_TYPE:
+ case JiraMojo.COLUMN_TYPE:
sinkHeader( sink, bundle.getString( "report.jira.label.type" ) );
break;
- case COLUMN_PRIORITY:
+ case JiraMojo.COLUMN_PRIORITY:
sinkHeader( sink, bundle.getString( "report.jira.label.priority" ) );
break;
- case COLUMN_VERSION:
+ case JiraMojo.COLUMN_VERSION:
sinkHeader( sink, bundle.getString( "report.jira.label.version" ) );
break;
- case COLUMN_FIX_VERSION:
+ case JiraMojo.COLUMN_FIX_VERSION:
sinkHeader( sink, bundle.getString( "report.jira.label.fixVersion" ) );
break;
- case COLUMN_COMPONENT:
+ case JiraMojo.COLUMN_COMPONENT:
sinkHeader( sink, bundle.getString( "report.jira.label.component" ) );
break;
@@ -197,11 +159,11 @@ public class JiraReportGenerator
sink.tableRow();
- for ( int columnIndex = 0; columnIndex < columnOrder.length; columnIndex++ )
+ for ( int columnIndex = 0; columnIndex < columns.length; columnIndex++ )
{
- switch ( columnOrder[columnIndex] )
+ switch ( columns[columnIndex] )
{
- case COLUMN_KEY:
+ case JiraMojo.COLUMN_KEY:
sink.tableCell();
sink.link( issue.getLink() );
sink.text( issue.getKey() );
@@ -209,43 +171,43 @@ public class JiraReportGenerator
sink.tableCell_();
break;
- case COLUMN_SUMMARY:
+ case JiraMojo.COLUMN_SUMMARY:
sinkCell( sink, issue.getSummary() );
break;
- case COLUMN_STATUS:
+ case JiraMojo.COLUMN_STATUS:
sinkCell( sink, issue.getStatus() );
break;
- case COLUMN_RESOLUTION:
+ case JiraMojo.COLUMN_RESOLUTION:
sinkCell( sink, issue.getResolution() );
break;
- case COLUMN_ASSIGNEE:
+ case JiraMojo.COLUMN_ASSIGNEE:
sinkCell( sink, issue.getAssignee() );
break;
- case COLUMN_REPORTER:
+ case JiraMojo.COLUMN_REPORTER:
sinkCell( sink, issue.getReporter() );
break;
- case COLUMN_TYPE:
+ case JiraMojo.COLUMN_TYPE:
sinkCell( sink, issue.getType() );
break;
- case COLUMN_PRIORITY:
+ case JiraMojo.COLUMN_PRIORITY:
sinkCell( sink, issue.getPriority() );
break;
- case COLUMN_VERSION:
+ case JiraMojo.COLUMN_VERSION:
sinkCell( sink, issue.getVersion() );
break;
- case COLUMN_FIX_VERSION:
+ case JiraMojo.COLUMN_FIX_VERSION:
sinkCell( sink, IssuesReportGenerator.printValues( issue.getFixVersions() ) );
break;
- case COLUMN_COMPONENT:
+ case JiraMojo.COLUMN_COMPONENT:
sinkCell( sink, IssuesReportGenerator.printValues( issue.getComponents() ) );
break;