Support project specific plugin configuration in own config file
For some plugins the project specific configuration is too complex to be stored in a single 'plugin' subsection in 'project.config'. If a plugin needs subsections in its project specific configuration then the project specific plugin configuration can be stored in an own configuration file in the project's 'refs/meta/config' branch. This change adds a method to PluginConfigFactory to easily access the project specific plugin configuration that is stored in such a plugin configuration file. The project specific plugin configuration is cached within ProjectState (which is cached in the project cache). This avoids reloading and reparsing of the config file on every access. After a project is evicted from the cache the project specific plugin configuration is reloaded. This means that any update that is done to the plugins configuration file is immediately active since any push to the `refs/meta/config` branch evicts the project from the cache and hence triggers a reloading of the project specific plugin configuration. Change-Id: Id5d371a22041bd7381f92e75fb021af5318249b4 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -40,12 +40,14 @@ import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.git.ProjectLevelConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import com.googlecode.prolog_cafe.compiler.CompileException;
|
||||
import com.googlecode.prolog_cafe.lang.PrologMachineCopy;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.slf4j.Logger;
|
||||
@@ -83,6 +85,7 @@ public class ProjectState {
|
||||
private final List<CommentLinkInfo> commentLinks;
|
||||
|
||||
private final ProjectConfig config;
|
||||
private final Map<String, ProjectLevelConfig> configs;
|
||||
private final Set<AccountGroup.UUID> localOwners;
|
||||
|
||||
/** Prolog rule state. */
|
||||
@@ -121,6 +124,7 @@ public class ProjectState {
|
||||
this.rulesCache = rulesCache;
|
||||
this.commentLinks = commentLinks;
|
||||
this.config = config;
|
||||
this.configs = Maps.newHashMap();
|
||||
this.capabilities = isAllProjects
|
||||
? new CapabilityCollection(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
|
||||
: null;
|
||||
@@ -216,6 +220,29 @@ public class ProjectState {
|
||||
return config;
|
||||
}
|
||||
|
||||
public ProjectLevelConfig getConfig(String fileName) {
|
||||
if (configs.containsKey(fileName)) {
|
||||
return configs.get(fileName);
|
||||
}
|
||||
|
||||
ProjectLevelConfig cfg = new ProjectLevelConfig(fileName);
|
||||
try {
|
||||
Repository git = gitMgr.openRepository(getProject().getNameKey());
|
||||
try {
|
||||
cfg.load(git);
|
||||
} finally {
|
||||
git.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
|
||||
} catch (ConfigInvalidException e) {
|
||||
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
|
||||
}
|
||||
|
||||
configs.put(fileName, cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public long getMaxObjectSizeLimit() {
|
||||
return config.getMaxObjectSizeLimit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user