use of com.google.gerrit.server.plugins.Plugin in project gerrit by GerritCodeReview.
the class HttpPluginServlet method sendAutoIndex.
private void sendAutoIndex(PluginContentScanner scanner, final String prefix, final String pluginName, PluginResourceKey cacheKey, HttpServletResponse res, long lastModifiedTime) throws IOException {
List<PluginEntry> cmds = new ArrayList<>();
List<PluginEntry> servlets = new ArrayList<>();
List<PluginEntry> restApis = new ArrayList<>();
List<PluginEntry> docs = new ArrayList<>();
PluginEntry about = null;
Predicate<PluginEntry> filter = entry -> {
String name = entry.getName();
Optional<Long> size = entry.getSize();
if (name.startsWith(prefix) && (name.endsWith(".md") || name.endsWith(".html")) && size.isPresent()) {
if (size.get() <= 0 || size.get() > SMALL_RESOURCE) {
log.warn(String.format("Plugin %s: %s omitted from document index. " + "Size %d out of range (0,%d).", pluginName, name.substring(prefix.length()), size.get(), SMALL_RESOURCE));
return false;
}
return true;
}
return false;
};
List<PluginEntry> entries = Collections.list(scanner.entries()).stream().filter(filter).collect(toList());
for (PluginEntry entry : entries) {
String name = entry.getName().substring(prefix.length());
if (name.startsWith("cmd-")) {
cmds.add(entry);
} else if (name.startsWith("servlet-")) {
servlets.add(entry);
} else if (name.startsWith("rest-api-")) {
restApis.add(entry);
} else if (name.startsWith("about.")) {
if (about == null) {
about = entry;
} else {
log.warn(String.format("Plugin %s: Multiple 'about' documents found; using %s", pluginName, about.getName().substring(prefix.length())));
}
} else {
docs.add(entry);
}
}
Collections.sort(cmds, PluginEntry.COMPARATOR_BY_NAME);
Collections.sort(docs, PluginEntry.COMPARATOR_BY_NAME);
StringBuilder md = new StringBuilder();
md.append(String.format("# Plugin %s #\n", pluginName));
md.append("\n");
appendPluginInfoTable(md, scanner.getManifest().getMainAttributes());
if (about != null) {
InputStreamReader isr = new InputStreamReader(scanner.getInputStream(about), UTF_8);
StringBuilder aboutContent = new StringBuilder();
try (BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
aboutContent.append("\n");
} else {
aboutContent.append(line).append("\n");
}
}
}
// Only append the About section if there was anything in it
if (aboutContent.toString().trim().length() > 0) {
md.append("## About ##\n");
md.append("\n").append(aboutContent);
}
}
appendEntriesSection(scanner, docs, "Documentation", md, prefix, 0);
appendEntriesSection(scanner, servlets, "Servlets", md, prefix, "servlet-".length());
appendEntriesSection(scanner, restApis, "REST APIs", md, prefix, "rest-api-".length());
appendEntriesSection(scanner, cmds, "Commands", md, prefix, "cmd-".length());
sendMarkdownAsHtml(md.toString(), pluginName, cacheKey, res, lastModifiedTime);
}
use of com.google.gerrit.server.plugins.Plugin in project gerrit by GerritCodeReview.
the class HttpPluginServlet method init.
@Override
public synchronized void init(ServletConfig config) throws ServletException {
super.init(config);
wrapper = new ContextMapper(config.getServletContext().getContextPath());
for (Plugin plugin : pending) {
install(plugin);
}
pending = null;
}
use of com.google.gerrit.server.plugins.Plugin in project gerrit by GerritCodeReview.
the class LfsPluginServlet method init.
@Override
public synchronized void init(ServletConfig config) throws ServletException {
super.init(config);
for (Plugin plugin : pending) {
install(plugin);
}
pending = null;
}
use of com.google.gerrit.server.plugins.Plugin in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method dynamicUnloading.
@Test
public void dynamicUnloading() throws Exception {
EasyMockSupport ems = new EasyMockSupport();
FilterConfig config = ems.createMock(FilterConfig.class);
HttpServletRequest req1 = new FakeHttpServletRequest();
HttpServletRequest req2 = new FakeHttpServletRequest();
HttpServletRequest req3 = new FakeHttpServletRequest();
HttpServletResponse res1 = new FakeHttpServletResponse();
HttpServletResponse res2 = new FakeHttpServletResponse();
HttpServletResponse res3 = new FakeHttpServletResponse();
Plugin plugin = ems.createMock(Plugin.class);
IMocksControl mockControl = ems.createStrictControl();
FilterChain chain = mockControl.createMock("chain", FilterChain.class);
Capture<FilterChain> capturedChainA1 = new Capture<>();
Capture<FilterChain> capturedChainB1 = new Capture<>();
Capture<FilterChain> capturedChainB2 = new Capture<>();
AllRequestFilter filterA = mockControl.createMock("filterA", AllRequestFilter.class);
AllRequestFilter filterB = mockControl.createMock("filterB", AllRequestFilter.class);
filterA.init(config);
filterB.init(config);
filterA.doFilter(eq(req1), eq(res1), capture(capturedChainA1));
filterB.doFilter(eq(req1), eq(res1), capture(capturedChainB1));
chain.doFilter(req1, res1);
// Cleaning up of filterA after it got unloaded
filterA.destroy();
filterB.doFilter(eq(req2), eq(res2), capture(capturedChainB2));
chain.doFilter(req2, res2);
// Cleaning up of filterA after it got unloaded
filterB.destroy();
chain.doFilter(req3, res3);
ems.replayAll();
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
ReloadableRegistrationHandle<AllRequestFilter> handleFilterA = addFilter(filterA);
ReloadableRegistrationHandle<AllRequestFilter> handleFilterB = addFilter(filterB);
filterProxy.init(config);
// Request #1 with filterA and filterB
filterProxy.doFilter(req1, res1, chain);
capturedChainA1.getValue().doFilter(req1, res1);
capturedChainB1.getValue().doFilter(req1, res1);
// Unloading filterA
handleFilterA.remove();
filterProxy.onStopPlugin(plugin);
// Request #1 only with filterB
filterProxy.doFilter(req2, res2, chain);
capturedChainA1.getValue().doFilter(req2, res2);
// Unloading filterB
handleFilterB.remove();
filterProxy.onStopPlugin(plugin);
// Request #1 with no additional filters
filterProxy.doFilter(req3, res3, chain);
filterProxy.destroy();
ems.verifyAll();
}
Aggregations