Search in sources :

Example 1 with FileBasedAllProjectsConfigProvider

use of com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider in project gerrit by GerritCodeReview.

the class AllProjectsConfigTest method setUp.

@Before
public void setUp() throws Exception {
    sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
    Files.createDirectories(sitePaths.etc_dir);
    Path gitPath = sitePaths.resolve("git");
    StoredConfig gerritConfig = new FileBasedConfig(sitePaths.resolve("etc").resolve("gerrit.config").toFile(), FS.DETECTED);
    gerritConfig.load();
    gerritConfig.setString("gerrit", null, "basePath", gitPath.toAbsolutePath().toString());
    gerritConfig.setString("gerrit", null, "allProjects", ALL_PROJECTS);
    gerritConfig.save();
    Files.createDirectories(sitePaths.resolve("git"));
    allProjectsRepoFile = gitPath.resolve("All-The-Projects.git").toFile();
    try (Repository repo = new FileRepository(allProjectsRepoFile)) {
        repo.create(true);
    }
    InMemorySecureStore secureStore = new InMemorySecureStore();
    InitFlags flags = new InitFlags(sitePaths, secureStore, ImmutableList.of(), false);
    Section.Factory sections = (name, subsection) -> new Section(flags, sitePaths, secureStore, ui, name, subsection);
    AllProjectsConfigProvider configProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
    allProjectsConfig = new AllProjectsConfig(new AllProjectsNameOnInitProvider(sections), configProvider, sitePaths, flags);
}
Also used : Path(java.nio.file.Path) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) InMemorySecureStore(com.google.gerrit.server.securestore.testing.InMemorySecureStore) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) Config(org.eclipse.jgit.lib.Config) ImmutableList(com.google.common.collect.ImmutableList) Path(java.nio.file.Path) Before(org.junit.Before) TestRepository(org.eclipse.jgit.junit.TestRepository) Files(java.nio.file.Files) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) File(java.io.File) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Rule(org.junit.Rule) SitePaths(com.google.gerrit.server.config.SitePaths) StoredConfig(org.eclipse.jgit.lib.StoredConfig) FS(org.eclipse.jgit.util.FS) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Repository(org.eclipse.jgit.lib.Repository) TemporaryFolder(org.junit.rules.TemporaryFolder) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) SitePaths(com.google.gerrit.server.config.SitePaths) StoredConfig(org.eclipse.jgit.lib.StoredConfig) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) InMemorySecureStore(com.google.gerrit.server.securestore.testing.InMemorySecureStore) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Before(org.junit.Before)

Example 2 with FileBasedAllProjectsConfigProvider

use of com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider in project gerrit by GerritCodeReview.

the class ProjectConfigTest method allProjectsProjectConfigInSitePaths_hashForKeyChangesWithnFileChanges.

@Test
public void allProjectsProjectConfigInSitePaths_hashForKeyChangesWithnFileChanges() throws Exception {
    Path tmp = Files.createTempFile("gerrit_test_", "_site");
    Files.deleteIfExists(tmp);
    SitePaths sitePaths = new SitePaths(tmp);
    FileBasedAllProjectsConfigProvider allProjectsConfigProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
    byte[] hashedContents = ProjectCacheImpl.allProjectsFileProjectConfigHash(allProjectsConfigProvider.get(ALL_PROJECTS));
    // Empty/absent config
    assertThat(hashedContents).isEqualTo(new byte[16]);
    FileBasedConfig fileBasedConfig = new FileBasedConfig(sitePaths.etc_dir.resolve(ALL_PROJECTS.get()).resolve(ProjectConfig.PROJECT_CONFIG).toFile(), FS.DETECTED);
    fileBasedConfig.setString("plugin", "my-plugin", "key", "value");
    fileBasedConfig.save();
    hashedContents = ProjectCacheImpl.allProjectsFileProjectConfigHash(allProjectsConfigProvider.get(ALL_PROJECTS));
    assertThat(hashedContents).isEqualTo(new byte[] { -53, -97, -1, 52, -119, 104, -13, -41, -7, 82, -90, 126, -32, -13, -91, 49 });
}
Also used : Path(java.nio.file.Path) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) SitePaths(com.google.gerrit.server.config.SitePaths) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Test(org.junit.Test)

Example 3 with FileBasedAllProjectsConfigProvider

use of com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider in project gerrit by GerritCodeReview.

the class ProjectConfigTest method setUp.

@Before
public void setUp() throws Exception {
    sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
    Files.createDirectories(sitePaths.etc_dir);
    factory = new ProjectConfig.Factory(ALL_PROJECTS, new FileBasedAllProjectsConfigProvider(sitePaths));
    db = new InMemoryRepository(new DfsRepositoryDescription("repo"));
    tr = new TestRepository<>(db);
}
Also used : FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) SitePaths(com.google.gerrit.server.config.SitePaths) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) Before(org.junit.Before)

Example 4 with FileBasedAllProjectsConfigProvider

use of com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider in project gerrit by GerritCodeReview.

the class ProjectConfigSchemaUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
    Files.createDirectories(sitePaths.etc_dir);
    Path gitPath = sitePaths.resolve("git");
    StoredConfig gerritConfig = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
    gerritConfig.load();
    gerritConfig.setString("gerrit", null, "basePath", gitPath.toAbsolutePath().toString());
    gerritConfig.setString("gerrit", null, "allProjects", ALL_PROJECTS);
    gerritConfig.save();
    Files.createDirectories(sitePaths.resolve("git"));
    allProjectsRepoFile = gitPath.resolve("All-The-Projects.git").toFile();
    try (Repository repo = new FileRepository(allProjectsRepoFile)) {
        repo.create(true);
    }
    FileBasedAllProjectsConfigProvider configProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
    factory = new ProjectConfigSchemaUpdate.Factory(new AllProjectsName(ALL_PROJECTS), configProvider);
}
Also used : Path(java.nio.file.Path) StoredConfig(org.eclipse.jgit.lib.StoredConfig) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) SitePaths(com.google.gerrit.server.config.SitePaths) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Before(org.junit.Before)

Aggregations

FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)4 SitePaths (com.google.gerrit.server.config.SitePaths)4 Path (java.nio.file.Path)3 FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)3 Before (org.junit.Before)3 FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)2 TestRepository (org.eclipse.jgit.junit.TestRepository)2 Repository (org.eclipse.jgit.lib.Repository)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AllProjectsConfigProvider (com.google.gerrit.server.config.AllProjectsConfigProvider)1 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)1 InMemorySecureStore (com.google.gerrit.server.securestore.testing.InMemorySecureStore)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 DfsRepositoryDescription (org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription)1