Search in sources :

Example 1 with DebugRenderer

use of com.google.gitiles.DebugRenderer in project gitiles by GerritCodeReview.

the class DevServer method createRootedDocServlet.

private Servlet createRootedDocServlet(DebugRenderer renderer, String docRoot) {
    File docRepo = new File(docRoot);
    FileKey repoKey = FileKey.exact(docRepo, FS.DETECTED);
    RepositoryResolver<HttpServletRequest> resolver = (req, name) -> {
        try {
            return RepositoryCache.open(repoKey, true);
        } catch (IOException e) {
            throw new RepositoryNotFoundException(repoKey.getFile(), e);
        }
    };
    return new RootedDocServlet(resolver, new RootedDocAccess(docRepo), renderer);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) PathResource(org.eclipse.jetty.util.resource.PathResource) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) URISyntaxException(java.net.URISyntaxException) GitilesAccess(com.google.gitiles.GitilesAccess) LoggerFactory(org.slf4j.LoggerFactory) InetAddress(java.net.InetAddress) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) RepositoryDescription(com.google.gitiles.RepositoryDescription) Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) GitilesServlet(com.google.gitiles.GitilesServlet) RepositoryCache(org.eclipse.jgit.lib.RepositoryCache) Logger(org.slf4j.Logger) Servlet(javax.servlet.Servlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) PathServlet(com.google.gitiles.PathServlet) Set(java.util.Set) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) RepositoryResolver(org.eclipse.jgit.transport.resolver.RepositoryResolver) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) STATIC_PREFIX(com.google.gitiles.GitilesServlet.STATIC_PREFIX) UnknownHostException(java.net.UnknownHostException) FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) File(java.io.File) RootedDocServlet(com.google.gitiles.RootedDocServlet) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Paths(java.nio.file.Paths) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FS(org.eclipse.jgit.util.FS) DebugRenderer(com.google.gitiles.DebugRenderer) Collections(java.util.Collections) HttpServletRequest(javax.servlet.http.HttpServletRequest) FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) File(java.io.File) RootedDocServlet(com.google.gitiles.RootedDocServlet)

Example 2 with DebugRenderer

use of com.google.gitiles.DebugRenderer in project gitiles by GerritCodeReview.

the class DevServer method appHandler.

private Handler appHandler() {
    DebugRenderer renderer = new DebugRenderer(STATIC_PREFIX, Arrays.asList(cfg.getStringList("gitiles", null, "customTemplates")), sourceRoot.resolve("gitiles-servlet/src/main/resources/com/google/gitiles/templates").toString(), firstNonNull(cfg.getString("gitiles", null, "siteTitle"), "Gitiles"));
    String docRoot = cfg.getString("gitiles", null, "docroot");
    Servlet servlet;
    if (!Strings.isNullOrEmpty(docRoot)) {
        servlet = createRootedDocServlet(renderer, docRoot);
    } else {
        servlet = new GitilesServlet(cfg, renderer, null, null, null, null, null, null, null);
    }
    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("");
    handler.addServlet(new ServletHolder(servlet), "/*");
    return handler;
}
Also used : DebugRenderer(com.google.gitiles.DebugRenderer) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) GitilesServlet(com.google.gitiles.GitilesServlet) Servlet(javax.servlet.Servlet) PathServlet(com.google.gitiles.PathServlet) RootedDocServlet(com.google.gitiles.RootedDocServlet) GitilesServlet(com.google.gitiles.GitilesServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

DebugRenderer (com.google.gitiles.DebugRenderer)2 GitilesServlet (com.google.gitiles.GitilesServlet)2 PathServlet (com.google.gitiles.PathServlet)2 RootedDocServlet (com.google.gitiles.RootedDocServlet)2 Servlet (javax.servlet.Servlet)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 GitilesAccess (com.google.gitiles.GitilesAccess)1 STATIC_PREFIX (com.google.gitiles.GitilesServlet.STATIC_PREFIX)1 RepositoryDescription (com.google.gitiles.RepositoryDescription)1 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1