LCOV - code coverage report
Current view: top level - httpd/raw - SiteStaticDirectoryServlet.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 7 8 87.5 %
Date: 2022-11-19 15:00:39 Functions: 1 2 50.0 %

          Line data    Source code
       1             : // Copyright (C) 2008 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.httpd.raw;
      16             : 
      17             : import com.google.common.cache.Cache;
      18             : import com.google.gerrit.server.config.GerritServerConfig;
      19             : import com.google.gerrit.server.config.SitePaths;
      20             : import com.google.inject.Inject;
      21             : import com.google.inject.Singleton;
      22             : import com.google.inject.name.Named;
      23             : import java.io.IOException;
      24             : import java.nio.file.Path;
      25             : import org.eclipse.jgit.lib.Config;
      26             : 
      27             : /** Sends static content from the site 's {@code static/} subdirectory. */
      28             : @Singleton
      29             : public class SiteStaticDirectoryServlet extends ResourceServlet {
      30             :   private static final long serialVersionUID = 1L;
      31             : 
      32             :   private final Path staticBase;
      33             : 
      34             :   @Inject
      35             :   SiteStaticDirectoryServlet(
      36             :       SitePaths site,
      37             :       @GerritServerConfig Config cfg,
      38             :       @Named(StaticModule.CACHE) Cache<Path, Resource> cache) {
      39          99 :     super(cache, cfg.getBoolean("site", "refreshHeaderFooter", true));
      40             :     Path p;
      41             :     try {
      42          15 :       p = site.static_dir.toRealPath().normalize();
      43          92 :     } catch (IOException e) {
      44          92 :       p = site.static_dir.toAbsolutePath().normalize();
      45          15 :     }
      46          99 :     staticBase = p;
      47          99 :   }
      48             : 
      49             :   @Override
      50             :   protected Path getResourcePath(String pathInfo) {
      51           0 :     return staticBase.resolve(pathInfo);
      52             :   }
      53             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750