Example usage for org.eclipse.jgit.notes NoteMap get

List of usage examples for org.eclipse.jgit.notes NoteMap get

Introduction

In this page you can find the example usage for org.eclipse.jgit.notes NoteMap get.

Prototype

public ObjectId get(AnyObjectId id) throws IOException 

Source Link

Document

Lookup a note for a specific ObjectId.

Usage

From source file:com.google.gerrit.gpg.PublicKeyStoreTest.java

License:Apache License

@Test
public void saveAppendsToExistingList() throws Exception {
    TestKey key1 = TestKey.key1();//from w  w  w .  j  av a2  s .c om
    TestKey key2 = TestKey.key2();
    tr.branch(REFS_GPG_KEYS).commit()
            // Mismatched for this key ID, but we can still read it out.
            .add(keyObjectId(key1.getKeyId()).name(), key2.getPublicKeyArmored()).create();

    store.add(key1.getPublicKeyRing());
    assertEquals(RefUpdate.Result.FAST_FORWARD, store.save(newCommitBuilder()));

    assertKeys(key1.getKeyId(), key1, key2);

    try (ObjectReader reader = tr.getRepository().newObjectReader(); RevWalk rw = new RevWalk(reader)) {
        NoteMap notes = NoteMap.read(reader,
                tr.getRevWalk().parseCommit(tr.getRepository().getRef(REFS_GPG_KEYS).getObjectId()));
        String contents = new String(reader.open(notes.get(keyObjectId(key1.getKeyId()))).getBytes(), UTF_8);
        String header = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
        int i1 = contents.indexOf(header);
        assertTrue(i1 >= 0);
        int i2 = contents.indexOf(header, i1 + header.length());
        assertTrue(i2 >= 0);
    }
}

From source file:com.google.gerrit.server.account.externalids.ExternalIdReader.java

License:Apache License

private static ExternalId parse(ExternalId.Key key, RevWalk rw, ObjectId rev)
        throws IOException, ConfigInvalidException {
    NoteMap noteMap = readNoteMap(rw, rev);
    ObjectId noteId = key.sha1();//from   ww w .j a  va  2s . com
    if (!noteMap.contains(noteId)) {
        return null;
    }

    byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
    return ExternalId.parse(noteId.name(), raw);
}

From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java

License:Apache License

/**
 * Insert or updates an new external ID and sets it in the note map.
 *
 * <p>If the external ID already exists it is overwritten.
 *//*from ww w .  j  av a2s  .co m*/
public static void upsert(RevWalk rw, ObjectInserter ins, NoteMap noteMap, ExternalId extId)
        throws IOException, ConfigInvalidException {
    ObjectId noteId = extId.key().sha1();
    Config c = new Config();
    if (noteMap.contains(extId.key().sha1())) {
        byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
        try {
            c.fromText(new String(raw, UTF_8));
        } catch (ConfigInvalidException e) {
            throw new ConfigInvalidException(
                    String.format("Invalid external id config for note %s: %s", noteId, e.getMessage()));
        }
    }
    extId.writeToConfig(c);
    byte[] raw = c.toText().getBytes(UTF_8);
    ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
    noteMap.set(noteId, dataBlob);
}

From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java

License:Apache License

/**
 * Removes an external ID from the note map.
 *
 * @throws IllegalStateException is thrown if there is an existing external ID that has the same
 *     key, but otherwise doesn't match the specified external ID.
 *//*from www  .jav a  2 s.  co  m*/
public static void remove(RevWalk rw, NoteMap noteMap, ExternalId extId)
        throws IOException, ConfigInvalidException {
    ObjectId noteId = extId.key().sha1();
    if (!noteMap.contains(noteId)) {
        return;
    }

    byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
    ExternalId actualExtId = ExternalId.parse(noteId.name(), raw);
    checkState(extId.equals(actualExtId),
            "external id %s should be removed, but it's not matching the actual external id %s",
            extId.toString(), actualExtId.toString());
    noteMap.remove(noteId);
}

From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java

License:Apache License

/**
 * Removes an external ID from the note map by external ID key.
 *
 * @throws IllegalStateException is thrown if an expected account ID is provided and an external
 *     ID with the specified key exists, but belongs to another account.
 *///from   w w  w .j  ava2 s.  co  m
private static void remove(RevWalk rw, NoteMap noteMap, ExternalId.Key extIdKey, Account.Id expectedAccountId)
        throws IOException, ConfigInvalidException {
    ObjectId noteId = extIdKey.sha1();
    if (!noteMap.contains(noteId)) {
        return;
    }

    byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
    ExternalId extId = ExternalId.parse(noteId.name(), raw);
    if (expectedAccountId != null) {
        checkState(expectedAccountId.equals(extId.accountId()),
                "external id %s should be removed for account %s," + " but external id belongs to account %s",
                extIdKey.get(), expectedAccountId.get(), extId.accountId().get());
    }
    noteMap.remove(noteId);
}