Example usage for org.eclipse.jgit.lib ObjectId name

List of usage examples for org.eclipse.jgit.lib ObjectId name

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId name.

Prototype

public final String name() 

Source Link

Document

name.

Usage

From source file:com.google.gerrit.acceptance.rest.project.CommitIncludedInIT.java

License:Apache License

private IncludedInInfo getIncludedIn(ObjectId id) throws Exception {
    RestResponse r = userRestSession.get("/projects/" + project.get() + "/commits/" + id.name() + "/in");
    IncludedInInfo result = newGson().fromJson(r.getReader(), IncludedInInfo.class);
    r.consume();//from  w w w. j  a  va  2s. com
    return result;
}

From source file:com.google.gerrit.acceptance.rest.project.GetCommitIT.java

License:Apache License

private void assertNotFound(ObjectId id) throws Exception {
    RestResponse r = userSession.get("/projects/" + project.get() + "/commits/" + id.name());
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
}

From source file:com.google.gerrit.acceptance.rest.project.GetCommitIT.java

License:Apache License

private CommitInfo getCommit(ObjectId id) throws Exception {
    RestResponse r = userSession.get("/projects/" + project.get() + "/commits/" + id.name());
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class);
    r.consume();//from w  w w  . j ava 2 s.c o  m
    return result;
}

From source file:com.google.gerrit.acceptance.server.change.GetRelatedIT.java

License:Apache License

private static ChangeAndCommit changeAndCommit(String changeId, ObjectId commitId, int revisionNum,
        int currentRevisionNum) {
    ChangeAndCommit result = new ChangeAndCommit();
    result.changeId = changeId;// ww w.  j  a va2 s  .c  o m
    result.commit = new CommitInfo();
    result.commit.commit = commitId.name();
    result._revisionNumber = revisionNum;
    result._currentRevisionNumber = currentRevisionNum;
    result.status = "NEW";
    return result;
}

From source file:com.google.gerrit.acceptance.server.notedb.ChangeRebuilderIT.java

License:Apache License

@Test
public void noteDbChangeState() throws Exception {
    notesMigration.setAllEnabled(true);// ww  w .  ja v a2s.c  o  m
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getPatchSetId().getParentKey();

    ObjectId changeMetaId = getMetaRef(project, changeMetaRef(id));
    assertThat(unwrapDb().changes().get(id).getNoteDbState()).isEqualTo(changeMetaId.name());

    putDraft(user, id, 1, "comment by user");
    ObjectId userDraftsId = getMetaRef(allUsers, RefNames.refsDraftComments(id, user.getId()));
    assertThat(unwrapDb().changes().get(id).getNoteDbState())
            .isEqualTo(changeMetaId.name() + "," + user.getId() + "=" + userDraftsId.name());

    putDraft(admin, id, 2, "comment by admin");
    ObjectId adminDraftsId = getMetaRef(allUsers, RefNames.refsDraftComments(id, admin.getId()));
    assertThat(admin.getId().get()).isLessThan(user.getId().get());
    assertThat(unwrapDb().changes().get(id).getNoteDbState()).isEqualTo(changeMetaId.name() + ","
            + admin.getId() + "=" + adminDraftsId.name() + "," + user.getId() + "=" + userDraftsId.name());

    putDraft(admin, id, 2, "revised comment by admin");
    adminDraftsId = getMetaRef(allUsers, RefNames.refsDraftComments(id, admin.getId()));
    assertThat(unwrapDb().changes().get(id).getNoteDbState()).isEqualTo(changeMetaId.name() + ","
            + admin.getId() + "=" + adminDraftsId.name() + "," + user.getId() + "=" + userDraftsId.name());
}

From source file:com.google.gerrit.acceptance.server.notedb.NoteDbOnlyIT.java

License:Apache License

