From: Duarte Meneses Date: Thu, 13 Aug 2015 15:19:32 +0000 (+0200) Subject: Improve quality X-Git-Tag: 2.5-rc1~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2a54dfc8fa78ff8f2eaf8072d1b7447b5720f297;p=sonar-scanner-cli.git Improve quality --- diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java b/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java index eb1002f..5b306bd 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java @@ -143,11 +143,8 @@ class ServerConnection { try { return downloadString(fullUrl, isCacheEnable); } catch (HttpRequest.HttpRequestException e) { - if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException || - e.getCause() instanceof java.net.SocketTimeoutException) { - if (isCacheEnable) { - return fallbackToCache(fullUrl, e); - } + if (isCausedByConnection(e) && isCacheEnable) { + return fallbackToCache(fullUrl, e); } logger.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl)); @@ -155,6 +152,11 @@ class ServerConnection { } } + private boolean isCausedByConnection(Exception e) { + return e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException || + e.getCause() instanceof java.net.SocketTimeoutException; + } + private String fallbackToCache(String fullUrl, HttpRequest.HttpRequestException originalException) { logger.info(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED + ", trying cache", serverUrl));