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

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

Introduction

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

Prototype

public void copyTo(OutputStream w) throws IOException 

Source Link

Document

Copy this ObjectId to an output writer in hex format.

Usage

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkRemoteObjectDatabase.java

License:Eclipse Distribution License

/**
 * Overwrite (or create) a loose ref in the remote repository.
 * <p>/*from  w w w. ja v  a2  s  .  co m*/
 * This method creates any missing parent directories, if necessary.
 *
 * @param name
 *            name of the ref within the ref space, for example
 *            <code>refs/heads/pu</code>.
 * @param value
 *            new value to store in this ref. Must not be null.
 * @throws IOException
 *             writing is not supported, or attempting to write the file
 *             failed, possibly due to permissions or remote disk full, etc.
 */
void writeRef(final String name, final ObjectId value) throws IOException {
    final ByteArrayOutputStream b;

    b = new ByteArrayOutputStream(Constants.OBJECT_ID_STRING_LENGTH + 1);
    value.copyTo(b);
    b.write('\n');

    writeFile(ROOT_DIR + name, b.toByteArray());
}

From source file:org.jvnet.hudson.plugins.m2release.ReleaseEnvironment.java

License:Open Source License

/**
 * Writes the current head commit hash into jenkins-home/jobs/job-name/lastReleaseRevisionNumber
 *
 * @return the commit hash that was written
 *//*from w  ww  . j  a v  a2s . c  o m*/
private String writeLatestReleaseRevisionNumber(AbstractBuild bld, TaskListener lstnr) {
    try {
        //write the latest release revision number
        SCM scm = bld.getProject().getScm();
        if (scm instanceof GitSCM) {
            GitSCM gitSCM = (GitSCM) scm;
            AbstractProject project = bld.getProject();
            final EnvVars environment = GitUtils.getPollEnvironment(project, bld.getWorkspace(), launcher,
                    lstnr);
            GitClient gitClient = gitSCM.createClient(lstnr, environment, bld, bld.getWorkspace());
            ObjectId objectId = gitClient.revParse(M2ReleaseBuildWrapper.DEFAULT_REF);
            StringWriter writer = new StringWriter();
            objectId.copyTo(writer);
            String headHash = writer.toString();

            TextFile file = ReleaseUtils.getLastReleaseRevisionNumberFile(project);
            file.write(headHash);
            return headHash;
        }
    } catch (IOException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw)); //todo
        lstnr.getLogger().println("[WSO2 Maven Release] Error " + e.getMessage() + " " + sw.toString());
    } catch (Throwable e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw)); //todo
        lstnr.getLogger().println("[WSO2 Maven Release] Error " + e.getMessage() + " " + sw.toString());
    }

    return "-";
}