|
18 | 18 | */ |
19 | 19 | package org.apache.maven.plugins.jira; |
20 | 20 |
|
| 21 | +import java.io.IOException; |
21 | 22 | import java.text.NumberFormat; |
22 | 23 | import java.text.ParsePosition; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.Map; |
25 | 26 |
|
26 | | -import org.apache.commons.httpclient.HttpClient; |
27 | | -import org.apache.commons.httpclient.methods.GetMethod; |
| 27 | +import org.apache.http.HttpEntity; |
| 28 | +import org.apache.http.HttpResponse; |
| 29 | +import org.apache.http.client.HttpClient; |
| 30 | +import org.apache.http.client.methods.HttpGet; |
| 31 | +import org.apache.http.util.EntityUtils; |
28 | 32 | import org.apache.maven.plugin.logging.Log; |
29 | 33 |
|
30 | 34 | /** |
@@ -87,21 +91,29 @@ static Map<String, String> getJiraUrlAndProjectId(String issueManagementUrl) { |
87 | 91 | /** |
88 | 92 | * Try to get a JIRA pid from the issue management URL. |
89 | 93 | * |
90 | | - * @param log Used to tell the user what happened |
91 | | - * @param issueManagementUrl The URL to the issue management system |
92 | | - * @param client The client used to connect to JIRA |
93 | | - * @return The JIRA id for the project, or null if it can't be found |
| 94 | + * @param log used to tell the user what happened |
| 95 | + * @param issueManagementUrl the URL to the issue management system |
| 96 | + * @param client the client used to connect to JIRA |
| 97 | + * @return the JIRA id for the project, or null if it can't be found |
94 | 98 | */ |
95 | 99 | public static String getPidFromJira(Log log, String issueManagementUrl, HttpClient client) { |
96 | 100 | String jiraId = null; |
97 | | - GetMethod gm = new GetMethod(issueManagementUrl); |
| 101 | + HttpGet request = new HttpGet(issueManagementUrl); |
98 | 102 |
|
99 | 103 | String projectPage; |
100 | 104 | try { |
101 | | - client.executeMethod(gm); |
| 105 | + HttpResponse response = client.execute(request); |
102 | 106 | log.debug("Successfully reached JIRA."); |
103 | | - projectPage = gm.getResponseBodyAsString(); |
104 | | - } catch (Exception e) { |
| 107 | + HttpEntity entity = response.getEntity(); |
| 108 | + if (entity != null) { |
| 109 | + projectPage = EntityUtils.toString(entity); |
| 110 | + } else { |
| 111 | + if (log.isDebugEnabled()) { |
| 112 | + log.error("Unable to read the JIRA project page"); |
| 113 | + } |
| 114 | + return null; |
| 115 | + } |
| 116 | + } catch (IOException e) { |
105 | 117 | if (log.isDebugEnabled()) { |
106 | 118 | log.error("Unable to reach the JIRA project page:", e); |
107 | 119 | } else { |
@@ -131,44 +143,42 @@ private JiraHelper() { |
131 | 143 | * Parse out the base URL for JIRA and the JIRA project name from the issue management URL. The issue management URL |
132 | 144 | * is assumed to be of the format http(s)://host:port/browse/{projectname} |
133 | 145 | * |
134 | | - * @param issueManagementUrl The URL to the issue management system |
| 146 | + * @param issueManagementUrl the URL to the issue management system |
135 | 147 | * @return A <code>Map</code> containing the URL and project name |
136 | 148 | * @since 2.8 |
137 | 149 | */ |
138 | 150 | public static Map<String, String> getJiraUrlAndProjectName(String issueManagementUrl) { |
139 | 151 | final int indexBrowse = issueManagementUrl.indexOf("/browse/"); |
140 | 152 |
|
141 | | - String jiraUrl; |
142 | | - String project; |
| 153 | + HashMap<String, String> urlMap = new HashMap<>(4); |
143 | 154 |
|
144 | 155 | if (indexBrowse != -1) { |
145 | | - jiraUrl = issueManagementUrl.substring(0, indexBrowse); |
| 156 | + String jiraUrl = issueManagementUrl.substring(0, indexBrowse); |
| 157 | + urlMap.put("url", jiraUrl); |
146 | 158 |
|
147 | 159 | final int indexBrowseEnd = indexBrowse + "/browse/".length(); |
148 | 160 |
|
149 | 161 | final int indexProject = issueManagementUrl.indexOf("/", indexBrowseEnd); |
150 | 162 |
|
151 | 163 | if (indexProject != -1) { |
152 | 164 | // Project name has trailing '/' |
153 | | - project = issueManagementUrl.substring(indexBrowseEnd, indexProject); |
| 165 | + String project = issueManagementUrl.substring(indexBrowseEnd, indexProject); |
| 166 | + urlMap.put("project", project); |
154 | 167 | } else { |
155 | 168 | // Project name without trailing '/' |
156 | | - project = issueManagementUrl.substring(indexBrowseEnd); |
| 169 | + String project = issueManagementUrl.substring(indexBrowseEnd); |
| 170 | + urlMap.put("project", project); |
157 | 171 | } |
158 | 172 | } else { |
159 | 173 | throw new IllegalArgumentException("Invalid browse URL"); |
160 | 174 | } |
161 | 175 |
|
162 | | - HashMap<String, String> urlMap = new HashMap<>(4); |
163 | | - urlMap.put("url", jiraUrl); |
164 | | - urlMap.put("project", project); |
165 | | - |
166 | 176 | return urlMap; |
167 | 177 | } |
168 | 178 |
|
169 | 179 | /** |
170 | | - * @param url URL. |
171 | | - * @return the base URL. |
| 180 | + * @param url URL |
| 181 | + * @return the base URL |
172 | 182 | * @since 2.8 |
173 | 183 | */ |
174 | 184 | public static String getBaseUrl(String url) { |
|
0 commit comments