Search in sources :

Example 81 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class Schema_126 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    try (Repository git = repoManager.openRepository(allUsersName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
        ProjectConfig config = ProjectConfig.read(md);
        String refsUsersShardedId = RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}";
        config.remove(config.getAccessSection(refsUsersShardedId));
        GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
        AccessSection users = config.getAccessSection(refsUsersShardedId, true);
        grant(config, users, Permission.READ, false, true, registered);
        grant(config, users, Permission.PUSH, false, true, registered);
        grant(config, users, Permission.SUBMIT, false, true, registered);
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);
        md.setMessage(COMMIT_MSG);
        config.commit(md);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) GroupReference(com.google.gerrit.common.data.GroupReference) IOException(java.io.IOException) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 82 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class Schema_128 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    try (Repository git = repoManager.openRepository(allProjectsName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git)) {
        ProjectConfig config = ProjectConfig.read(md);
        GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
        AccessSection refsFor = config.getAccessSection("refs/for/*", true);
        grant(config, refsFor, Permission.ADD_PATCH_SET, false, false, registered);
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);
        md.setMessage(COMMIT_MSG);
        config.commit(md);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) GroupReference(com.google.gerrit.common.data.GroupReference) IOException(java.io.IOException) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 83 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class Schema_131 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)) {
            ProjectConfig config = ProjectConfig.read(md);
            if (config.hasLegacyPermissions()) {
                md.getCommitBuilder().setAuthor(serverUser);
                md.getCommitBuilder().setCommitter(serverUser);
                md.setMessage(COMMIT_MSG);
                config.commit(md);
                repoUpgraded.add(projectName);
            }
        } 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) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) 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) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) 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 84 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parseAddApproval.

private PatchSetApproval parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
    // There are potentially 3 accounts involved here:
    //  1. The account from the commit, which is the effective IdentifiedUser
    //     that produced the update.
    //  2. The account in the label footer itself, which is used during submit
    //     to copy other users' labels to a new patch set.
    //  3. The account in the Real-user footer, indicating that the whole
    //     update operation was executed by this user on behalf of the effective
    //     user.
    Account.Id effectiveAccountId;
    String labelVoteStr;
    int s = line.indexOf(' ');
    if (s > 0) {
        // Account in the label line (2) becomes the effective ID of the
        // approval. If there is a real user (3) different from the commit user
        // (2), we actually don't store that anywhere in this case; it's more
        // important to record that the real user (3) actually initiated submit.
        labelVoteStr = line.substring(0, s);
        PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
        checkFooter(ident != null, FOOTER_LABEL, line);
        effectiveAccountId = noteUtil.parseIdent(ident, id);
    } else {
        labelVoteStr = line;
        effectiveAccountId = committerId;
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(labelVoteStr);
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(l.label())), l.value(), ts);
    psa.setTag(tag);
    if (!Objects.equals(realAccountId, committerId)) {
        psa.setRealAccountId(realAccountId);
    }
    ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, l.label());
    if (!approvals.containsKey(k)) {
        approvals.put(k, psa);
    }
    return psa;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 85 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parsePatchSet.

private void parsePatchSet(PatchSet.Id psId, ObjectId rev, Account.Id accountId, Timestamp ts) throws ConfigInvalidException {
    if (accountId == null) {
        throw parseException("patch set %s requires an identified user as uploader", psId.get());
    }
    PatchSet ps = patchSets.get(psId);
    if (ps == null) {
        ps = new PatchSet(psId);
        patchSets.put(psId, ps);
    } else if (!ps.getRevision().equals(PARTIAL_PATCH_SET)) {
        if (deletedPatchSets.contains(psId)) {
            // no relevance
            return;
        }
        throw new ConfigInvalidException(String.format("Multiple revisions parsed for patch set %s: %s and %s", psId.get(), patchSets.get(psId).getRevision(), rev.name()));
    }
    ps.setRevision(new RevId(rev.name()));
    ps.setUploader(accountId);
    ps.setCreatedOn(ts);
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevId(com.google.gerrit.reviewdb.client.RevId)

Aggregations

ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)158 IOException (java.io.IOException)95 Inject (com.google.inject.Inject)38 Repository (org.eclipse.jgit.lib.Repository)37 Provider (com.google.inject.Provider)34 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)31 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)30 ArrayList (java.util.ArrayList)30 Account (com.google.gerrit.entities.Account)27 List (java.util.List)26 Set (java.util.Set)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 AuthException (com.google.gerrit.extensions.restapi.AuthException)25 Config (org.eclipse.jgit.lib.Config)24 Singleton (com.google.inject.Singleton)23 OrmException (com.google.gwtorm.server.OrmException)22 AccountGroup (com.google.gerrit.entities.AccountGroup)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 StorageException (com.google.gerrit.exceptions.StorageException)20 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)20