]> source.dussan.org Git - sonarqube.git/commitdiff
Disable downloading for certain files from BatchResourcesServlet
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Feb 2011 01:33:28 +0000 (04:33 +0300)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Feb 2011 11:59:49 +0000 (14:59 +0300)
sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java
sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java

index e8195a55ca41f9d3f55df90205385c213061891c..b47258bb802a59f59504b1b28c41f243f197029b 100644 (file)
@@ -87,12 +87,29 @@ public class BatchResourcesServlet extends HttpServlet {
     for (Object obj : paths) {
       String path = (String) obj;
       if (StringUtils.endsWith(path, ".jar")) {
-        libs.add(StringUtils.removeStart(path, "/WEB-INF/lib/"));
+        String filename = StringUtils.removeStart(path, "/WEB-INF/lib/");
+        if (!isIgnored(filename)) {
+          libs.add(filename);
+        }
       }
     }
     return libs;
   }
 
+  private static String[] IGNORE = { "derby", "jtds", "mysql", "postgresql", "jruby", "jfreechart", "eastwood", "jetty" };
+
+  /**
+   * Dirty hack to disable downloading for certain files.
+   */
+  static boolean isIgnored(String filename) {
+    for (String prefix : IGNORE) {
+      if (StringUtils.startsWith(filename, prefix)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   /**
    * @return part of request URL after servlet path
    */
index d5bf6699540799f1d63a8d9fdf31c7f846cd3c6f..192854a08d545139072f6d38fd8422a215c0909f 100644 (file)
@@ -75,4 +75,20 @@ public class BatchResourcesServletTest {
     assertThat(servlet.getLibs().size(), is(1));
     assertThat(servlet.getLibs().get(0), is("sonar-core-2.6.jar"));
   }
+
+  @Test
+  public void shouldIgnore() {
+    assertThat(BatchResourcesServlet.isIgnored("sonar-batch-2.6-SNAPSHOT.jar"), is(false));
+    assertThat(BatchResourcesServlet.isIgnored("derby-10.6.1.0.jar"), is(true));
+    assertThat(BatchResourcesServlet.isIgnored("derbyclient-10.6.1.0.jar"), is(true));
+    assertThat(BatchResourcesServlet.isIgnored("derbynet-10.6.1.0.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));
+  }
 }