blob: 640f3ca44746aea2376bfe09d093fa5452593367 [file] [log] [blame]
Dave Borowitz5d49ff22012-12-17 14:07:57 -08001// Copyright 2012 Google Inc. All Rights Reserved.
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
15package com.google.gitiles;
16
17import org.eclipse.jgit.errors.ConfigInvalidException;
18import org.eclipse.jgit.lib.Config;
19import org.eclipse.jgit.storage.file.FileBasedConfig;
20import org.eclipse.jgit.util.FS;
21
22import java.io.File;
23import java.io.IOException;
24
25import javax.servlet.FilterConfig;
26
27public class GitilesConfig {
28 private static final String FILTER_CONFIG_PARAM = "configPath";
29 private static final String PROPERTY_NAME = "com.google.gitiles.configPath";
30 private static final String DEFAULT_PATH = "gitiles.config";
31
Dave Borowitz03397692012-12-18 17:11:16 -080032 public static File defaultFile() {
33 return defaultFile(null);
Dave Borowitz5d49ff22012-12-17 14:07:57 -080034 }
35
Dave Borowitz03397692012-12-18 17:11:16 -080036 public static File defaultFile(FilterConfig filterConfig) {
Dave Borowitz5d49ff22012-12-17 14:07:57 -080037 String configPath = null;
38 if (filterConfig != null) {
39 configPath = filterConfig.getInitParameter(FILTER_CONFIG_PARAM);
40 }
41 if (configPath == null) {
42 configPath = System.getProperty(PROPERTY_NAME, DEFAULT_PATH);
43 }
Dave Borowitz03397692012-12-18 17:11:16 -080044 return new File(configPath);
45 }
46
47 public static Config loadDefault() throws IOException, ConfigInvalidException {
48 return loadDefault(null);
49 }
50
51 public static Config loadDefault(FilterConfig filterConfig)
52 throws IOException, ConfigInvalidException {
Dave Borowitzc0960322013-03-26 23:53:27 -040053 FileBasedConfig config = new FileBasedConfig(defaultFile(filterConfig), FS.DETECTED);
Dave Borowitz5d49ff22012-12-17 14:07:57 -080054 config.load();
55 return config;
56 }
57
58 private GitilesConfig() {}
59}