From a8d71f4ad92eb3d19abf3d678d1a93ab731b6b6a Mon Sep 17 00:00:00 2001 From: fgiust Date: Sun, 13 Nov 2005 23:49:11 +0000 Subject: [PATCH] MPJIRA-4 must contain an "id" attribute Fixed by downloading the project page and extracting a project id from it git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@344007 13f79535-47bb-0310-9956-ffa450edef68 --- jira/project.xml | 2 +- .../org/apache/maven/jira/JiraDownloader.java | 48 +++++++++++++++---- jira/xdocs/changes.xml | 2 + 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/jira/project.xml b/jira/project.xml index 5d8b5959..a109a19d 100644 --- a/jira/project.xml +++ b/jira/project.xml @@ -27,7 +27,7 @@ This plugin downloads issues from Jira and creates a report. Download issues from Jira http://maven.apache.org/maven-1.x/reference/plugins/jira/ - http://jira.codehaus.org/secure/IssueNavigator.jspa?id=10450 + http://jira.codehaus.org/browse/MPJIRA /www/maven.apache.org/maven-1.x/reference/plugins/jira/ scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/jira/ diff --git a/jira/src/main/org/apache/maven/jira/JiraDownloader.java b/jira/src/main/org/apache/maven/jira/JiraDownloader.java index becf1560..f8a5820e 100644 --- a/jira/src/main/org/apache/maven/jira/JiraDownloader.java +++ b/jira/src/main/org/apache/maven/jira/JiraDownloader.java @@ -21,6 +21,8 @@ import java.io.File; 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; @@ -186,12 +188,13 @@ public final class JiraDownloader { public void doExecute() throws Exception { if (project == null) { throw new Exception("No project set."); - } else { - if (project.getIssueTrackingUrl() == null) { - throw new Exception("No issue tracking url set."); - } } + if (project.getIssueTrackingUrl() == null) { + throw new Exception("No issue tracking url set."); + } + + try { HttpClient cl = new HttpClient(); HttpState state = new HttpState(); @@ -205,19 +208,48 @@ public final class JiraDownloader { // chop off the parameter part int pos = url.indexOf("?"); // and get the id while we're at it - String id = ""; + String id = null; if (pos >= 0) { // url id = url.substring(url.lastIndexOf("=") + 1); - } - // TODO: fail the build in the else block, issueTrackingUrl has to include id + } String jiraUrl = url.substring(0, url.lastIndexOf("/")); - if (jiraUrl.endsWith("secure")) { + if (jiraUrl.endsWith("secure") || jiraUrl.endsWith("browse")) { jiraUrl = jiraUrl.substring(0, jiraUrl.lastIndexOf("/")); } log.info("Jira lives at: " + jiraUrl); doAuthentication(cl, jiraUrl); + + if (id == null) { + GetMethod gm = new GetMethod(url); + log.info("Jira URL " + url + " doesn't include a pid, trying to get it"); + try { + cl.executeMethod(gm); + log.info("Succesfully 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="); // @todo, a safer way to get the PID + + if (pidIndex == -1) { + // fail + log.error("Unable to get JIRA pid using url " + project.getIssueTrackingUrl()); + return; + } + + NumberFormat nf = NumberFormat.getInstance(); + Number pidNumber = nf.parse(projectPage, new ParsePosition(pidIndex + 4)); + id = Integer.toString(pidNumber.intValue()); + } + // create the URL for getting the proper iussues from JIRA String fullURL = jiraUrl + "/secure/IssueNavigator.jspa?view=rss&pid=" + id; diff --git a/jira/xdocs/changes.xml b/jira/xdocs/changes.xml index eb492dda..f4e93b94 100644 --- a/jira/xdocs/changes.xml +++ b/jira/xdocs/changes.xml @@ -25,6 +25,8 @@ + Make the Jira report work also using a fancy JIRA url like http://jira.codehaus.org/browse/MPJIRA (it doesn't require + the url with a numeric project id anymore) Update dependencies to match ones in maven 1.1 core and to unify them between plugins. The following dependencies are updated :
  • log4j v1.2.8 -> v1.2.12