diff options
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java | 21 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java | 4 |
2 files changed, 15 insertions, 10 deletions
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 47e92a283d6..c62ccd63c56 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 @@ -90,6 +90,13 @@ public class ReportPublisher implements Startable { reportDir = new File(projectReactor.getRoot().getWorkDir(), "batch-report"); writer = new BatchReportWriter(reportDir); contextPublisher.init(writer); + + if (!analysisMode.isIssues() && !analysisMode.isMediumTest()) { + String publicUrl = publicUrl(); + if (HttpUrl.parse(publicUrl) == null) { + throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl); + } + } } @Override @@ -172,23 +179,21 @@ public class ReportPublisher implements Startable { if (taskId == null) { LOG.info("ANALYSIS SUCCESSFUL"); } else { + String publicUrl = publicUrl(); + HttpUrl httpUrl = HttpUrl.parse(publicUrl); + Map<String, String> metadata = new LinkedHashMap<>(); String effectiveKey = projectReactor.getRoot().getKeyWithBranch(); metadata.put("projectKey", effectiveKey); - metadata.put("serverUrl", publicUrl()); - - HttpUrl publicUrl = HttpUrl.parse(publicUrl()); - if (publicUrl == null) { - throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl()); - } + metadata.put("serverUrl", publicUrl); - URL dashboardUrl = publicUrl.newBuilder() + URL dashboardUrl = httpUrl.newBuilder() .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey) .build() .url(); metadata.put("dashboardUrl", dashboardUrl.toExternalForm()); - URL taskUrl = HttpUrl.parse(publicUrl()).newBuilder() + URL taskUrl = HttpUrl.parse(publicUrl).newBuilder() .addPathSegment("api").addPathSegment("ce").addPathSegment("task") .addQueryParameter("id", taskId) .build() diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java index 15685428522..bb54bfb9113 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java @@ -118,10 +118,10 @@ public class ReportPublisherTest { public void fail_if_public_url_malformed() throws IOException { settings.setProperty(CoreProperties.SERVER_BASE_URL, "invalid"); ReportPublisher underTest = new ReportPublisher(settings, wsClient, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); - + exception.expect(MessageException.class); exception.expectMessage("Failed to parse public URL set in SonarQube server: invalid"); - underTest.logSuccess("TASK-123"); + underTest.start(); } @Test |