Search in sources :

Example 16 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class Schema_125 method getLabelTypes.

private Collection<LabelType> getLabelTypes(ProjectConfig config) throws IOException, ConfigInvalidException {
    Map<String, LabelType> labelTypes = new HashMap<>(config.getLabelSections());
    Project.NameKey parent = config.getProject().getParent(allProjectsName);
    while (parent != null) {
        try (Repository git = repoManager.openRepository(parent);
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, parent, git)) {
            ProjectConfig parentConfig = ProjectConfig.read(md);
            for (LabelType lt : parentConfig.getLabelSections().values()) {
                if (!labelTypes.containsKey(lt.getName())) {
                    labelTypes.put(lt.getName(), lt);
                }
            }
            parent = parentConfig.getProject().getParent(allProjectsName);
        }
    }
    return labelTypes.values();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) HashMap(java.util.HashMap) LabelType(com.google.gerrit.common.data.LabelType) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 17 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class Schema_130 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SortedSet<Project.NameKey> repoList = repoManager.list();
    SortedSet<Project.NameKey> repoUpgraded = new TreeSet<>();
    ui.message("\tMigrating " + repoList.size() + " repositories ...");
    for (Project.NameKey projectName : repoList) {
        try (Repository git = repoManager.openRepository(projectName);
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, git)) {
            ProjectConfigSchemaUpdate cfg = ProjectConfigSchemaUpdate.read(md);
            cfg.removeForceFromPermission("pushTag");
            if (cfg.isUpdated()) {
                repoUpgraded.add(projectName);
            }
            cfg.save(serverUser, COMMIT_MSG);
        } catch (ConfigInvalidException | IOException ex) {
            throw new OrmException("Cannot migrate project " + projectName, ex);
        }
    }
    ui.message("\tMigration completed:  " + repoUpgraded.size() + " repositories updated:");
    ui.message("\t" + repoUpgraded.stream().map(n -> n.get()).collect(joining(" ")));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SortedSet(java.util.SortedSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) Inject(com.google.inject.Inject) IOException(java.io.IOException) Collectors.joining(java.util.stream.Collectors.joining) TreeSet(java.util.TreeSet) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) TreeSet(java.util.TreeSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 18 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method saveProjectConfig.

protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(p)) {
        md.setAuthor(identifiedUserFactory.create(admin.getId()));
        cfg.commit(md);
    }
    projectCache.evict(cfg.getProject());
}
Also used : MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 19 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method grant.

protected void grant(Project.NameKey project, String ref, String permission, boolean force, AccountGroup.UUID groupUUID) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        md.setMessage(String.format("Grant %s on %s", permission, ref));
        ProjectConfig config = ProjectConfig.read(md);
        AccessSection s = config.getAccessSection(ref, true);
        Permission p = s.getPermission(permission, true);
        PermissionRule rule = Util.newRule(config, groupUUID);
        rule.setForce(force);
        p.add(rule);
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) PermissionRule(com.google.gerrit.common.data.PermissionRule) Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 20 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method removePermission.

protected void removePermission(Project.NameKey project, String ref, String permission) throws IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        md.setMessage(String.format("Remove %s on %s", permission, ref));
        ProjectConfig config = ProjectConfig.read(md);
        AccessSection s = config.getAccessSection(ref, true);
        Permission p = s.getPermission(permission, true);
        p.getRules().clear();
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)37 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)18 Project (com.google.gerrit.reviewdb.client.Project)15 AccessSection (com.google.gerrit.common.data.AccessSection)14 IOException (java.io.IOException)13 Repository (org.eclipse.jgit.lib.Repository)12 OrmException (com.google.gwtorm.server.OrmException)11 Permission (com.google.gerrit.common.data.Permission)9 PermissionRule (com.google.gerrit.common.data.PermissionRule)8 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 HashMap (java.util.HashMap)6 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)6 GroupReference (com.google.gerrit.common.data.GroupReference)5 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 Account (com.google.gerrit.reviewdb.client.Account)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 LabelType (com.google.gerrit.common.data.LabelType)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4