aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-impl
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-12 16:59:27 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-12 16:59:27 +0200
commitd998842fbd070404ac2dde82e391103256fcc550 (patch)
tree35763f1e4435c2004623899fda4ec9ad9e20d610 /sonar-runner-impl
parent1085fe249e3dcef1a48d15334ed1e1b9097eba8c (diff)
downloadsonar-scanner-cli-d998842fbd070404ac2dde82e391103256fcc550.tar.gz
sonar-scanner-cli-d998842fbd070404ac2dde82e391103256fcc550.zip
SONARPLUGINS-3061 Support trailing slash in sonar.host.url
Diffstat (limited to 'sonar-runner-impl')
-rw-r--r--sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java9
-rw-r--r--sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java5
-rw-r--r--sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java14
3 files changed, 27 insertions, 1 deletions
diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java
index 968e46c..116ba4f 100644
--- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java
+++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java
@@ -41,10 +41,17 @@ class ServerConnection {
private final String userAgent;
private ServerConnection(String serverUrl, String app, String appVersion) {
- this.serverUrl = serverUrl;
+ this.serverUrl = removeEndSlash(serverUrl);
this.userAgent = app + "/" + appVersion;
}
+ private String removeEndSlash(String url) {
+ if (url == null) {
+ return null;
+ }
+ return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
+ }
+
static ServerConnection create(Properties properties) {
String serverUrl = properties.getProperty("sonar.host.url");
String app = properties.getProperty(InternalProperties.RUNNER_APP);
diff --git a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java
index 38c1df5..77982f3 100644
--- a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java
+++ b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java
@@ -22,6 +22,7 @@ package org.sonar.runner.impl;
import org.apache.commons.io.IOUtils;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.HttpException;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
@@ -58,6 +59,10 @@ class MockHttpServer {
Handler handler = new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
+ // SONARPLUGINS-3061
+ if (target.startsWith("//")) {
+ throw new HttpException(404, "Not found");
+ }
Request baseRequest = request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
setResponseBody(getMockResponseData());
setRequestBody(IOUtils.toString(baseRequest.getInputStream()));
diff --git a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java
index fe53622..bb671bf 100644
--- a/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java
+++ b/sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java
@@ -63,6 +63,20 @@ public class ServerConnectionTest {
assertThat(FileUtils.readFileToString(toFile)).isEqualTo("abcde");
}
+ // SONARPLUGINS-3061
+ @Test
+ public void should_support_trailing_slash() throws Exception {
+ httpServer.setMockResponseData("abcde");
+ Properties props = new Properties();
+ props.setProperty("sonar.host.url", httpServer.url() + "/");
+
+ ServerConnection connection = ServerConnection.create(props);
+ File toFile = temp.newFile();
+ connection.download("/batch/index.txt", toFile);
+
+ assertThat(FileUtils.readFileToString(toFile)).isEqualTo("abcde");
+ }
+
@Test
public void should_not_download_file_when_host_is_down() throws Exception {
Properties props = new Properties();