diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-02 13:42:47 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-02 14:16:49 +0100 |
commit | 18a077aac51e118a93ccc796dd96264ee19e862e (patch) | |
tree | 3a6b92f3065dec8f940ea4dc0def648ec4a56bc3 /sonar-batch/src/main/java/org | |
parent | 92b68fdb6bca9347e153424fb4f79ceae400fc3d (diff) | |
download | sonarqube-18a077aac51e118a93ccc796dd96264ee19e862e.tar.gz sonarqube-18a077aac51e118a93ccc796dd96264ee19e862e.zip |
Fix logging of public url
Diffstat (limited to 'sonar-batch/src/main/java/org')
3 files changed, 17 insertions, 21 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java index 16bac82b84f..cea28187c9a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java @@ -28,8 +28,6 @@ import com.google.gson.JsonParser; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.Logger; @@ -49,16 +47,10 @@ public class BatchWsClient { private final WsClient target; private final boolean hasCredentials; - private final String publicBaseUrl; - public BatchWsClient(WsClient target, boolean hasCredentials, @Nullable String publicBaseUrl) { + public BatchWsClient(WsClient target, boolean hasCredentials) { this.target = target; this.hasCredentials = hasCredentials; - if (StringUtils.isBlank(publicBaseUrl)) { - this.publicBaseUrl = target.wsConnector().baseUrl(); - } else { - this.publicBaseUrl = publicBaseUrl.replaceAll("(/)+$", "") + "/"; - } } /** @@ -80,15 +72,6 @@ public class BatchWsClient { return target.wsConnector().baseUrl(); } - /** - * The public URL is optionally configured on server. If not, then the regular {@link #baseUrl()} is returned. - * URL has a trailing slash. - * See https://jira.sonarsource.com/browse/SONAR-4239 - */ - public String publicBaseUrl() { - return publicBaseUrl; - } - @VisibleForTesting WsConnector wsConnector() { return target.wsConnector(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java index a8ac402da35..dd922755930 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java @@ -55,7 +55,7 @@ public class BatchWsClientProvider extends ProviderAdapter { .url(url) .credentials(login, settings.property(CoreProperties.PASSWORD)); - wsClient = new BatchWsClient(new HttpWsClient(builder.build()), login != null, settings.property(CoreProperties.SERVER_BASE_URL)); + wsClient = new BatchWsClient(new HttpWsClient(builder.build()), login != null); } return wsClient; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java index 524a9a034f5..6f96639d2bd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java @@ -33,6 +33,7 @@ import java.util.LinkedHashMap; import java.util.Map; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.picocontainer.Startable; import org.sonar.api.CoreProperties; import org.sonar.api.batch.BatchSide; @@ -176,13 +177,13 @@ public class ReportPublisher implements Startable { String effectiveKey = projectReactor.getRoot().getKeyWithBranch(); metadata.put("projectKey", effectiveKey); - URL dashboardUrl = HttpUrl.parse(wsClient.publicBaseUrl()).newBuilder() + URL dashboardUrl = HttpUrl.parse(publicUrl()).newBuilder() .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey) .build() .url(); metadata.put("dashboardUrl", dashboardUrl.toExternalForm()); - URL taskUrl = HttpUrl.parse(wsClient.publicBaseUrl()).newBuilder() + URL taskUrl = HttpUrl.parse(publicUrl()).newBuilder() .addPathSegment("api").addPathSegment("ce").addPathSegment("task") .addQueryParameter("id", taskId) .build() @@ -213,4 +214,16 @@ public class ReportPublisher implements Startable { throw new IllegalStateException("Unable to dump " + file, e); } } + + /** + * The public URL is optionally configured on server. If not, then the regular URL is returned. + * See https://jira.sonarsource.com/browse/SONAR-4239 + */ + private String publicUrl() { + String publicUrl = settings.getString(CoreProperties.SERVER_BASE_URL); + if (StringUtils.isBlank(publicUrl)) { + return wsClient.baseUrl(); + } + return publicUrl.replaceAll("(/)+$", "") + "/"; + } } |