Line data Source code
1 : // Copyright (C) 2015 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.util.time.TimeUtil; 19 : import java.io.IOException; 20 : import java.nio.file.FileSystems; 21 : import java.nio.file.Path; 22 : import java.nio.file.attribute.FileTime; 23 : 24 : class PolyGerritUiServlet extends ResourceServlet { 25 : private static final long serialVersionUID = 1L; 26 : 27 0 : private static final FileTime NOW = FileTime.fromMillis(TimeUtil.nowMs()); 28 : 29 : private final Path ui; 30 : 31 : PolyGerritUiServlet(Cache<Path, Resource> cache, Path ui) { 32 0 : super(cache, true); 33 0 : this.ui = ui; 34 0 : } 35 : 36 : @Override 37 : protected Path getResourcePath(String pathInfo) { 38 0 : return ui.resolve(pathInfo); 39 : } 40 : 41 : @Override 42 : protected FileTime getLastModifiedTime(Path p) throws IOException { 43 0 : if (ui.getFileSystem().equals(FileSystems.getDefault())) { 44 : // Assets are being served from disk, so we can trust the mtime. 45 0 : return super.getLastModifiedTime(p); 46 : } 47 : // Assume this FileSystem is serving from a WAR. All WAR outputs from the build process have 48 : // mtimes of 1980/1/1, so we can't trust it, and return the initialization time of this class 49 : // instead. 50 0 : return NOW; 51 : } 52 : }