Fix getting inherited values from PluginConfig
The code for constructing a Config with the parameters from the current project plus the missing parameters from the parent projects relies on getting all parameter names from Config#getNames(...). The problem is that Config#getNames(...) doesn't include parameter names which are only available in the default Config (the Config that we provided to the constructor when creating a new Config). This may lead to a situation where a parameter is defined on a project, but a grandchild of it is not inheriting this parameter although it and its parent do not have this parameter. To fix this we are now copying the initial Config instead of creating a new Config and providing the existing Config as default Config to it. Change-Id: I93ed8f7f13f1bc757e59a5897f1949540c41f9ed
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -53,7 +54,7 @@ public class PluginConfig {
|
||||
parent.getConfig().getPluginConfig(pluginName)
|
||||
.withInheritance(projectStateFactory);
|
||||
Set<String> allNames = cfg.getNames(PLUGIN, pluginName);
|
||||
cfg = new Config(cfg);
|
||||
cfg = copyConfig(cfg);
|
||||
for (String name : parentPluginConfig.cfg.getNames(PLUGIN, pluginName)) {
|
||||
if (!allNames.contains(name)) {
|
||||
cfg.setStringList(PLUGIN, pluginName, name, Arrays
|
||||
@@ -64,6 +65,17 @@ public class PluginConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static Config copyConfig(Config cfg) {
|
||||
Config copiedCfg = new Config();
|
||||
try {
|
||||
copiedCfg.fromText(cfg.toText());
|
||||
} catch (ConfigInvalidException e) {
|
||||
// cannot happen
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return copiedCfg;
|
||||
}
|
||||
|
||||
public String getString(String name) {
|
||||
return cfg.getString(PLUGIN, pluginName, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user