Search in sources :

Example 6 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertInvalidButParsableExternalIds.

private Set<ConsistencyProblemInfo> insertInvalidButParsableExternalIds() throws IOException, ConfigInvalidException, OrmException {
    MutableInteger i = new MutableInteger();
    String scheme = "invalid";
    ExternalIdsUpdate u = extIdsUpdate.create();
    Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
    ExternalId extIdForNonExistingAccount = createExternalIdForNonExistingAccount(nextId(scheme, i));
    u.insert(extIdForNonExistingAccount);
    expectedProblems.add(consistencyError("External ID '" + extIdForNonExistingAccount.key().get() + "' belongs to account that doesn't exist: " + extIdForNonExistingAccount.accountId().get()));
    ExternalId extIdWithInvalidEmail = createExternalIdWithInvalidEmail(nextId(scheme, i));
    u.insert(extIdWithInvalidEmail);
    expectedProblems.add(consistencyError("External ID '" + extIdWithInvalidEmail.key().get() + "' has an invalid email: " + extIdWithInvalidEmail.email()));
    ExternalId extIdWithDuplicateEmail = createExternalIdWithDuplicateEmail(nextId(scheme, i));
    u.insert(extIdWithDuplicateEmail);
    expectedProblems.add(consistencyError("Email '" + extIdWithDuplicateEmail.email() + "' is not unique, it's used by the following external IDs: '" + extIdWithDuplicateEmail.key().get() + "', 'mailto:" + extIdWithDuplicateEmail.email() + "'"));
    ExternalId extIdWithBadPassword = createExternalIdWithBadPassword("admin-username");
    u.insert(extIdWithBadPassword);
    expectedProblems.add(consistencyError("External ID '" + extIdWithBadPassword.key().get() + "' has an invalid password: unrecognized algorithm"));
    return expectedProblems;
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) RefsMetaExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) HashSet(java.util.HashSet)

Example 7 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertValidExternalIds.

private void insertValidExternalIds() throws IOException, ConfigInvalidException, OrmException {
    MutableInteger i = new MutableInteger();
    String scheme = "valid";
    ExternalIdsUpdate u = extIdsUpdate.create();
    // create valid external IDs
    u.insert(ExternalId.createWithPassword(ExternalId.Key.parse(nextId(scheme, i)), admin.id, "admin.other@example.com", "secret-password"));
    u.insert(createExternalIdWithOtherCaseEmail(nextId(scheme, i)));
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) RefsMetaExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate)

Example 8 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeNoteUtil method parseNote.

public List<Comment> parseNote(byte[] note, MutableInteger p, Change.Id changeId) throws ConfigInvalidException {
    if (p.value >= note.length) {
        return ImmutableList.of();
    }
    Set<Comment.Key> seen = new HashSet<>();
    List<Comment> result = new ArrayList<>();
    int sizeOfNote = note.length;
    byte[] psb = PATCH_SET.getBytes(UTF_8);
    byte[] bpsb = BASE_PATCH_SET.getBytes(UTF_8);
    byte[] bpn = PARENT_NUMBER.getBytes(UTF_8);
    RevId revId = new RevId(parseStringField(note, p, changeId, REVISION));
    String fileName = null;
    PatchSet.Id psId = null;
    boolean isForBase = false;
    Integer parentNumber = null;
    while (p.value < sizeOfNote) {
        boolean matchPs = match(note, p, psb);
        boolean matchBase = match(note, p, bpsb);
        if (matchPs) {
            fileName = null;
            psId = parsePsId(note, p, changeId, PATCH_SET);
            isForBase = false;
        } else if (matchBase) {
            fileName = null;
            psId = parsePsId(note, p, changeId, BASE_PATCH_SET);
            isForBase = true;
            if (match(note, p, bpn)) {
                parentNumber = parseParentNumber(note, p, changeId);
            }
        } else if (psId == null) {
            throw parseException(changeId, "missing %s or %s header", PATCH_SET, BASE_PATCH_SET);
        }
        Comment c = parseComment(note, p, fileName, psId, revId, isForBase, parentNumber);
        fileName = c.key.filename;
        if (!seen.add(c.key)) {
            throw parseException(changeId, "multiple comments for %s in note", c.key);
        }
        result.add(c);
    }
    return result;
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) QuotedString(org.eclipse.jgit.util.QuotedString) RevId(com.google.gerrit.reviewdb.client.RevId) MutableInteger(org.eclipse.jgit.util.MutableInteger) FooterKey(org.eclipse.jgit.revwalk.FooterKey) HashSet(java.util.HashSet)

Example 9 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeRevisionNote method parse.

@Override
protected List<Comment> parse(byte[] raw, int offset) throws IOException, ConfigInvalidException {
    MutableInteger p = new MutableInteger();
    p.value = offset;
    if (isJson(raw, p.value)) {
        RevisionNoteData data = parseJson(noteUtil, raw, p.value);
        if (status == PatchLineComment.Status.PUBLISHED) {
            pushCert = data.pushCert;
        } else {
            pushCert = null;
        }
        return data.comments;
    }
    if (status == PatchLineComment.Status.PUBLISHED) {
        pushCert = parsePushCert(changeId, raw, p);
        trimLeadingEmptyLines(raw, p);
    } else {
        pushCert = null;
    }
    return noteUtil.parseNote(raw, p, changeId);
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger)

Example 10 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class RevisionNote method parse.

public void parse() throws IOException, ConfigInvalidException {
    raw = reader.open(noteId, OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
    MutableInteger p = new MutableInteger();
    trimLeadingEmptyLines(raw, p);
    if (p.value >= raw.length) {
        comments = ImmutableList.of();
        return;
    }
    comments = ImmutableList.copyOf(parse(raw, p.value));
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger)

Aggregations

MutableInteger (org.eclipse.jgit.util.MutableInteger)10 HashSet (java.util.HashSet)3 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 RevId (com.google.gerrit.reviewdb.client.RevId)2 ExternalIdsUpdate (com.google.gerrit.server.account.externalids.ExternalIdsUpdate)2 RefsMetaExternalIdsUpdate (com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate)2 Comment (com.google.gerrit.reviewdb.client.Comment)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)1 GerritServerId (com.google.gerrit.server.config.GerritServerId)1 IndexPredicate (com.google.gerrit.server.index.IndexPredicate)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 ArrayList (java.util.ArrayList)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Repository (org.eclipse.jgit.lib.Repository)1 FooterKey (org.eclipse.jgit.revwalk.FooterKey)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 QuotedString (org.eclipse.jgit.util.QuotedString)1