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;
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;
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()
@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");
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");
}
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);
WsRequest wsRequest = capture.getValue();
assertThat(wsRequest.getParams()).containsOnly(
entry("organization", "MyOrg"),
- entry("projectKey", "struts"));
+ entry("projectKey", "org.sonarsource.sonarqube:sonarqube"));
}
@Test
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());
}
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);
}
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");
}
/**