@Test
public void updateChangeFailureRollsBackRefUpdate() throws Exception {
    assume().that(notesMigration.fuseUpdates()).isTrue();
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();

    String master = "refs/heads/master";
    String backup = "refs/backup/master";
    ObjectId master1 = getRef(master).get();
    assertThat(getRef(backup)).isEmpty();

    // Toy op that copies the value of refs/heads/master to refs/backup/master.
    BatchUpdateOp backupMasterOp = new BatchUpdateOp() {
        ObjectId newId;/*from  www.j a  v a 2 s. com*/

        @Override
        public void updateRepo(RepoContext ctx) throws IOException {
            ObjectId oldId = ctx.getRepoView().getRef(backup).orElse(ObjectId.zeroId());
            newId = ctx.getRepoView().getRef(master).get();
            ctx.addRefUpdate(oldId, newId, backup);
        }

        @Override
        public boolean updateChange(ChangeContext ctx) {
            ctx.getUpdate(ctx.getChange().currentPatchSetId())
                    .setChangeMessage("Backed up master branch to " + newId.name());
            return true;
        }
    };

    try (BatchUpdate bu = newBatchUpdate()) {
        bu.addOp(id, backupMasterOp);
        bu.execute();
    }

    // Ensure backupMasterOp worked.
    assertThat(getRef(backup)).hasValue(master1);
    assertThat(getMessages(id)).contains("Backed up master branch to " + master1.name());

    // Advance master by submitting the change.
    gApi.changes().id(id.get()).current().review(ReviewInput.approve());
    gApi.changes().id(id.get()).current().submit();
    ObjectId master2 = getRef(master).get();
    assertThat(master2).isNotEqualTo(master1);
    int msgCount = getMessages(id).size();

    try (BatchUpdate bu = newBatchUpdate()) {
        // This time, we attempt to back up master, but we fail during updateChange.
        bu.addOp(id, backupMasterOp);
        String msg = "Change is bad";
        bu.addOp(id, new BatchUpdateOp() {
            @Override
            public boolean updateChange(ChangeContext ctx) throws ResourceConflictException {
                throw new ResourceConflictException(msg);
            }
        });
        try {
            bu.execute();
            assert_().fail("expected ResourceConflictException");
        } catch (ResourceConflictException e) {
            assertThat(e).hasMessageThat().isEqualTo(msg);
        }
    }

    // If updateChange hadn't failed, backup would have been updated to master2.
    assertThat(getRef(backup)).hasValue(master1);
    assertThat(getMessages(id)).hasSize(msgCount);
}

From source file:com.google.gerrit.pgm.rules.PrologCompiler.java

License:Apache License

@Override
public Status call() throws IOException, CompileException {
    ObjectId metaConfig = git.resolve(RefNames.REFS_CONFIG);
    if (metaConfig == null) {
        return Status.NO_RULES;
    }/*from  www  .j  av  a2  s . c om*/

    ObjectId rulesId = git.resolve(metaConfig.name() + ":rules.pl");
    if (rulesId == null) {
        return Status.NO_RULES;
    }

    if (ruleDir == null) {
        throw new CompileException("Caching not enabled");
    }
    Files.createDirectories(ruleDir);

    File tempDir = File.createTempFile("GerritCodeReview_", ".rulec");
    if (!tempDir.delete() || !tempDir.mkdir()) {
        throw new IOException("Cannot create " + tempDir);
    }
    try {
        // Try to make the directory accessible only by this process.
        // This may help to prevent leaking rule data to outsiders.
        tempDir.setReadable(true, true);
        tempDir.setWritable(true, true);
        tempDir.setExecutable(true, true);

        compileProlog(rulesId, tempDir);
        compileJava(tempDir);

        Path jarPath = ruleDir.resolve("rules-" + rulesId.getName() + ".jar");
        List<String> classFiles = getRelativePaths(tempDir, ".class");
        createJar(jarPath, classFiles, tempDir, metaConfig, rulesId);

        return Status.COMPILED;
    } finally {
        deleteAllFiles(tempDir);
    }
}

From source file:com.google.gerrit.pgm.rules.PrologCompiler.java

License:Apache License

