diff options
Diffstat (limited to 'org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java')
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java index 579e6ff796..62eb62dc98 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java @@ -162,8 +162,8 @@ public class ConfigureGerritAfterCloneTask implements PostCloneTask { if (HTTPS.equals(s) && (u.getPort() == 443 || u.getPort() == -1) && path != null && path.startsWith(GERRIT_CONTEXT_ROOT)) { return true; - } else - if (SSH.equals(s) && u.getPort() == GERRIT_SSHD_DEFAULT_PORT) { + } else if (SSH.equals(s) + && u.getPort() == GERRIT_SSHD_DEFAULT_PORT) { return true; } } @@ -172,52 +172,45 @@ public class ConfigureGerritAfterCloneTask implements PostCloneTask { String baseURL = u.setPath("/").toString(); //$NON-NLS-1$ baseURL = baseURL.substring(0, baseURL.length() - 1); String tmpPath = ""; //$NON-NLS-1$ - HttpURLConnection httpConnection = null; - try { - int slash = 1; - while (true) { - InputStream in = null; - try { - httpConnection = (HttpURLConnection) new URL(baseURL - + tmpPath + GERRIT_CONFIG_SERVER_VERSION_API) - .openConnection(); - NetUtil.setSslVerification(repo, httpConnection); - httpConnection.setRequestMethod("GET"); //$NON-NLS-1$ - httpConnection.setReadTimeout(1000 * timeout); - int responseCode = httpConnection.getResponseCode(); - switch (responseCode) { - case HttpURLConnection.HTTP_OK: - in = httpConnection.getInputStream(); + int slash = 1; + while (true) { + HttpURLConnection httpConnection = null; + try { + httpConnection = (HttpURLConnection) new URL(baseURL + + tmpPath + GERRIT_CONFIG_SERVER_VERSION_API) + .openConnection(); + NetUtil.setSslVerification(repo, httpConnection); + httpConnection.setRequestMethod("GET"); //$NON-NLS-1$ + httpConnection.setReadTimeout(1000 * timeout); + int responseCode = httpConnection.getResponseCode(); + switch (responseCode) { + case HttpURLConnection.HTTP_OK: + try (InputStream in = httpConnection.getInputStream()) { String response = readFully(in, "UTF-8"); //$NON-NLS-1$ - if (response.startsWith(GERRIT_XSSI_MAGIC_STRING)) { - return true; - } else { - return false; - } - case HttpURLConnection.HTTP_NOT_FOUND: - if (slash > path.length()) { - return false; - } - slash = path.indexOf('/', slash); - if (slash == -1) { - // try the entire path - slash = path.length(); - } - tmpPath = path.substring(0, slash); - slash++; - break; - default: + return response + .startsWith(GERRIT_XSSI_MAGIC_STRING); + } + case HttpURLConnection.HTTP_NOT_FOUND: + if (slash > path.length()) { return false; } - } finally { - if (in != null) { - in.close(); + slash = path.indexOf('/', slash); + if (slash == -1) { + // try the entire path + slash = path.length(); } + tmpPath = path.substring(0, slash); + slash++; + break; + default: + return false; + } + } catch (IOException e) { + return false; + } finally { + if (httpConnection != null) { + httpConnection.disconnect(); } - } - } finally { - if (httpConnection != null) { - httpConnection.disconnect(); } } } else if (SSH.equals(s)) { |