]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SONARPLUGINS-3061 Support trailing slash in sonar.host.url
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 12 Jul 2013 14:59:27 +0000 (16:59 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 12 Jul 2013 14:59:27 +0000 (16:59 +0200)
sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerConnection.java
sonar-runner-impl/src/test/java/org/sonar/runner/impl/MockHttpServer.java
sonar-runner-impl/src/test/java/org/sonar/runner/impl/ServerConnectionTest.java

index 968e46c2e3d00bb26455e4e63fb3e67e3b2d2764..116ba4fa545926278b872a0bf21f59b5e53e508d 100644 (file)
@@ -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);
index 38c1df503e58b681bc14f54664cc50ee0e5a67e0..77982f3ae7a1c675d5b0a3cd344181e81d7291b3 100644 (file)
@@ -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()));
index fe53622803ada52c4742b28ddd6d339bc98df164..bb671bfb131762ca17703d9e6bbd83a7ce4f2d5d 100644 (file)
@@ -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();