]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7235 Improve error message when server public URL is not a valid URL
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 16 Mar 2016 08:33:56 +0000 (09:33 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 16 Mar 2016 08:54:13 +0000 (09:54 +0100)
sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java

index 47e92a283d6b23ea19463a7556b50bb7e54fe18e..c62ccd63c56d3cd35c9ae764d8aa6bfba5d64d47 100644 (file)
@@ -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()
index 156854285229607963d974993b84e9ab2e739258..bb54bfb9113c2b2c8d36253ab17c108d7c4389b1 100644 (file)
@@ -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