aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-09-25 01:14:53 +0000
committerGodin <mandrikov@gmail.com>2010-09-25 01:14:53 +0000
commit2dc85f396a6e04650ffa909f55aa6d34173b5eb1 (patch)
tree80db7d1ab6a6fe0d0b4fc8b2d6c414c496ebbef3 /sonar-server
parentcea7dd429645b3c86a7810f8bfc74cbbfb0955c9 (diff)
downloadsonarqube-2dc85f396a6e04650ffa909f55aa6d34173b5eb1.tar.gz
sonarqube-2dc85f396a6e04650ffa909f55aa6d34173b5eb1.zip
SONAR-1709: Add StaticResourcesServlet for loading static resources from plugins
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/dev/web.xml9
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java51
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/web.xml11
4 files changed, 73 insertions, 4 deletions
diff --git a/sonar-server/src/dev/web.xml b/sonar-server/src/dev/web.xml
index afd470ea8e0..5943fb50f09 100644
--- a/sonar-server/src/dev/web.xml
+++ b/sonar-server/src/dev/web.xml
@@ -53,6 +53,11 @@
<servlet-name>gchart</servlet-name>
<servlet-class>org.jfree.eastwood.ChartServlet</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>static</servlet-name>
+ <servlet-class>org.sonar.server.plugins.StaticResourcesServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>chart</servlet-name>
<url-pattern>/chart</url-pattern>
@@ -61,6 +66,10 @@
<servlet-name>gchart</servlet-name>
<url-pattern>/gchart</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>static</servlet-name>
+ <url-pattern>/static/*</url-pattern>
+ </servlet-mapping>
<listener>
<listener-class>org.sonar.server.platform.PlatformLifecycleListener</listener-class>
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java b/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
new file mode 100644
index 00000000000..4864f895e49
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
@@ -0,0 +1,51 @@
+package org.sonar.server.plugins;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.server.platform.Platform;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class StaticResourcesServlet extends HttpServlet {
+
+ private static final Logger LOG = LoggerFactory.getLogger(StaticResourcesServlet.class);
+
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String path = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath() + request.getServletPath() + "/");
+ String pluginKey = StringUtils.substringBefore(path, "/");
+ String resource = "/static/" + StringUtils.substringAfter(path, "/");
+
+ PluginClassLoaders pluginClassLoaders = Platform.getInstance().getContainer().getComponent(PluginClassLoaders.class);
+
+ ClassLoader classLoader = pluginClassLoaders.getClassLoader(pluginKey);
+ if (classLoader == null) {
+ return;
+ }
+
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = classLoader.getResourceAsStream(resource);
+ if (in != null) {
+ out = response.getOutputStream();
+ IOUtils.copy(in, out);
+ }
+ } catch (Exception e) {
+ LOG.error("Unable to load static resource '" + resource + "' from plugin '" + pluginKey + "'", e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ }
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
index 92ac5eabba9..f8997db4be1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
@@ -162,9 +162,9 @@ module ApplicationHelper
if options[:resource]
"#{ApplicationController.root_context}/plugins/resource/#{options[:resource]}?page=#{page}"
elsif @project
- "#{ApplicationController.root_context}/plugins/resource/#{@project.id}?page=#{page}"
- else
- ''
+ "#{ApplicationController.root_context}/plugins/resource/#{@project.id}?page=#{page}"
+ else
+ ''
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/web.xml b/sonar-server/src/main/webapp/WEB-INF/web.xml
index 58c1f1a825b..99d68dcc5f6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/web.xml
+++ b/sonar-server/src/main/webapp/WEB-INF/web.xml
@@ -74,13 +74,22 @@
<servlet-name>gchart</servlet-name>
<servlet-class>org.jfree.eastwood.ChartServlet</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>static</servlet-name>
+ <servlet-class>org.sonar.server.plugins.StaticResourcesServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>chart</servlet-name>
<url-pattern>/chart</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>gchart</servlet-name>
- <url-pattern>/gchart</url-pattern>
+ <url-pattern>/gchart</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>static</servlet-name>
+ <url-pattern>/static/*</url-pattern>
</servlet-mapping>
<listener>