svn commit: r422314 - in /maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven: announcement/JiraAnnouncementDownloader.java jira/JiraDownloader2.java jira/JiraHelper.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r422314 - in /maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven: announcement/JiraAnnouncementDownloader.java jira/JiraDownloader2.java jira/JiraHelper.java

Dennis Lundberg-2
Author: dennisl
Date: Sat Jul 15 16:06:35 2006
New Revision: 422314

URL: http://svn.apache.org/viewvc?rev=422314&view=rev
Log:
Refactor a JIRA helper method into a helper class, so it can be used from the announcement mojo as well

Added:
    maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraHelper.java
Modified:
    maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/announcement/JiraAnnouncementDownloader.java
    maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraDownloader2.java

Modified: maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/announcement/JiraAnnouncementDownloader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/announcement/JiraAnnouncementDownloader.java?rev=422314&r1=422313&r2=422314&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/announcement/JiraAnnouncementDownloader.java (original)
+++ maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/announcement/JiraAnnouncementDownloader.java Sat Jul 15 16:06:35 2006
@@ -26,6 +26,7 @@
 import org.apache.commons.httpclient.StatusLine;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.maven.jira.JiraHelper;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.settings.Proxy;
@@ -148,7 +149,6 @@
             }
         }
 
