Coverage Report - org.apache.maven.plugin.jira.JiraHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
JiraHelper
0%
0/20
0%
0/4
5
 
 1  
 package org.apache.maven.plugin.jira;
 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.text.NumberFormat;
 23  
 import java.text.ParsePosition;
 24  
 
 25  
 import org.apache.commons.httpclient.HttpClient;
 26  
 import org.apache.commons.httpclient.methods.GetMethod;
 27  
 import org.apache.maven.plugin.logging.Log;
 28  
 
 29  
 /**
 30  
  * A helper class with common JIRA related functionality.
 31  
  *
 32  
  * @author Dennis Lundberg
 33  
  * @version $Id: org.apache.maven.plugin.jira.JiraHelper.html 816588 2012-05-08 12:37:27Z hboutemy $
 34  
  */
 35  0
 public class JiraHelper
 36  
 {
 37  
     private static final String PID = "pid=";
 38  
 
 39  
     /**
 40  
      * Try to get a JIRA pid from the issue management URL.
 41  
      *
 42  
      * @param log     Used to tell the user what happened
 43  
      * @param issueManagementUrl The URL to the issue management system
 44  
      * @param client  The client used to connect to JIRA
 45  
      * @return The JIRA id for the project, or null if it can't be found
 46  
      */
 47  
     public static String getPidFromJira( Log log, String issueManagementUrl, HttpClient client )
 48  
     {
 49  0
         String jiraId = null;
 50  0
         GetMethod gm = new GetMethod( issueManagementUrl );
 51  
     
 52  
         String projectPage;
 53  
         try
 54  
         {
 55  0
             client.executeMethod( gm );
 56  0
             log.debug( "Successfully reached JIRA." );
 57  0
             projectPage = gm.getResponseBodyAsString();
 58  
         }
 59  0
         catch ( Exception e )
 60  
         {
 61  0
             if ( log.isDebugEnabled() )
 62  
             {
 63  0
                 log.error( "Unable to reach the JIRA project page:", e );
 64  
             }
 65  
             else
 66  
             {
 67  0
                 log.error( "Unable to reach the JIRA project page. Cause is: " + e.getLocalizedMessage() );
 68  
             }
 69  0
             return null;
 70  0
         }
 71  
 
 72  0
         int pidIndex = projectPage.indexOf( PID );
 73  
 
 74  0
         if ( pidIndex == -1 )
 75  
         {
 76  0
             log.error( "Unable to extract a JIRA pid from the page at the url " + issueManagementUrl );
 77  
         }
 78  
         else
 79  
         {
 80  0
             NumberFormat nf = NumberFormat.getInstance();
 81  0
             Number pidNumber = nf.parse( projectPage, new ParsePosition( pidIndex + PID.length() ) );
 82  0
             jiraId = Integer.toString( pidNumber.intValue() );
 83  0
             log.debug( "Found the pid " + jiraId + " at " + issueManagementUrl );
 84  
         }
 85  0
         return jiraId;
 86  
     }
 87  
 }