Decouple plugins from their "jar" external form

Until now all the server-side plugins have been associated
to a single jar file in the /plugin directory.

As first step to allow different forms of plugins
(e.g. script files, directories or anything else that
can provide classes and resources) we need to de-couple
the underlying Jar file from the server side plugin.

We introduce the concept of "plugin-scanner" as the interface
to scan the external form to discover:
- plugin classes
- plugin resources
- plugin meta-data (i.e. Manifest)

Change-Id: I769595a030545a5f272f453c3cf435b74719e1e7
This commit is contained in:
Luca Milanesio
2014-01-29 23:53:00 +00:00
parent 0927a52b64
commit a0c3ba5a4d
10 changed files with 320 additions and 46 deletions

View File

@@ -29,6 +29,7 @@ import com.google.gerrit.server.documentation.MarkdownFormatter;
import com.google.gerrit.server.plugins.Plugin;
import com.google.gerrit.server.plugins.PluginsCollection;
import com.google.gerrit.server.plugins.ReloadPluginListener;
import com.google.gerrit.server.plugins.ServerPlugin;
import com.google.gerrit.server.plugins.StartPluginListener;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.gwtexpui.server.CacheHeaders;
@@ -268,7 +269,7 @@ class HttpPluginServlet extends HttpServlet
}
if (file.startsWith(holder.staticPrefix)) {
JarFile jar = holder.plugin.getJarFile();
JarFile jar = jarFileOf(holder.plugin);
if (jar != null) {
JarEntry entry = jar.getJarEntry(file);
if (exists(entry)) {
@@ -286,7 +287,7 @@ class HttpPluginServlet extends HttpServlet
} else if (file.startsWith(holder.docPrefix) && file.endsWith("/")) {
res.sendRedirect(uri + "index.html");
} else if (file.startsWith(holder.docPrefix)) {
JarFile jar = holder.plugin.getJarFile();
JarFile jar = jarFileOf(holder.plugin);
JarEntry entry = jar.getJarEntry(file);
if (!exists(entry)) {
entry = findSource(jar, file);
@@ -632,6 +633,14 @@ class HttpPluginServlet extends HttpServlet
return data;
}
private static JarFile jarFileOf(Plugin plugin) {
if(plugin instanceof ServerPlugin) {
return ((ServerPlugin) plugin).getJarFile();
} else {
return null;
}
}
private static class PluginHolder {
final Plugin plugin;
final GuiceFilter filter;
@@ -648,7 +657,7 @@ class HttpPluginServlet extends HttpServlet
}
private static String getPrefix(Plugin plugin, String attr, String def) {
JarFile jarFile = plugin.getJarFile();
JarFile jarFile = jarFileOf(plugin);
if (jarFile == null) {
return def;
}