Line data Source code
1 : // Copyright (C) 2013 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.acceptance; 16 : 17 : import com.google.common.collect.Lists; 18 : import java.io.File; 19 : import org.eclipse.jgit.lib.Config; 20 : import org.eclipse.jgit.storage.file.FileBasedConfig; 21 : import org.eclipse.jgit.util.FS; 22 : 23 : /** A file based Config that can merge another Config instance. */ 24 : public class MergeableFileBasedConfig extends FileBasedConfig { 25 : public MergeableFileBasedConfig(File cfgLocation, FS fs) { 26 16 : super(cfgLocation, fs); 27 16 : } 28 : 29 : /** 30 : * Merge another Config into this Config. 31 : * 32 : * <p>In case a configuration parameter exists both in this instance and in the merged instance 33 : * then the value in this instance will simply replaced by the value from the merged instance. 34 : * 35 : * @param s Config to merge into this instance 36 : */ 37 : public void merge(Config s) { 38 16 : if (s == null) { 39 1 : return; 40 : } 41 16 : for (String section : s.getSections()) { 42 12 : for (String subsection : s.getSubsections(section)) { 43 2 : for (String name : s.getNames(section, subsection, true)) { 44 2 : setStringList( 45 : section, 46 : subsection, 47 : name, 48 2 : Lists.newArrayList(s.getStringList(section, subsection, name))); 49 2 : } 50 2 : } 51 : 52 12 : for (String name : s.getNames(section, true)) { 53 12 : setStringList( 54 12 : section, null, name, Lists.newArrayList(s.getStringList(section, null, name))); 55 12 : } 56 12 : } 57 16 : } 58 : }