/** Takes compiled prolog .class files, puts them into the jar file. */
private void createJar(Path archiveFile, List<String> toBeJared, File tempDir, ObjectId metaConfig,
        ObjectId rulesId) throws IOException {
    long now = TimeUtil.nowMs();
    Manifest mf = new Manifest();
    mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    mf.getMainAttributes().putValue("Built-by", "Gerrit Code Review " + Version.getVersion());
    if (git.getDirectory() != null) {
        mf.getMainAttributes().putValue("Source-Repository", git.getDirectory().getPath());
    }//from   ww  w  .  j  a  v  a  2 s  . c  o  m
    mf.getMainAttributes().putValue("Source-Commit", metaConfig.name());
    mf.getMainAttributes().putValue("Source-Blob", rulesId.name());

    Path tmpjar = Files.createTempFile(archiveFile.getParent(), ".rulec_", ".jar");
    try (OutputStream stream = Files.newOutputStream(tmpjar);
            JarOutputStream out = new JarOutputStream(stream, mf)) {
        byte[] buffer = new byte[10240];
        // TODO: fixify this loop
        for (String path : toBeJared) {
            JarEntry jarAdd = new JarEntry(path);
            File f = new File(tempDir, path);
            jarAdd.setTime(now);
            out.putNextEntry(jarAdd);
            if (f.isFile()) {
                try (FileInputStream in = new FileInputStream(f)) {
                    while (true) {
                        int nRead = in.read(buffer, 0, buffer.length);
                        if (nRead <= 0) {
                            break;
                        }
                        out.write(buffer, 0, nRead);
                    }
                }
            }
            out.closeEntry();
        }
    }

    try {
        Files.move(tmpjar, archiveFile);
    } catch (IOException e) {
        throw new IOException("Cannot replace " + archiveFile, e);
    }
}

From source file:com.google.gerrit.rules.PrologCompiler.java

License:Apache License

@Override
public Status call() throws IOException, CompileException {
    ObjectId metaConfig = git.resolve(RefNames.REFS_CONFIG);
    if (metaConfig == null) {
        return Status.NO_RULES;
    }//from  w ww. j ava  2  s  .  co m

    ObjectId rulesId = git.resolve(metaConfig.name() + ":rules.pl");
    if (rulesId == null) {
        return Status.NO_RULES;
    }

    if (ruleDir == null) {
        throw new CompileException("Caching not enabled");
    }
    if (!ruleDir.isDirectory() && !ruleDir.mkdir()) {
        throw new IOException("Cannot create " + ruleDir);
    }

    File tempDir = File.createTempFile("GerritCodeReview_", ".rulec");
    if (!tempDir.delete() || !tempDir.mkdir()) {
        throw new IOException("Cannot create " + tempDir);
    }
    try {
        // Try to make the directory accessible only by this process.
        // This may help to prevent leaking rule data to outsiders.
        tempDir.setReadable(true, true);
        tempDir.setWritable(true, true);
        tempDir.setExecutable(true, true);

        compileProlog(rulesId, tempDir);
        compileJava(tempDir);

        File jarFile = new File(ruleDir, "rules-" + rulesId.getName() + ".jar");
        List<String> classFiles = getRelativePaths(tempDir, ".class");
        createJar(jarFile, classFiles, tempDir, metaConfig, rulesId);

        return Status.COMPILED;
    } finally {
        deleteAllFiles(tempDir);
    }
}

From source file:com.google.gerrit.rules.PrologCompiler.java

License:Apache License

/** Takes compiled prolog .class files, puts them into the jar file. */
private void createJar(File archiveFile, List<String> toBeJared, File tempDir, ObjectId metaConfig,
        ObjectId rulesId) throws IOException {
    long now = TimeUtil.nowMs();
    File tmpjar = File.createTempFile(".rulec_", ".jar", archiveFile.getParentFile());
    try {//from  w ww.ja v  a2s  .co m
        Manifest mf = new Manifest();
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        mf.getMainAttributes().putValue("Built-by", "Gerrit Code Review " + Version.getVersion());
        if (git.getDirectory() != null) {
            mf.getMainAttributes().putValue("Source-Repository", git.getDirectory().getPath());
        }
        mf.getMainAttributes().putValue("Source-Commit", metaConfig.name());
        mf.getMainAttributes().putValue("Source-Blob", rulesId.name());

        try (FileOutputStream stream = new FileOutputStream(tmpjar);
                JarOutputStream out = new JarOutputStream(stream, mf)) {
            byte buffer[] = new byte[10240];
            for (String path : toBeJared) {
                JarEntry jarAdd = new JarEntry(path);
                File f = new File(tempDir, path);
                jarAdd.setTime(now);
                out.putNextEntry(jarAdd);
                if (f.isFile()) {
                    FileInputStream in = new FileInputStream(f);
                    try {
                        while (true) {
                            int nRead = in.read(buffer, 0, buffer.length);
                            if (nRead <= 0) {
                                break;
                            }
                            out.write(buffer, 0, nRead);
                        }
                    } finally {
                        in.close();
                    }
                }
                out.closeEntry();
            }
        }

        if (!tmpjar.renameTo(archiveFile)) {
            throw new IOException("Cannot replace " + archiveFile);
        }
    } finally {
        tmpjar.delete();
    }
}