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;
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();
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;
@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()));
"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() {