| | |
| | | /*
|
| | | * Copyright 2011 gitblit.com.
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit;
|
| | |
|
| | | import java.io.File;
|
| | |
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.Properties;
|
| | | import java.util.regex.PatternSyntaxException;
|
| | |
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
| | | */
|
| | | public class FileSettings implements IStoredSettings {
|
| | |
|
| | | private final Logger logger = LoggerFactory.getLogger(FileSettings.class);
|
| | |
|
| | | private Properties properties = new Properties();
|
| | |
|
| | | private long lastread = 0;
|
| | |
|
| | | private final Logger logger = LoggerFactory.getLogger(FileSettings.class);
|
| | | private long lastread;
|
| | |
|
| | | @Override
|
| | | public List<String> getAllKeys(String startingWith) {
|
| | |
| | | strings.add(chunk);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | } catch (PatternSyntaxException e) {
|
| | | logger.error("Failed to parse " + value, e);
|
| | | }
|
| | | return strings;
|
| | | }
|
| | |
| | | private synchronized Properties read() {
|
| | | File file = new File(Constants.PROPERTIES_FILE);
|
| | | if (file.exists() && (file.lastModified() > lastread)) {
|
| | | FileInputStream is = null;
|
| | | try {
|
| | | properties = new Properties();
|
| | | properties.load(new FileInputStream(Constants.PROPERTIES_FILE));
|
| | | is = new FileInputStream(Constants.PROPERTIES_FILE);
|
| | | properties.load(is);
|
| | | lastread = file.lastModified();
|
| | | } catch (FileNotFoundException f) {
|
| | | // IGNORE - won't happen because file.exists() check above
|
| | | } catch (Throwable t) {
|
| | | t.printStackTrace();
|
| | | } finally {
|
| | | if (is != null) {
|
| | | try {
|
| | | is.close();
|
| | | } catch (Throwable t) {
|
| | | // IGNORE
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return properties;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return getClass().getSimpleName() + ": " + new File(Constants.PROPERTIES_FILE).getAbsolutePath();
|
| | | return new File(Constants.PROPERTIES_FILE).getAbsolutePath();
|
| | | }
|
| | | }
|