Line data Source code
1 : // Copyright (C) 2017 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.server.git; 16 : 17 : import com.google.common.flogger.FluentLogger; 18 : import com.google.gerrit.extensions.events.LifecycleListener; 19 : import com.google.gerrit.server.config.SitePaths; 20 : import com.google.gerrit.server.util.git.DelegateSystemReader; 21 : import com.google.inject.Inject; 22 : import com.google.inject.Singleton; 23 : import org.eclipse.jgit.lib.Config; 24 : import org.eclipse.jgit.storage.file.FileBasedConfig; 25 : import org.eclipse.jgit.util.FS; 26 : import org.eclipse.jgit.util.SystemReader; 27 : 28 : @Singleton 29 : public class SystemReaderInstaller implements LifecycleListener { 30 16 : private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 31 : 32 : private final SitePaths site; 33 : 34 : @Inject 35 16 : SystemReaderInstaller(SitePaths site) { 36 16 : this.site = site; 37 16 : } 38 : 39 : @Override 40 : public void start() { 41 16 : SystemReader.setInstance(customReader()); 42 16 : logger.atInfo().log("Set JGit's SystemReader to read system config from %s", site.jgit_config); 43 16 : } 44 : 45 : @Override 46 15 : public void stop() {} 47 : 48 : private SystemReader customReader() { 49 16 : SystemReader current = SystemReader.getInstance(); 50 : 51 16 : return new DelegateSystemReader(current) { 52 : @Override 53 : public FileBasedConfig openSystemConfig(Config parent, FS fs) { 54 16 : return new FileBasedConfig(parent, site.jgit_config.toFile(), FS.DETECTED); 55 : } 56 : }; 57 : } 58 : }