diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt index 5c16bdb92a..051f9c2eb9 100644 --- a/Documentation/dev-plugins.txt +++ b/Documentation/dev-plugins.txt @@ -384,11 +384,11 @@ If a plugin does not register a filter or servlet to handle URLs `/Documentation/*` or `/static/*`, the core Gerrit server will automatically export these resources over HTTP from the plugin JAR. -Static resources under `static/` directory in the JAR will be +Static resources under the `static/` directory in the JAR will be available as `/plugins/helloworld/static/resource`. This prefix is configurable by setting the `Gerrit-HttpStaticPrefix` attribute. -Documentation files under `Documentation/` directory in the JAR +Documentation files under the `Documentation/` directory in the JAR will be available as `/plugins/helloworld/Documentation/resource`. This prefix is configurable by setting the `Gerrit-HttpDocumentationPrefix` attribute. @@ -444,9 +444,15 @@ For any discovered HTML (`*.html`) file, Gerrit will use the name of the file, minus the `*.html` extension, as the link text. Any hyphens in the file name will be replaced with spaces. +If a discovered file is named `about.md` or `about.html`, its +content will be inserted in an 'About' section at the top of the +auto-generated index page. If both `about.md` and `about.html` +exist, only the first discovered file will be used. + If a discovered file name beings with `cmd-` it will be clustered -into a 'Commands' section of the generated index page. All other -files are clustered under a 'Documentation' section. +into a 'Commands' section of the generated index page. + +All other files are clustered under a 'Documentation' section. Some optional information from the manifest is extracted and displayed as part of the index page, if present in the manifest: diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java index c771f9ebba..4b3084ac3b 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java @@ -44,8 +44,10 @@ import org.eclipse.jgit.util.RawParseUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; @@ -330,6 +332,7 @@ class HttpPluginServlet extends HttpServlet ResourceKey cacheKey, HttpServletResponse res) throws IOException { List cmds = Lists.newArrayList(); List docs = Lists.newArrayList(); + JarEntry about = null; Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); @@ -339,8 +342,13 @@ class HttpPluginServlet extends HttpServlet && (name.endsWith(".md") || name.endsWith(".html")) && 0 < size && size <= SMALL_RESOURCE) { - if (name.substring(prefix.length()).startsWith("cmd-")) { + name = name.substring(prefix.length()); + if (name.startsWith("cmd-")) { cmds.add(entry); + } else if (name.startsWith("about.")) { + if (about == null) { + about = entry; + } } else { docs.add(entry); } @@ -364,6 +372,28 @@ class HttpPluginServlet extends HttpServlet md.append("\n"); appendPluginInfoTable(md, jar.getManifest().getMainAttributes()); + if (about != null) { + InputStreamReader isr = new InputStreamReader(jar.getInputStream(about)); + BufferedReader reader = new BufferedReader(isr); + StringBuilder aboutContent = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (line.isEmpty()) { + aboutContent.append("\n"); + } else { + aboutContent.append(line).append("\n"); + } + } + reader.close(); + + // 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(jar, docs, "Documentation", md, prefix, 0); appendEntriesSection(jar, cmds, "Commands", md, prefix, "cmd-".length());