Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-05-23 20:06:18 +0000
committerThomas Wolf2016-05-23 20:06:18 +0000
commit8a901ff4d012f4e9c8e5395c6c66d061e6a93cdc (patch)
tree6465f21c11cd1fa2ffcf85bf85a56179ed10198c
parent118f42f3321c2aa9e98c1e5d388d43950865b877 (diff)
downloadegit-8a901ff4d012f4e9c8e5395c6c66d061e6a93cdc.tar.gz
egit-8a901ff4d012f4e9c8e5395c6c66d061e6a93cdc.tar.xz
egit-8a901ff4d012f4e9c8e5395c6c66d061e6a93cdc.zip
Catch IOException in ConfigureGerritAfterCloneTask
This task must not make the git clone be reported as failed -- the repository was already successfully cloned. Catch the exception and return false, which is the safe thing to do: in the worst case, the user may have to do the Gerrit config setup him- or herself via the ConfigureGerritWizard. Also clean up closing streams and disconnecting. Bug: 494342 Change-Id: Ie10cb12da8e8d732c956e7352c15702898e23710 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java79
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)) {

Back to the top