-        
         // get the Priority Ids
         if ( priorityIds != null )
         {
@@ -210,7 +210,7 @@
         throws Exception
     {
         try
-        {            
+        {
             HttpClient cl = new HttpClient();
             
             HttpState state = new HttpState();
@@ -231,12 +231,16 @@
             
             doAuthentication( cl, jiraUrl );
 
+            if ( jiraId == null || jiraId.length() == 0 )
+            {
+                jiraId = JiraHelper.getPidFromJira( log, project.getIssueManagement().getUrl(), cl );
+            }
+
             // create the URL for getting the proper issues from JIRA
             String fullURL = jiraUrl + "/secure/IssueNavigator.jspa?view=rss&pid=" + jiraId;
             
-            //TODO:only for a temporary use case,
-            //hardcoded of for fix version
-            fullURL += "&fixfor=12000";
+            // @todo: only for a temporary use case, hardcoded fix-for version
+            fullURL += "&fixfor=12730";
             
             fullURL += createFilter();
             
@@ -271,11 +275,11 @@
 
         String jiraUrl = url.substring( 0, url.lastIndexOf( "/" ) );
 
-        if ( jiraUrl.endsWith( "secure" ) )
+        if ( jiraUrl.endsWith( "secure" ) || jiraUrl.endsWith( "browse" ) )
         {
             jiraUrl = jiraUrl.substring( 0, jiraUrl.lastIndexOf( "/" ) );
         }
-        getLog().info( "Jira lives at: " + jiraUrl );  
+        getLog().info( "Jira lives at: " + jiraUrl );
         
         urlMap.put("url", jiraUrl);
         
@@ -374,12 +378,12 @@
         }
 
         if ( settings != null )
-        {  
+        {
             proxy = settings.getActiveProxy();
         }
 
         if ( proxy != null )
-        {  
+        {
             proxyHost = settings.getActiveProxy().getHost();
             
             proxyPort = settings.getActiveProxy().getPort();
@@ -428,7 +432,7 @@
 
             final String strGetResponseBody = gm.getResponseBodyAsString();
             
-            // write the reponse to file          
+            // write the reponse to file
             PrintWriter pw = new PrintWriter( new FileWriter( getOutput() ) );
             
             pw.print( strGetResponseBody );

Modified: maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraDownloader2.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraDownloader2.java?rev=422314&r1=422313&r2=422314&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraDownloader2.java (original)
+++ maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraDownloader2.java Sat Jul 15 16:06:35 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.jira;
 
 /* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+ *   Copyright 2001-2006 The Apache Software Foundation.
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -243,7 +241,7 @@
 
             if ( jiraId == null || jiraId.length() == 0 )
             {
-                jiraId = getPidFromJira( cl );
+                jiraId = JiraHelper.getPidFromJira( log, project.getIssueManagement().getUrl(), cl );
             }
 
             // create the URL for getting the proper issues from JIRA
@@ -260,50 +258,6 @@
         {
             getLog().error( "Error accessing " + project.getIssueManagement().getUrl(), e );
         }
-    }
-
-    /**
-     * Try to get a JIRA pid from the issue management URL.
-     *
-     * @param client The client used to connect to JIRA
-     * @return The JIRA id for the project, or null if it can't be found
-     */
-    private String getPidFromJira( HttpClient client )
-    {
-        String jiraId = null;
-        GetMethod gm = new GetMethod( project.getIssueManagement().getUrl() );
-        log.info( "JIRA URL " + project.getIssueManagement().getUrl() + " doesn't include a pid, trying to get it" );
-        try
-        {
-            client.executeMethod( gm );
-            log.info( "Successfully reached JIRA." );
-        }
-        catch ( Exception e )
-        {
-            if ( log.isDebugEnabled() )
-            {
-                log.error( "Unable to reach JIRA project page:", e );
-            }
-            else
-            {
-                log.error( "Unable to reach JIRA project page. Cause is: " + e.getLocalizedMessage() );
-            }
-        }
-        String projectPage = gm.getResponseBodyAsString();
-        int pidIndex = projectPage.indexOf( "pid=" );
-
-        if ( pidIndex == -1 )
-        {
-            log.error( "Unable to get JIRA pid using the url " + project.getIssueManagement().getUrl() );
-        }
-        else
-        {
-            NumberFormat nf = NumberFormat.getInstance();
-            Number pidNumber = nf.parse( projectPage, new ParsePosition( pidIndex + 4 ) );
-            jiraId = Integer.toString( pidNumber.intValue() );
-            log.debug( "Found the pid " + jiraId + " at " + project.getIssueManagement().getUrl() );
-        }
-        return jiraId;
     }
 
     private Map getJiraUrlAndIssueId()

Added: maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraHelper.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraHelper.java?rev=422314&view=auto
==============================================================================
--- maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraHelper.java (added)
+++ maven/sandbox/plugins/maven-changes-plugin/src/main/java/org/apache/maven/jira/JiraHelper.java Sat Jul 15 16:06:35 2006
@@ -0,0 +1,80 @@
+package org.apache.maven.jira;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+
+/**
+ * A helper class with common JIRA related functionality.
+ *
+ * @author Dennis Lundberg
+ * @version $Id: JiraHelper.java 422265 2006-07-15 16:49:50 +0000 (lö, 15 jul 2006) dennisl $
+ */
+public class JiraHelper
+{
+    /**
+     * Try to get a JIRA pid from the issue management URL.
+     *
+     * @param log     Used to tell the user what happened
+     * @param issueManagementUrl The URL to the issue management system
+     * @param client  The client used to connect to JIRA
+     * @return The JIRA id for the project, or null if it can't be found
+     */
+    public static String getPidFromJira( Log log, String issueManagementUrl, HttpClient client )
+    {
+        String jiraId = null;
+        GetMethod gm = new GetMethod( issueManagementUrl );
+        log.info( "JIRA URL " + issueManagementUrl + " doesn't include a pid, trying to get it" );
+        try
+        {
+            client.executeMethod( gm );
+            log.info( "Successfully reached JIRA." );
+        }
+        catch ( Exception e )
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.error( "Unable to reach JIRA project page:", e );
+            }
+            else
+            {
+                log.error( "Unable to reach JIRA project page. Cause is: " + e.getLocalizedMessage() );
+            }
+        }
+        String projectPage = gm.getResponseBodyAsString();
+        int pidIndex = projectPage.indexOf( "pid=" );
+
+        if ( pidIndex == -1 )
+        {
+            log.error( "Unable to get JIRA pid using the url " + issueManagementUrl );
+        }
+        else
+        {
+            NumberFormat nf = NumberFormat.getInstance();
+            Number pidNumber = nf.parse( projectPage, new ParsePosition( pidIndex + 4 ) );
+            jiraId = Integer.toString( pidNumber.intValue() );
+            log.debug( "Found the pid " + jiraId + " at " + issueManagementUrl );
+        }
+        return jiraId;
+    }
+}