]> source.dussan.org Git - sonarqube.git/commitdiff
Fix compatibility of rails upgrade with sonar-runner
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Sep 2012 12:44:26 +0000 (14:44 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Sep 2012 12:44:26 +0000 (14:44 +0200)
sonar-server/src/dev/web.xml
sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java
sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java

index b537e1dd48ae987414e700102b0053956121b70e..9fc07c9f20a6acaa33c5707cf0d572cb6ea38b9b 100644 (file)
     <param-name>rails.env</param-name>
     <param-value>development</param-value>
   </context-param>
-
-
   <context-param>
     <param-name>jruby.min.runtimes</param-name>
     <param-value>1</param-value>
   </context-param>
-
   <context-param>
     <param-name>jruby.max.runtimes</param-name>
     <param-value>3</param-value>
   </context-param>
+  <context-param>
+    <param-name>jruby.compat.version</param-name>
+    <param-value>1.8</param-value>
+  </context-param>
+  <context-param>
+    <param-name>jruby.rack.logging</param-name>
+    <param-value>slf4j</param-value>
+  </context-param>
 
+  <filter>
+    <filter-name>ServletFilters</filter-name>
+    <filter-class>org.sonar.server.platform.ServletFilters</filter-class>
+  </filter>
   <filter>
     <filter-name>DatabaseSessionFilter</filter-name>
     <filter-class>org.sonar.server.ui.DatabaseSessionFilter</filter-class>
     <filter-name>RackFilter</filter-name>
     <filter-class>org.jruby.rack.RackFilter</filter-class>
   </filter>
-  <filter>
-    <filter-name>ServletFilters</filter-name>
-    <filter-class>org.sonar.server.platform.ServletFilters</filter-class>
-  </filter>
 
   <filter-mapping>
     <filter-name>DatabaseSessionFilter</filter-name>
index 1751c24079252cff1232f723aa89536cadea4f72..1106e80859c46ccb4696e184073170d61d723948 100644 (file)
@@ -48,8 +48,8 @@ public class BatchResourcesServlet extends HttpServlet {
 
   @Override
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-    String resource = getResource(request);
-    if (StringUtils.isEmpty(resource)) {
+    String filename = filename(request);
+    if (StringUtils.isBlank(filename)) {
       PrintWriter writer = null;
       try {
         response.setContentType("text/plain");
@@ -62,19 +62,19 @@ public class BatchResourcesServlet extends HttpServlet {
         IOUtils.closeQuietly(writer);
       }
     } else {
-      response.setContentType("application/java-archive");
       InputStream in = null;
       OutputStream out = null;
       try {
-        in = getServletContext().getResourceAsStream("/WEB-INF/lib/" + resource);
+        in = getServletContext().getResourceAsStream("/WEB-INF/lib/" + filename);
         if (in == null) {
           // TODO
         } else {
+          response.setContentType("application/java-archive");
           out = response.getOutputStream();
           IOUtils.copy(in, out);
         }
       } catch (Exception e) {
-        LOG.error("Unable to load batch resource '" + resource + "'", e);
+        LOG.error("Unable to load batch resource '" + filename + "'", e);
         response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       } finally {
         IOUtils.closeQuietly(in);
@@ -115,8 +115,12 @@ public class BatchResourcesServlet extends HttpServlet {
   /**
    * @return part of request URL after servlet path
    */
-  String getResource(HttpServletRequest request) {
-    return StringUtils.substringAfter(request.getRequestURI(), request.getContextPath() + request.getServletPath() + "/");
+  String filename(HttpServletRequest request) {
+    String filename = null;
+    if (StringUtils.endsWithIgnoreCase(request.getRequestURI(), "jar")) {
+      filename = StringUtils.substringAfterLast(request.getRequestURI(), "/");
+    }
+    return filename;
   }
 
 }
index ea633db07f8ec41f6016b665c28e7e45a016ee3c..bdc12799cccdce06caad7328e7a7a938cef845ea 100644 (file)
@@ -23,18 +23,13 @@ import com.google.common.collect.Sets;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Set;
-
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import java.util.Set;
 
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 public class BatchResourcesServletTest {
   private BatchResourcesServlet servlet;
@@ -47,18 +42,24 @@ public class BatchResourcesServletTest {
   }
 
   @Test
-  public void shouldDetermineResource() {
+  public void test_filename() {
     when(request.getContextPath()).thenReturn("sonar");
     when(request.getServletPath()).thenReturn("/batch");
 
     when(request.getRequestURI()).thenReturn("/sonar/batch/sonar-core-2.6.jar");
-    assertThat(servlet.getResource(request), is("sonar-core-2.6.jar"));
+    assertThat(servlet.filename(request)).isEqualTo("sonar-core-2.6.jar");
 
     when(request.getRequestURI()).thenReturn("/sonar/batch/");
-    assertThat(servlet.getResource(request), is(""));
+    assertThat(servlet.filename(request)).isNull();
 
     when(request.getRequestURI()).thenReturn("/sonar/batch");
-    assertThat(servlet.getResource(request), is(""));
+    assertThat(servlet.filename(request)).isNull();
+
+    when(request.getRequestURI()).thenReturn("/sonar/batch.html");
+    assertThat(servlet.filename(request)).isNull();
+
+    when(request.getRequestURI()).thenReturn("/sonar/batch/index.html");
+    assertThat(servlet.filename(request)).isNull();
   }
 
   @Test
@@ -72,21 +73,21 @@ public class BatchResourcesServletTest {
     libs.add("/WEB-INF/lib/directory/");
     when(servletContext.getResourcePaths(anyString())).thenReturn(libs);
 
-    assertThat(servlet.getLibs().size(), is(1));
-    assertThat(servlet.getLibs().get(0), is("sonar-core-2.6.jar"));
+    assertThat(servlet.getLibs()).hasSize(1);
+    assertThat(servlet.getLibs().get(0)).isEqualTo("sonar-core-2.6.jar");
   }
 
   @Test
   public void shouldIgnore() {
-    assertThat(BatchResourcesServlet.isIgnored("sonar-batch-2.6-SNAPSHOT.jar"), is(false));
-    assertThat(BatchResourcesServlet.isIgnored("h2-1.3.166.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("mysql-connector-java-5.1.13.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("postgresql-9.0-801.jdbc3.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("jtds-1.2.4.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("jfreechart-1.0.9.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("eastwood-1.1.0.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("jetty-util-6.1.24.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("jruby-complete-1.5.6.jar"), is(true));
-    assertThat(BatchResourcesServlet.isIgnored("jruby-rack-1.0.5.jar"), is(true));
+    assertThat(BatchResourcesServlet.isIgnored("sonar-batch-2.6-SNAPSHOT.jar")).isFalse();
+    assertThat(BatchResourcesServlet.isIgnored("h2-1.3.166.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("mysql-connector-java-5.1.13.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("postgresql-9.0-801.jdbc3.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("jtds-1.2.4.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("jfreechart-1.0.9.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("eastwood-1.1.0.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("jetty-util-6.1.24.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("jruby-complete-1.5.6.jar")).isTrue();
+    assertThat(BatchResourcesServlet.isIgnored("jruby-rack-1.0.5.jar")).isTrue();
   }
 }