]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9396 remove usage of dashboard/index<project_key> in scanner report
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Tue, 29 May 2018 10:47:50 +0000 (12:47 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 6 Jun 2018 18:20:51 +0000 (20:20 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java
tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java

index 97b01015e2c53dbebb724bef3093555993a1cd91..d9f36877aacbfff070a5c685a5c05bc4e35b5cd0 100644 (file)
@@ -24,6 +24,7 @@ import com.google.common.base.Throwables;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
@@ -54,6 +55,7 @@ import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsResponse;
 
+import static java.net.URLEncoder.encode;
 import static org.sonar.core.config.ScannerProperties.BRANCH_NAME;
 import static org.sonar.core.config.ScannerProperties.ORGANIZATION;
 import static org.sonar.core.util.FileUtils.deleteQuietly;
@@ -222,10 +224,16 @@ public class ReportPublisher implements Startable {
       metadata.put("serverVersion", server.getVersion());
       settings.get(BRANCH_NAME).ifPresent(branch -> metadata.put("branch", branch));
 
-      URL dashboardUrl = httpUrl.newBuilder()
-        .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey)
-        .build()
-        .url();
+      URL dashboardUrl;
+      try {
+        dashboardUrl = httpUrl.newBuilder()
+          .addPathSegment("dashboard")
+          .addEncodedQueryParameter("id", encode(effectiveKey, "UTF-8"))
+          .build()
+          .url();
+      } catch (UnsupportedEncodingException e) {
+        throw new IllegalStateException("Unable to urlencode " + effectiveKey, e);
+      }
       metadata.put("dashboardUrl", dashboardUrl.toExternalForm());
 
       URL taskUrl = HttpUrl.parse(publicUrl).newBuilder()
index b25f773f536ca21e9eecba58351c5f6ec5a86a46..ccc9d46b1cef09a04c9f9a20ba2b4226090f1333 100644 (file)
@@ -85,7 +85,7 @@ public class ReportPublisherTest {
   @Before
   public void setUp() throws IOException {
     wsClient = mock(ScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS);
-    root = new DefaultInputModule(ProjectDefinition.create().setKey("struts").setBaseDir(temp.newFolder()).setWorkDir(temp.getRoot()));
+    root = new DefaultInputModule(ProjectDefinition.create().setKey("org.sonarsource.sonarqube:sonarqube").setBaseDir(temp.newFolder()).setWorkDir(temp.getRoot()));
     when(moduleHierarchy.root()).thenReturn(root);
     when(server.getPublicRootUrl()).thenReturn("https://localhost");
     when(server.getVersion()).thenReturn("6.4");
@@ -100,17 +100,17 @@ public class ReportPublisherTest {
     underTest.logSuccess("TASK-123");
 
     assertThat(logTester.logs(LoggerLevel.INFO))
-      .contains("ANALYSIS SUCCESSFUL, you can browse https://localhost/dashboard/index/struts")
+      .contains("ANALYSIS SUCCESSFUL, you can browse https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube")
       .contains("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report")
       .contains("More about the report processing at https://localhost/api/ce/task?id=TASK-123");
 
     File detailsFile = new File(temp.getRoot(), "report-task.txt");
     assertThat(readFileToString(detailsFile)).isEqualTo(
       "organization=MyOrg\n" +
-        "projectKey=struts\n" +
+        "projectKey=org.sonarsource.sonarqube:sonarqube\n" +
         "serverUrl=https://localhost\n" +
         "serverVersion=6.4\n" +
-        "dashboardUrl=https://localhost/dashboard/index/struts\n" +
+        "dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" +
         "ceTaskId=TASK-123\n" +
         "ceTaskUrl=https://localhost/api/ce/task?id=TASK-123\n");
   }
@@ -138,21 +138,21 @@ public class ReportPublisherTest {
     underTest.logSuccess("TASK-123");
 
     assertThat(logTester.logs(LoggerLevel.INFO))
-      .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard/index/struts")
+      .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube")
       .contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123");
 
     File detailsFile = new File(temp.getRoot(), "report-task.txt");
     assertThat(readFileToString(detailsFile)).isEqualTo(
-      "projectKey=struts\n" +
+      "projectKey=org.sonarsource.sonarqube:sonarqube\n" +
         "serverUrl=https://publicserver/sonarqube\n" +
         "serverVersion=6.4\n" +
-        "dashboardUrl=https://publicserver/sonarqube/dashboard/index/struts\n" +
+        "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" +
         "ceTaskId=TASK-123\n" +
         "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n");
   }
 
   @Test
-  public void fail_if_public_url_malformed() throws IOException {
+  public void fail_if_public_url_malformed() {
     when(server.getPublicRootUrl()).thenReturn("invalid");
     ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
@@ -229,7 +229,7 @@ public class ReportPublisherTest {
     WsRequest wsRequest = capture.getValue();
     assertThat(wsRequest.getParams()).containsOnly(
       entry("organization", "MyOrg"),
-      entry("projectKey", "struts"));
+      entry("projectKey", "org.sonarsource.sonarqube:sonarqube"));
   }
 
   @Test
@@ -263,7 +263,7 @@ public class ReportPublisherTest {
     WsRequest wsRequest = capture.getValue();
     assertThat(wsRequest.getParameters().getKeys()).hasSize(3);
     assertThat(wsRequest.getParameters().getValues("organization")).containsExactly(orgName);
-    assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("struts");
+    assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("org.sonarsource.sonarqube:sonarqube");
     assertThat(wsRequest.getParameters().getValues("characteristic"))
       .containsExactlyInAnyOrder("branch=" + branchName, "branchType=" + SHORT.name());
   }
@@ -301,7 +301,7 @@ public class ReportPublisherTest {
     WsRequest wsRequest = capture.getValue();
     assertThat(wsRequest.getParameters().getKeys()).hasSize(3);
     assertThat(wsRequest.getParameters().getValues("organization")).containsExactly(orgName);
-    assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("struts");
+    assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("org.sonarsource.sonarqube:sonarqube");
     assertThat(wsRequest.getParameters().getValues("characteristic"))
       .containsExactlyInAnyOrder("pullRequest=" + pullRequestId);
   }
index 0fa0f7093e76af070f707873806cbeca66cb4db6..1e9c7eeab54dc2d09c490948f879fd7c7bdef889 100644 (file)
@@ -283,16 +283,16 @@ public class ScannerTest {
 
     BuildResult result = scan("shared/xoo-multi-modules-sample");
 
-    assertThat(result.getLogs()).contains("/dashboard/index/com.sonarsource.it.samples:multi-modules-sample");
+    assertThat(result.getLogs()).contains("/dashboard?id=com.sonarsource.it.samples%3Amulti-modules-sample");
 
     result = scan("shared/xoo-multi-modules-sample",
       "sonar.branch", "mybranch");
 
-    assertThat(result.getLogs()).contains("/dashboard/index/com.sonarsource.it.samples:multi-modules-sample:mybranch");
+    assertThat(result.getLogs()).contains("/dashboard?id=com.sonarsource.it.samples%3Amulti-modules-sample%3Amybranch");
 
     tester.settings().setGlobalSettings("sonar.core.serverBaseURL", "http://foo:123/sonar");
     result = scan("shared/xoo-multi-modules-sample");
-    assertThat(result.getLogs()).contains("http://foo:123/sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample");
+    assertThat(result.getLogs()).contains("http://foo:123/sonar/dashboard?id=com.sonarsource.it.samples%3Amulti-modules-sample");
   }
 
   /**