diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-06-09 11:45:01 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-06-13 10:39:20 +0200 |
commit | 466b48d80a5ae5f0b5fa11f17398b36c932135e8 (patch) | |
tree | 16b596f4e58c243630cbe92f5a44a5e5a488dbf8 /sonar-scanner-engine/src/main | |
parent | 475108c6cc00851cc76e57e01492a6df30c12a4b (diff) | |
download | sonarqube-466b48d80a5ae5f0b5fa11f17398b36c932135e8.tar.gz sonarqube-466b48d80a5ae5f0b5fa11f17398b36c932135e8.zip |
SONAR-7748 Implement API Server.getPublicRootUrl() on scanner side
Diffstat (limited to 'sonar-scanner-engine/src/main')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/batch/platform/DefaultServer.java | 19 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java | 24 |
2 files changed, 19 insertions, 24 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/platform/DefaultServer.java index b747438a9f5..60ad445afa7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/platform/DefaultServer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/platform/DefaultServer.java @@ -30,17 +30,19 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.BatchSide; import org.sonar.api.config.Settings; import org.sonar.api.platform.Server; -import org.sonar.batch.bootstrap.GlobalProperties; +import org.sonar.batch.bootstrap.BatchWsClient; + +import static org.apache.commons.lang.StringUtils.trimToEmpty; @BatchSide public class DefaultServer extends Server { private Settings settings; - private GlobalProperties props; + private BatchWsClient client; - public DefaultServer(Settings settings, GlobalProperties props) { + public DefaultServer(Settings settings, BatchWsClient client) { this.settings = settings; - this.props = props; + this.client = client; } @Override @@ -85,7 +87,12 @@ public class DefaultServer extends Server { @Override public String getPublicRootUrl() { - return null; + String baseUrl = trimToEmpty(settings.getString(CoreProperties.SERVER_BASE_URL)); + if (baseUrl.isEmpty()) { + // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side + baseUrl = client.baseUrl(); + } + return StringUtils.removeEnd(baseUrl, "/"); } @Override @@ -100,7 +107,7 @@ public class DefaultServer extends Server { @Override public String getURL() { - return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/"); + return StringUtils.removeEnd(client.baseUrl(), "/"); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java index 2539aa065ee..b47217b8859 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java @@ -34,10 +34,10 @@ import java.util.Map; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.picocontainer.Startable; -import org.sonar.api.CoreProperties; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.config.Settings; +import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; import org.sonar.api.utils.ZipUtils; @@ -52,7 +52,6 @@ import org.sonarqube.ws.WsCe; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsResponse; -import static org.apache.commons.lang.StringUtils.trimToEmpty; import static org.sonar.core.util.FileUtils.deleteQuietly; @BatchSide @@ -71,14 +70,16 @@ public class ReportPublisher implements Startable { private final DefaultAnalysisMode analysisMode; private final TempFolder temp; private final ReportPublisherStep[] publishers; + private final Server server; private File reportDir; private ScannerReportWriter writer; - public ReportPublisher(Settings settings, BatchWsClient wsClient, AnalysisContextReportPublisher contextPublisher, + public ReportPublisher(Settings settings, BatchWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) { this.settings = settings; this.wsClient = wsClient; + this.server = server; this.contextPublisher = contextPublisher; this.projectReactor = projectReactor; this.analysisMode = analysisMode; @@ -93,7 +94,7 @@ public class ReportPublisher implements Startable { contextPublisher.init(writer); if (!analysisMode.isIssues() && !analysisMode.isMediumTest()) { - String publicUrl = publicUrl(); + String publicUrl = server.getPublicRootUrl(); if (HttpUrl.parse(publicUrl) == null) { throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl); } @@ -185,7 +186,7 @@ public class ReportPublisher implements Startable { if (taskId == null) { LOG.info("ANALYSIS SUCCESSFUL"); } else { - String publicUrl = publicUrl(); + String publicUrl = server.getPublicRootUrl(); HttpUrl httpUrl = HttpUrl.parse(publicUrl); Map<String, String> metadata = new LinkedHashMap<>(); @@ -230,17 +231,4 @@ 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 baseUrl = trimToEmpty(settings.getString(CoreProperties.SERVER_BASE_URL)); - if (baseUrl.isEmpty()) { - // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side - baseUrl = wsClient.baseUrl(); - } - return baseUrl.replaceAll("(/)+$", ""); - } } |