use of org.gradle.internal.ErroringAction in project gradle by gradle.
the class GitHttpRepository method expectCloneSomething.
public void expectCloneSomething() {
server.expect(server.get(backingRepo.getName() + "/info/refs", getRefsAction()));
server.expect(server.post(backingRepo.getName() + "/git-upload-pack", new ErroringAction<HttpExchange>() {
@Override
protected void doExecute(HttpExchange httpExchange) throws Exception {
httpExchange.getResponseHeaders().add("content-type", "application/x-git-upload-pack-result");
httpExchange.sendResponseHeaders(200, 0);
ProcessBuilder builder = new ProcessBuilder();
final Process process = builder.command("git", "upload-pack", "--stateless-rpc", backingRepo.getWorkTree().getAbsolutePath()).redirectErrorStream(true).start();
InputStream instream = new GZIPInputStream(httpExchange.getRequestBody());
ByteArrayOutputStream requestContent = new ByteArrayOutputStream();
IOUtils.copy(instream, requestContent);
byte[] bytes = requestContent.toByteArray();
process.getOutputStream().write(bytes);
process.getOutputStream().flush();
IOUtils.copy(process.getInputStream(), httpExchange.getResponseBody());
int result = process.waitFor();
if (result != 0) {
throw new RuntimeException("Failed to run git upload-pack");
}
}
}));
}
use of org.gradle.internal.ErroringAction in project gradle by gradle.
the class GitHttpRepository method getRefsAction.
private Action<HttpExchange> getRefsAction() {
return new ErroringAction<HttpExchange>() {
@Override
protected void doExecute(HttpExchange httpExchange) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
Process process = builder.command("git", "upload-pack", "--advertise-refs", backingRepo.getWorkTree().getAbsolutePath()).redirectErrorStream(true).start();
ByteArrayOutputStream content = new ByteArrayOutputStream();
content.write("001e# service=git-upload-pack\n".getBytes());
content.write("0000".getBytes());
IOUtils.copy(process.getInputStream(), content);
process.waitFor();
int result = process.waitFor();
if (result != 0) {
throw new RuntimeException("Failed to run git upload-pack");
}
byte[] bytes = content.toByteArray();
httpExchange.getResponseHeaders().add("content-type", "application/x-git-upload-pack-advertisement");
httpExchange.sendResponseHeaders(200, bytes.length);
httpExchange.getResponseBody().write(bytes);
}
};
}
Aggregations