maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r1054097 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac: TracDownloader.java TracMojo.java TracReportGenerator.java
Date Fri, 31 Dec 2010 11:53:27 GMT
Author: dennisl
Date: Fri Dec 31 11:53:26 2010
New Revision: 1054097

URL: http://svn.apache.org/viewvc?rev=1054097&view=rev
Log:
o Refactoring: move the downloading of tickets from Trac to its own class.

Added:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
  (with props)
Modified:
    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

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java?rev=1054097&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
Fri Dec 31 11:53:26 2010
@@ -0,0 +1,169 @@
+package org.apache.maven.plugin.trac;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.project.MavenProject;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Get issues from a Trac installation.
+ *
+ * @author Dennis Lundberg
+ * @version $Id$
+ * @since 2.4
+ */
+public class TracDownloader
+{
+    /** The Maven project. */
+    private MavenProject project;
+    /** The Trac query for searching for tickets. */
+    private String query;
+    /** The password for authentication into a private Trac installation. */
+    private String tracPassword;
+    /** The username for authentication into a private Trac installation. */
+    private String tracUser;
+
+    private TracTicket createTicket( Object[] ticketObj )
+    {
+        TracTicket ticket = new TracTicket();
+
+        ticket.setId( String.valueOf( ticketObj[0] ) );
+
+        ticket.setLink( getUrl() + "/ticket/" + String.valueOf( ticketObj[0] ) );
+
+        ticket.setTimeCreated( String.valueOf( ticketObj[1] ) );
+
+        ticket.setTimeChanged( String.valueOf( ticketObj[2] ) );
+
+        Map attributes = (Map) ticketObj[3];
+
+        ticket.setType( (String) attributes.get( "type" ) );
+
+        ticket.setSummary( (String) attributes.get( "summary" ) );
+
+        ticket.setStatus( (String) attributes.get( "status" ) );
+
+        ticket.setResolution( (String) attributes.get( "resolution" ) );
+
+        ticket.setOwner( (String) attributes.get( "owner" ) );
+
+        ticket.setMilestone( (String) attributes.get( "milestone" ) );
+
+        ticket.setPriority( (String) attributes.get( "priority" ) );
+
+        ticket.setReporter( (String) attributes.get( "reporter" ) );
+
+        ticket.setComponent( (String) attributes.get( "component" ) );
+
+        return ticket;
+    }
+
+    public List getIssueList() throws MalformedURLException, XmlRpcException
+    {
+        // Create and configure an XML-RPC client
+        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+
+        try
+        {
+            config.setServerURL( new URL( getUrl() + "/login/xmlrpc" ) );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new MalformedURLException( "The Trac URL is incorrect." );
+        }
+        config.setBasicUserName( tracUser );
+        config.setBasicPassword( tracPassword );
+
+        XmlRpcClient client = new XmlRpcClient();
+
+        client.setConfig( config );
+
+        // Fetch tickets
+        String qstr = "";
+
+        if ( !StringUtils.isEmpty( query ) )
+        {
+            qstr = query;
+        }
+
+        Object[] params = new Object[] { new String( qstr ) };
+        Object[] queryResult = null;
+        ArrayList ticketList = new ArrayList();
+        try
+        {
+            queryResult = (Object[]) client.execute( "ticket.query", params );
+
+            for ( int i = 0; i < queryResult.length; i++ )
+            {
+                params = new Object[] { queryResult[i] };
+                Object[] ticketGetResult = null;
+                ticketGetResult = (Object[]) client.execute( "ticket.get", params );
+                ticketList.add( createTicket( ticketGetResult ) );
+            }
+        }
+        catch ( XmlRpcException e )
+        {
+            throw new XmlRpcException( "XmlRpc Error.", e );
+        }
+        return ticketList;
+    }
+
+    private String getUrl()
+    {
+
+        String url = project.getIssueManagement().getUrl();
+
+        if ( url.endsWith( "/" ) )
+        {
+            url = url.substring( 0, url.length() - 1 );
+        }
+
+        return url;
+    }
+
+    public void setProject( MavenProject project )
+    {
+        this.project = project;
+    }
+
+    public void setQuery( String query )
+    {
+        this.query = query;
+    }
+
+    public void setTracPassword( String tracPassword )
+    {
+        this.tracPassword = tracPassword;
+    }
+
+    public void setTracUser( String tracUser )
+    {
+        this.tracUser = tracUser;
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/trac/TracDownloader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

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=1054097&r1=1054096&r2=1054097&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
Fri Dec 31 11:53:26 2010
@@ -20,10 +20,8 @@ package org.apache.maven.plugin.trac;
  */
 
 import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 import java.util.ResourceBundle;
 
 import org.apache.maven.doxia.siterenderer.Renderer;
@@ -32,9 +30,6 @@ import org.apache.maven.plugin.changes.P
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Goal which downloads issues from the Issue Tracking System and generates a
@@ -96,75 +91,56 @@ public class TracMojo
         return ProjectUtils.validateIfIssueManagementComplete( project, "Trac", "Trac Report",
getLog() );
     }
 
-    public void executeReport( Locale locale )
-        throws MavenReportException
+    private void configureIssueDownloader( TracDownloader issueDownloader )
     {
-        // Create and configure an XML-RPC client
-        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+        issueDownloader.setProject( project );
 
-        try
-        {
-            config.setServerURL( new URL( getTracUrl() + "/login/xmlrpc" ) );
-        }
-        catch ( MalformedURLException e1 )
-        {
+        issueDownloader.setQuery( query );
 
-            throw new MavenReportException( "The Trac URL is incorrect." );
+        issueDownloader.setTracPassword( tracPassword );
 
-        }
-        config.setBasicUserName( tracUser );
-        config.setBasicPassword( tracPassword );
-
-        XmlRpcClient client = new XmlRpcClient();
-
-        client.setConfig( config );
-
-        // Fetch tickets from Trac
-        String qstr = "";
+        issueDownloader.setTracUser( tracUser );
+    }
 
-        if ( !StringUtils.isEmpty( query ) )
-        {
-            qstr = query;
-        }
+    public void executeReport( Locale locale )
+        throws MavenReportException
+    {
+        TracDownloader issueDownloader = new TracDownloader();
+        configureIssueDownloader( issueDownloader );
 
-        Object[] params = new Object[] { new String( qstr ) };
-        Object[] queryResult = null;
-        ArrayList ticketList = new ArrayList();
         try
         {
-            queryResult = (Object[]) client.execute( "ticket.query", params );
+            List ticketList = issueDownloader.getIssueList();
 
-            for ( int i = 0; i < queryResult.length; i++ )
+            // Generate the report
+            TracReportGenerator report = new TracReportGenerator( columnNames );
+
+            if ( ticketList.isEmpty() )
             {
-                params = new Object[] { queryResult[i] };
-                Object[] ticketGetResult = null;
-                ticketGetResult = (Object[]) client.execute( "ticket.get", params );
-                ticketList.add( createTicket( ticketGetResult ) );
+                report.doGenerateEmptyReport( getBundle( locale ), getSink() );
+                getLog().warn( "No ticket has matched." );
+            }
+            else
+            {
+                try
+                {
+                    report.doGenerateReport( getBundle( locale ), getSink(), ticketList );
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
             }
         }
-        catch ( XmlRpcException e )
-        {
-            throw new MavenReportException( "XmlRpc Error.", e );
-        }
-
-        // Generate the report
-        TracReportGenerator report = new TracReportGenerator( columnNames );
-
-        if ( ticketList.isEmpty() )
+        catch ( MalformedURLException e )
         {
-            report.doGenerateEmptyReport( getBundle( locale ), getSink() );
-            getLog().warn( "No ticket has matched." );
+            // Rethrow this error so that the build fails
+            throw new MavenReportException( "The Trac URL is incorrect." );
         }
-        else
+        catch ( XmlRpcException e )
         {
-            try
-            {
-                report.doGenerateReport( getBundle( locale ), getSink(), ticketList );
-            }
-            catch ( Exception e )
-            {
-                e.printStackTrace();
-            }
+            // Rethrow this error so that the build fails
+            throw new MavenReportException( "XmlRpc Error.", e );
         }
     }
 
@@ -197,52 +173,4 @@ public class TracMojo
     {
         return ResourceBundle.getBundle( "trac-report", locale, this.getClass().getClassLoader()
);
     }
-
-    private String getTracUrl()
-    {
-
-        String tracUrl = project.getIssueManagement().getUrl();
-
-        if ( tracUrl.endsWith( "/" ) )
-        {
-            tracUrl = tracUrl.substring( 0, tracUrl.length() - 1 );
-        }
-
-        return tracUrl;
-    }
-
-    private TracTicket createTicket( Object[] ticketObj )
-    {
-        TracTicket ticket = new TracTicket();
-
-        ticket.setId( String.valueOf( ticketObj[0] ) );
-
-        ticket.setLink( getTracUrl() + "/ticket/" + String.valueOf( ticketObj[0] ) );
-
-        ticket.setTimeCreated( String.valueOf( ticketObj[1] ) );
-
-        ticket.setTimeChanged( String.valueOf( ticketObj[2] ) );
-
-        Map attributes = (Map) ticketObj[3];
-
-        ticket.setType( (String) attributes.get( "type" ) );
-
-        ticket.setSummary( (String) attributes.get( "summary" ) );
-
-        ticket.setStatus( (String) attributes.get( "status" ) );
-
-        ticket.setResolution( (String) attributes.get( "resolution" ) );
-
-        ticket.setOwner( (String) attributes.get( "owner" ) );
-
-        ticket.setMilestone( (String) attributes.get( "milestone" ) );
-
-        ticket.setPriority( (String) attributes.get( "priority" ) );
-
-        ticket.setReporter( (String) attributes.get( "reporter" ) );
-
-        ticket.setComponent( (String) attributes.get( "component" ) );
-
-        return ticket;
-    }
 }

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=1054097&r1=1054096&r2=1054097&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
Fri Dec 31 11:53:26 2010
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.trac;
  */
 
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.ResourceBundle;
 
@@ -111,7 +110,7 @@ public class TracReportGenerator
         sinkEndReport( sink );
     }
 
-    public void doGenerateReport( ResourceBundle bundle, Sink sink, ArrayList ticketList
)
+    public void doGenerateReport( ResourceBundle bundle, Sink sink, List ticketList )
     {
         sinkBeginReport( sink, bundle );
 



Mime
View raw message