maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r1054744 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin: jira/JiraMojo.java trac/TracMojo.java trac/TracReportGenerator.java
Date Mon, 03 Jan 2011 20:51:34 GMT
Author: dennisl
Date: Mon Jan  3 20:51:34 2011
New Revision: 1054744

URL: http://svn.apache.org/viewvc?rev=1054744&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/trac/TracMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracReportGenerator.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=1054744&r1=1054743&r2=1054744&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:51:34 2011
@@ -54,6 +54,9 @@ public class JiraMojo
     static final int COLUMN_FIX_VERSION = 9;
     static final int COLUMN_COMPONENT = 10;
 
+    /**
+     * Valid JIRA columns.
+     */
     private static Map JIRA_COLUMNS = new HashMap();
 
     static
@@ -292,7 +295,14 @@ public class JiraMojo
                 JiraXML jira = new JiraXML( jiraXmlPath, jiraXmlEncoding );
                 List issueList = jira.getIssueList();
 
-                report = new JiraReportGenerator( toIntArray( getColumnIds( columnNames,
JIRA_COLUMNS ) ) );
+                List columnIds = getColumnIds( columnNames, JIRA_COLUMNS );
+                if ( columnIds.size() == 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." );
+                }
+                report = new JiraReportGenerator( toIntArray( columnIds ) );
 
                 if ( onlyCurrentVersion )
                 {
@@ -327,8 +337,9 @@ public class JiraMojo
      * @param columnNames The names of the columns
      * @param allColumns A mapping from column name to column id
      * @return A List of column id:s
+     * @todo Move to helper class
      */
-    private List getColumnIds( String columnNames, Map allColumns )
+    public static List getColumnIds( String columnNames, Map allColumns )
     {
         List columnIds = new ArrayList();
         String[] columnNamesArray = columnNames.split( "," );
@@ -349,8 +360,9 @@ public class JiraMojo
      *
      * @param list The List to convert
      * @return An in array
+     * @todo Move to helper class
      */
-    private int[] toIntArray( List list )
+    public static int[] toIntArray( List list )
     {
         int[] intArray = new int[list.size()];
         for ( int j = 0; j < intArray.length; j++ )

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracMojo.java?rev=1054744&r1=1054743&r2=1054744&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
Mon Jan  3 20:51:34 2011
@@ -20,13 +20,17 @@ package org.apache.maven.plugin.trac;
  */
 
 import java.net.MalformedURLException;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ResourceBundle;
 
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.plugin.changes.AbstractChangesReport;
 import org.apache.maven.plugin.changes.ProjectUtils;
+import org.apache.maven.plugin.jira.JiraMojo;
+import org.apache.maven.plugin.jira.JiraReportGenerator;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.xmlrpc.XmlRpcException;
@@ -43,23 +47,39 @@ import org.apache.xmlrpc.XmlRpcException
 public class TracMojo
     extends AbstractChangesReport
 {
+    static final int COLUMN_ID = 0;
+    static final int COLUMN_TYPE = 1;
+    static final int COLUMN_SUMMARY = 2;
+    static final int COLUMN_STATUS = 3;
+    static final int COLUMN_RESOLUTION = 4;
+    static final int COLUMN_MILESTONE = 5;
+    static final int COLUMN_OWNER = 6;
+    static final int COLUMN_PRIORITY = 7;
+    static final int COLUMN_REPORTER = 8;
+    static final int COLUMN_COMPONENT = 9;
+    static final int COLUMN_CREATED = 10;
+    static final int COLUMN_CHANGED = 11;
+
     /**
      * Valid Trac columns.
      */
-    private static final String[] TRAC_COLUMNS = {
-            /* 0 */ "id",
-            /* 1 */ "type",
-            /* 2 */ "summary",
-            /* 3 */ "status",
-            /* 4 */ "resolution",
-            /* 5 */ "milestone",
-            /* 6 */ "owner",
-            /* 7 */ "priority",
-            /* 8 */ "reporter",
-            /* 9 */ "component",
-            /* 10 */ "created",
-            /* 11 */ "changed"
-    };
+    private static Map TRAC_COLUMNS = new HashMap();
+
+    static
+    {
+        TRAC_COLUMNS.put( "id", new Integer( COLUMN_ID ) );
+        TRAC_COLUMNS.put( "type", new Integer( COLUMN_TYPE ) );
+        TRAC_COLUMNS.put( "summary", new Integer( COLUMN_SUMMARY ) );
+        TRAC_COLUMNS.put( "status", new Integer( COLUMN_STATUS ) );
+        TRAC_COLUMNS.put( "resolution", new Integer( COLUMN_RESOLUTION ) );
+        TRAC_COLUMNS.put( "milestone", new Integer( COLUMN_MILESTONE ) );
+        TRAC_COLUMNS.put( "owner", new Integer( COLUMN_OWNER ) );
+        TRAC_COLUMNS.put( "priority", new Integer( COLUMN_PRIORITY ) );
+        TRAC_COLUMNS.put( "reporter", new Integer( COLUMN_REPORTER ) );
+        TRAC_COLUMNS.put( "component", new Integer( COLUMN_COMPONENT ) );
+        TRAC_COLUMNS.put( "created", new Integer( COLUMN_CREATED ) );
+        TRAC_COLUMNS.put( "changed", new Integer( COLUMN_CHANGED ) );
+    }
 
     /**
      * Defines the Trac username for authentication into a private Trac
@@ -130,8 +150,16 @@ public class TracMojo
         {
             List issueList = issueDownloader.getIssueList();
 
+            List columnIds = JiraMojo.getColumnIds( columnNames, TRAC_COLUMNS );
+            if ( columnIds.size() == 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." );
+            }
+
             // Generate the report
-            TracReportGenerator report = new TracReportGenerator( columnNames, TRAC_COLUMNS
);
+            TracReportGenerator report = new TracReportGenerator( JiraMojo.toIntArray( columnIds
) );
 
             if ( issueList.isEmpty() )
             {

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracReportGenerator.java?rev=1054744&r1=1054743&r2=1054744&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracReportGenerator.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracReportGenerator.java
Mon Jan  3 20:51:34 2011
@@ -36,49 +36,19 @@ import org.apache.maven.reporting.MavenR
  */
 public class TracReportGenerator
 {
-    private static final int COLUMN_ID = 0;
-    private static final int COLUMN_TYPE = 1;
-    private static final int COLUMN_SUMMARY = 2;
-    private static final int COLUMN_STATUS = 3;
-    private static final int COLUMN_RESOLUTION = 4;
-    private static final int COLUMN_MILESTONE = 5;
-    private static final int COLUMN_OWNER = 6;
-    private static final int COLUMN_PRIORITY = 7;
-    private static final int COLUMN_REPORTER = 8;
-    private static final int COLUMN_COMPONENT = 9;
-    private static final int COLUMN_CREATED = 10;
-    private static final int COLUMN_CHANGED = 11;
-
-    private int[] columnOrder;
-
-    public TracReportGenerator( String columnNames, String[] columns )
+    /**
+     * Holds the id:s for the columns to include in the report, in the order
+     * that they should appear in the report.
+     */
+    private int[] columns;
+
+    /**
+     * @param includedColumns The id:s of the columns to include in the report
+     */
+    public TracReportGenerator( 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;
-            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 )
@@ -116,44 +86,44 @@ public class TracReportGenerator
 
         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_ID:
+                case TracMojo.COLUMN_ID:
                     sinkHeader( sink, bundle.getString( "report.trac.label.id" ) );
                     break;
-                case COLUMN_TYPE:
+                case TracMojo.COLUMN_TYPE:
                     sinkHeader( sink, bundle.getString( "report.trac.label.type" ) );
                     break;
-                case COLUMN_SUMMARY:
+                case TracMojo.COLUMN_SUMMARY:
                     sinkHeader( sink, bundle.getString( "report.trac.label.summary" ) );
                     break;
-                case COLUMN_OWNER:
+                case TracMojo.COLUMN_OWNER:
                     sinkHeader( sink, bundle.getString( "report.trac.label.owner" ) );
                     break;
-                case COLUMN_REPORTER:
+                case TracMojo.COLUMN_REPORTER:
                     sinkHeader( sink, bundle.getString( "report.trac.label.reporter" ) );
                     break;
-                case COLUMN_PRIORITY:
+                case TracMojo.COLUMN_PRIORITY:
                     sinkHeader( sink, bundle.getString( "report.trac.label.priority" ) );
                     break;
-                case COLUMN_STATUS:
+                case TracMojo.COLUMN_STATUS:
                     sinkHeader( sink, bundle.getString( "report.trac.label.status" ) );
                     break;
-                case COLUMN_RESOLUTION:
+                case TracMojo.COLUMN_RESOLUTION:
                     sinkHeader( sink, bundle.getString( "report.trac.label.resolution" )
);
                     break;
-                case COLUMN_CREATED:
+                case TracMojo.COLUMN_CREATED:
                     sinkHeader( sink, bundle.getString( "report.trac.label.created" ) );
                     break;
-                case COLUMN_CHANGED:
+                case TracMojo.COLUMN_CHANGED:
                     sinkHeader( sink, bundle.getString( "report.trac.label.changed" ) );
                     break;
-                case COLUMN_MILESTONE:
+                case TracMojo.COLUMN_MILESTONE:
                     sinkHeader( sink, bundle.getString( "report.trac.label.milestone" ) );
                     break;
-                case COLUMN_COMPONENT:
+                case TracMojo.COLUMN_COMPONENT:
                     sinkHeader( sink, bundle.getString( "report.trac.label.component" ) );
                     break;
                 default:
@@ -180,48 +150,48 @@ public class TracReportGenerator
 
             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_ID:
+                    case TracMojo.COLUMN_ID:
                         sink.tableCell();
                         sink.link( issue.getLink() );
                         sink.text( issue.getId() );
                         sink.link_();
                         sink.tableCell_();
                         break;
-                    case COLUMN_TYPE:
+                    case TracMojo.COLUMN_TYPE:
                         sinkCell( sink, issue.getType() );
                         break;
-                    case COLUMN_SUMMARY:
+                    case TracMojo.COLUMN_SUMMARY:
                         sinkCell( sink, issue.getSummary() );
                         break;
-                    case COLUMN_OWNER:
+                    case TracMojo.COLUMN_OWNER:
                         sinkCell( sink, issue.getAssignee() );
                         break;
-                    case COLUMN_REPORTER:
+                    case TracMojo.COLUMN_REPORTER:
                         sinkCell( sink, issue.getReporter() );
                         break;
-                    case COLUMN_PRIORITY:
+                    case TracMojo.COLUMN_PRIORITY:
                         sinkCell( sink, issue.getPriority() );
                         break;
-                    case COLUMN_STATUS:
+                    case TracMojo.COLUMN_STATUS:
                         sinkCell( sink, issue.getStatus() );
                         break;
-                    case COLUMN_RESOLUTION:
+                    case TracMojo.COLUMN_RESOLUTION:
                         sinkCell( sink, issue.getResolution() );
                         break;
-                    case COLUMN_CREATED:
+                    case TracMojo.COLUMN_CREATED:
                         sinkCell( sink, sdf.format( issue.getCreated() ) );
                         break;
-                    case COLUMN_CHANGED:
+                    case TracMojo.COLUMN_CHANGED:
                         sinkCell( sink, sdf.format( issue.getUpdated() ) );
                         break;
-                    case COLUMN_MILESTONE:
+                    case TracMojo.COLUMN_MILESTONE:
                         sinkCell( sink, IssuesReportGenerator.printValues( issue.getFixVersions()
) );
                         break;
-                    case COLUMN_COMPONENT:
+                    case TracMojo.COLUMN_COMPONENT:
                         sinkCell( sink, IssuesReportGenerator.printValues( issue.getComponents()
) );
                         break;
                     default:



Mime
View raw message