Search in sources :

Example 46 with FileBasedConfig

use of org.eclipse.jgit.storage.file.FileBasedConfig 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 47 with FileBasedConfig

use of org.eclipse.jgit.storage.file.FileBasedConfig 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

FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)47 File (java.io.File)19 IOException (java.io.IOException)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)12 Config (org.eclipse.jgit.lib.Config)10 FS (org.eclipse.jgit.util.FS)7 Test (org.junit.Test)7 StoredConfig (org.eclipse.jgit.lib.StoredConfig)6 Path (java.nio.file.Path)5 Repository (org.eclipse.jgit.lib.Repository)5 SitePaths (com.google.gerrit.server.config.SitePaths)4 HashMap (java.util.HashMap)4 UserModel (com.gitblit.models.UserModel)3 FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 SystemReader (org.eclipse.jgit.util.SystemReader)3 Before (org.junit.Before)3