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:
@@ -28,6 +28,7 @@ import org.eclipse.jgit.api.AddCommand;
|
||||
import org.eclipse.jgit.api.CheckoutCommand;
|
||||
import org.eclipse.jgit.api.CloneCommand;
|
||||
import org.eclipse.jgit.api.CommitCommand;
|
||||
import org.eclipse.jgit.api.FetchCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.PushCommand;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
@@ -178,6 +179,12 @@ public class GitUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void fetch(Git git, String spec) throws GitAPIException {
|
||||
FetchCommand fetch = git.fetch();
|
||||
fetch.setRefSpecs(new RefSpec(spec));
|
||||
fetch.call();
|
||||
}
|
||||
|
||||
public static void checkout(Git git, String name) throws GitAPIException {
|
||||
CheckoutCommand checkout = git.checkout();
|
||||
checkout.setName(name);
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// 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.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.gerrit.acceptance.git.GitUtil.checkout;
|
||||
import static com.google.gerrit.acceptance.git.GitUtil.cloneProject;
|
||||
import static com.google.gerrit.acceptance.git.GitUtil.createProject;
|
||||
import static com.google.gerrit.acceptance.git.GitUtil.fetch;
|
||||
import static com.google.gerrit.acceptance.git.GitUtil.initSsh;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.acceptance.git.PushOneCommit;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProjectLevelConfigIT extends AbstractDaemonTest {
|
||||
|
||||
@Inject
|
||||
private AccountCreator accounts;
|
||||
|
||||
@Inject
|
||||
private SchemaFactory<ReviewDb> reviewDbProvider;
|
||||
|
||||
@Inject
|
||||
private ProjectCache projectCache;
|
||||
|
||||
private ReviewDb db;
|
||||
private TestAccount admin;
|
||||
private String project;
|
||||
private Git git;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
admin = accounts.admin();
|
||||
initSsh(admin);
|
||||
SshSession sshSession = new SshSession(server, admin);
|
||||
|
||||
project = "p";
|
||||
createProject(sshSession, project, null, true);
|
||||
git = cloneProject(sshSession.getUrl() + "/" + project);
|
||||
fetch(git, GitRepositoryManager.REF_CONFIG + ":refs/heads/config");
|
||||
checkout(git, "refs/heads/config");
|
||||
|
||||
db = reviewDbProvider.open();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessProjectSpecificConfig() throws GitAPIException, IOException {
|
||||
String configName = "test.config";
|
||||
Config cfg = new Config();
|
||||
cfg.setString("s1", null, "k1", "v1");
|
||||
cfg.setString("s2", "ss", "k2", "v2");
|
||||
PushOneCommit push =
|
||||
new PushOneCommit(db, admin.getIdent(), "Create Project Level Config",
|
||||
configName, cfg.toText());
|
||||
push.to(git, GitRepositoryManager.REF_CONFIG);
|
||||
|
||||
ProjectState state = projectCache.get(new Project.NameKey(project));
|
||||
assertEquals(cfg.toText(), state.getConfig(configName).get().toText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonExistingConfig() {
|
||||
ProjectState state = projectCache.get(new Project.NameKey(project));
|
||||
assertEquals("", state.getConfig("test.config").get().toText());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user