Example usage for org.eclipse.jgit.transport PacketLineOut end

List of usage examples for org.eclipse.jgit.transport PacketLineOut end

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport PacketLineOut end.

Prototype

public void end() throws IOException 

Source Link

Document

Write a packet end marker, sometimes referred to as a flush command.

Usage

From source file:com.google.gerrit.acceptance.ssh.UploadArchiveIT.java

License:Apache License

private InputStream argumentsToInputStream(String c) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PacketLineOut pctOut = new PacketLineOut(out);
    for (String arg : Splitter.on(' ').split(c)) {
        pctOut.writeString("argument " + arg);
    }//from  w w  w.j  av  a 2  s  .  c  o m
    pctOut.end();
    return new ByteArrayInputStream(out.toByteArray());
}

From source file:com.google.gerrit.sshd.commands.UploadArchive.java

License:Apache License

@Override
protected void runImpl() throws IOException, Failure {
    PacketLineOut packetOut = new PacketLineOut(out);
    packetOut.setFlushOnEnd(true);//from w  w w.j a  v a 2 s  .c  o m
    packetOut.writeString("ACK");
    packetOut.end();

    try {
        // Parse Git arguments
        readArguments();

        ArchiveFormat f = allowedFormats.getExtensions().get("." + options.format);
        if (f == null) {
            throw new Failure(3, "fatal: upload-archive not permitted");
        }

        // Find out the object to get from the specified reference and paths
        ObjectId treeId = repo.resolve(options.treeIsh);
        if (treeId == null) {
            throw new Failure(4, "fatal: reference not found");
        }

        // Verify the user has permissions to read the specified reference
        if (!projectControl.allRefsAreVisible() && !canRead(treeId)) {
            throw new Failure(5, "fatal: cannot perform upload-archive operation");
        }

        // The archive is sent in DATA sideband channel
        try (SideBandOutputStream sidebandOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA,
                SideBandOutputStream.MAX_BUF, out)) {
            new ArchiveCommand(repo).setFormat(f.name()).setFormatOptions(getFormatOptions(f)).setTree(treeId)
                    .setPaths(options.path.toArray(new String[0])).setPrefix(options.prefix)
                    .setOutputStream(sidebandOut).call();
            sidebandOut.flush();
        } catch (GitAPIException e) {
            throw new Failure(7, "fatal: git api exception, " + e);
        }
    } catch (Failure f) {
        // Report the error in ERROR sideband channel
        try (SideBandOutputStream sidebandError = new SideBandOutputStream(SideBandOutputStream.CH_ERROR,
                SideBandOutputStream.MAX_BUF, out)) {
            sidebandError.write(f.getMessage().getBytes(UTF_8));
            sidebandError.flush();
        }
        throw f;
    } finally {
        // In any case, cleanly close the packetOut channel
        packetOut.end();
    }
}

From source file:org.webcat.core.git.http.SmartHttpInfoRefsFilter.java

License:Open Source License

/**
 * Delegates to the/*from  w  w  w .  j  a  v  a  2 s .  c om*/
 * {@link #advertise(WORequest, Repository, PacketLineOutRefAdvertiser)}
 * method on the class and then appends the advertisement to the response.
 *
 * @param request the request
 * @param response the response
 * @param filterChain the filter chain
 * @throws Exception if an error occurred
 */
public void filterRequest(WORequest request, WOResponse response, RequestFilterChain filterChain)
        throws Exception {
    if (service.equals(request.formValueForKey("service"))) {
        try {
            Repository repo = RepositoryRequestUtils.repositoryFromRequest(request);

            response.setHeader("application/x-" + service + "-advertisement", HttpSupport.HDR_CONTENT_TYPE);

            NSMutableDataOutputStream output = new NSMutableDataOutputStream();
            PacketLineOut lineOut = new PacketLineOut(output);

            lineOut.writeString("# service=" + service + "\n");
            lineOut.end();

            advertise(request, repo, new PacketLineOutRefAdvertiser(lineOut));

            output.close();
            response.appendContentData(output.data());
        } catch (IOException e) {
            Log.error("(403) An exception occurred when advertising the " + "repository", e);
            response.setStatus(WOMessage.HTTP_STATUS_FORBIDDEN);
        }
    } else {
        filterChain.filterRequest(request, response);
    }
}

From source file:playRepository.RepositoryService.java

License:Apache License

/**
 * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/git-upload-pack.html">git-upload-pack</a>
 * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/git-receive-pack.html">git-receive-pack</a>
 *///from  w  w w  . j  av  a  2 s .c om
public static byte[] gitAdvertise(Project project, String service, Response response) throws IOException {
    response.setContentType("application/x-" + service + "-advertisement");

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    PacketLineOut packetLineOut = new PacketLineOut(byteArrayOutputStream);
    packetLineOut.writeString("# service=" + service + "\n");
    packetLineOut.end();
    PacketLineOutRefAdvertiser packetLineOutRefAdvertiser = new PacketLineOutRefAdvertiser(packetLineOut);

    if (service.equals("git-upload-pack")) {
        Repository repository = GitRepository.buildGitRepository(project);
        UploadPack uploadPack = new UploadPack(repository);
        uploadPack.setBiDirectionalPipe(false);
        uploadPack.sendAdvertisedRefs(packetLineOutRefAdvertiser);
    } else if (service.equals("git-receive-pack")) {
        Repository repository = GitRepository.buildGitRepository(project, false);
        ReceivePack receivePack = new ReceivePack(repository);
        receivePack.sendAdvertisedRefs(packetLineOutRefAdvertiser);
    }

    byteArrayOutputStream.close();

    return byteArrayOutputStream.toByteArray();
}