aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-03-11 14:26:57 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-03-15 11:51:50 +0100
commit55039a7a500530ae049b4b4c991bafa75faf1ac7 (patch)
tree9aad5499d89de0ebf05ae79e253c6e8685bb3bd6 /sonar-batch/src
parentbc1b7ed1c7a6db15710af9d68096d7e5d054c9f8 (diff)
downloadsonarqube-55039a7a500530ae049b4b4c991bafa75faf1ac7.tar.gz
sonarqube-55039a7a500530ae049b4b4c991bafa75faf1ac7.zip
SONAR-7235 Improve error message when server public URL is not a valid URL
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java15
2 files changed, 22 insertions, 1 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 5ab75c42f2a..47e92a283d6 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
@@ -38,6 +38,7 @@ 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.utils.MessageException;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.ZipUtils;
import org.sonar.api.utils.log.Logger;
@@ -176,7 +177,12 @@ public class ReportPublisher implements Startable {
metadata.put("projectKey", effectiveKey);
metadata.put("serverUrl", publicUrl());
- URL dashboardUrl = HttpUrl.parse(publicUrl()).newBuilder()
+ HttpUrl publicUrl = HttpUrl.parse(publicUrl());
+ if (publicUrl == null) {
+ throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl());
+ }
+
+ URL dashboardUrl = publicUrl.newBuilder()
.addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey)
.build()
.url();
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 9b3ce46fed3..15685428522 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
@@ -26,12 +26,14 @@ import java.nio.file.Path;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
@@ -52,6 +54,9 @@ public class ReportPublisherTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class);
Settings settings = new Settings(new PropertyDefinitions(CorePropertyDefinitions.all()));
@@ -108,6 +113,16 @@ public class ReportPublisherTest {
"ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"
);
}
+
+ @Test
+ 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");
+ }
@Test
public void log_but_not_dump_information_when_report_is_not_uploaded() {