List of usage examples for org.eclipse.jgit.transport ReceivePack setPostReceiveHook
public void setPostReceiveHook(PostReceiveHook h)
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java
License:Open Source License
ReceivePack createReceivePack(Repository db) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
ReceivePack rp = new ReceivePack(db);
rp.setPostReceiveHook(new GitPostReceiveHook());
return rp;//from w w w . j ava2s. c o m
}
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepositorySSHAccess.java
License:Open Source License
@Override public ReceivePack createReceivePack(String fullRepositoryName) throws IOException, InterruptedException { if (isMine(fullRepositoryName)) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); ReceivePack rp = repo.createReceivePack(repo.openRepository()); rp.setPostReceiveHook(new GitPostReceiveHook()); return rp; }//w ww . j a v a2 s . c o m return null; }
From source file:com.gitblit.GitServlet.java
License:Apache License
@Override public void init(ServletConfig config) throws ServletException { groovyDir = GitBlit.getGroovyScriptsFolder(); try {//from ww w . j ava 2 s . co m // set Grape root File grapeRoot = new File(GitBlit.getString(Keys.groovy.grapeFolder, "groovy/grape")).getAbsoluteFile(); grapeRoot.mkdirs(); System.setProperty("grape.root", grapeRoot.getAbsolutePath()); gse = new GroovyScriptEngine(groovyDir.getAbsolutePath()); } catch (IOException e) { throw new ServletException("Failed to instantiate Groovy Script Engine!", e); } // set the Gitblit receive hook setReceivePackFactory(new DefaultReceivePackFactory() { @Override public ReceivePack create(HttpServletRequest req, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { // determine repository name from request String repositoryName = req.getPathInfo().substring(1); repositoryName = GitFilter.getRepositoryName(repositoryName); GitblitReceiveHook hook = new GitblitReceiveHook(); hook.repositoryName = repositoryName; hook.gitblitUrl = HttpUtils.getGitblitURL(req); ReceivePack rp = super.create(req, db); rp.setPreReceiveHook(hook); rp.setPostReceiveHook(hook); return rp; } }); super.init(new GitblitServletConfig(config)); }
From source file:com.google.gerrit.sshd.commands.Receive.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { if (!projectControl.canRunReceivePack()) { throw new Failure(1, "fatal: receive-pack not permitted on this server"); }//from w w w .j a va 2 s. c om final ReceiveCommits receive = factory.create(projectControl, repo).getReceiveCommits(); Capable r = receive.canUpload(); if (r != Capable.OK) { throw new UnloggedFailure(1, "\nfatal: " + r.getMessage()); } verifyProjectVisible("reviewer", reviewerId); verifyProjectVisible("CC", ccId); receive.addReviewers(reviewerId); receive.addExtraCC(ccId); final ReceivePack rp = receive.getReceivePack(); rp.setRefLogIdent(currentUser.newRefLogIdent()); rp.setTimeout(config.getTimeout()); rp.setMaxObjectSizeLimit(config.getEffectiveMaxObjectSizeLimit(projectControl.getProjectState())); init(rp); rp.setPostReceiveHook(PostReceiveHookChain.newChain(Lists.newArrayList(postReceiveHooks))); try { rp.receive(in, out, err); } catch (UnpackException badStream) { // In case this was caused by the user pushing an object whose size // is larger than the receive.maxObjectSizeLimit gerrit.config parameter // we want to present this error to the user if (badStream.getCause() instanceof TooLargeObjectInPackException) { StringBuilder msg = new StringBuilder(); msg.append("Receive error on project \"").append(projectControl.getProject().getName()) .append("\""); msg.append(" (user "); msg.append(currentUser.getAccount().getUserName()); msg.append(" account "); msg.append(currentUser.getAccountId()); msg.append("): "); msg.append(badStream.getCause().getMessage()); log.info(msg.toString()); throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage()); } // This may have been triggered by branch level access controls. // Log what the heck is going on, as detailed as we can. // StringBuilder msg = new StringBuilder(); msg.append("Unpack error on project \"").append(projectControl.getProject().getName()).append("\":\n"); msg.append(" AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook()); if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) { msg.append("DEFAULT"); } else if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) { msg.append("VisibleRefFilter"); } else { msg.append(rp.getAdvertiseRefsHook().getClass()); } msg.append("\n"); if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) { Map<String, Ref> adv = rp.getAdvertisedRefs(); msg.append(" Visible references (").append(adv.size()).append("):\n"); for (Ref ref : adv.values()) { msg.append(" - ").append(ref.getObjectId().abbreviate(8).name()).append(" ") .append(ref.getName()).append("\n"); } Map<String, Ref> allRefs = rp.getRepository().getRefDatabase().getRefs(RefDatabase.ALL); List<Ref> hidden = new ArrayList<>(); for (Ref ref : allRefs.values()) { if (!adv.containsKey(ref.getName())) { hidden.add(ref); } } msg.append(" Hidden references (").append(hidden.size()).append("):\n"); for (Ref ref : hidden) { msg.append(" - ").append(ref.getObjectId().abbreviate(8).name()).append(" ") .append(ref.getName()).append("\n"); } } IOException detail = new IOException(msg.toString(), badStream); throw new Failure(128, "fatal: Unpack error, check server log", detail); } }
From source file:com.tasktop.c2c.server.scm.web.GitHandler.java
License:Open Source License
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final boolean containerSupportsChunkedIO = computeContainerSupportsChunkedIO(); String pathInfo = request.getPathInfo(); log.info("Git request: " + request.getMethod() + " " + request.getRequestURI() + " " + pathInfo); Repository repository = null;//from w ww.j av a 2 s.c om try { // only work on Git requests Matcher matcher = pathInfo == null ? null : GIT_COMMAND_PATTERN.matcher(pathInfo); if (matcher == null || !matcher.matches()) { log.info("Unexpected path: " + pathInfo); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } String requestCommand = matcher.group(1); String requestPath = matcher.group(2); // sanity check on path, disallow path separator components if (requestPath == null || requestPath.contains("/") || requestPath.contains("..")) { badPathResponse(); } repository = repositoryResolver.open(request, requestPath); InputStream requestInput = request.getInputStream(); if (!containerSupportsChunkedIO) { requestInput = new ChunkedInputStream(requestInput); } MultiplexingOutputStream mox = createMultiplexingOutputStream(response, containerSupportsChunkedIO); // indicate that we're ok to handle the request // note that following this there will be a two-way communication with the process // that might still encounter errors. That's ok. startOkResponse(response, containerSupportsChunkedIO); // identify the git command GitCommand command = GitCommand.fromCommandName(requestCommand); if (command != null) { // permissions check if (!Security.hasOneOfRoles(command.getRoles())) { log.info("Access denied to " + Security.getCurrentUser() + " for " + command.getCommandName() + " on " + TenancyUtil.getCurrentTenantProjectIdentifer() + " " + requestPath); response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } switch (command) { case RECEIVE_PACK: ReceivePack rp = new ReceivePack(repository); rp.setPostReceiveHook(postReceiveHook); rp.receive(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; case UPLOAD_PACK: UploadPack up = new UploadPack(repository); up.upload(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; default: response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } // at this stage we're done with IO // send the exit value and closing chunk try { int exitValue = 0; if (exitValue != 0) { log.info("Exit value: " + exitValue); } mox.writeExitCode(exitValue); mox.close(); } catch (IOException e) { // ignore log.debug("Cannot complete writing exit state", e); } // clear interrupt status Thread.interrupted(); } catch (ErrorResponseException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotAuthorizedException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotEnabledException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } finally { log.info("Git request complete"); if (repository != null) { repository.close(); } } }
From source file:com.tasktop.c2c.server.scm.web.GitSmartHttpServlet.java
License:Open Source License
public void setPostRecieveHook(final PostReceiveHook hook) { ReceivePackFactory<HttpServletRequest> rpf = new DefaultReceivePackFactory() { public ReceivePack create(final HttpServletRequest req, final Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { ReceivePack result = super.create(req, db); if (!result.getPostReceiveHook().equals(PostReceiveHook.NULL)) { throw new IllegalStateException(); }/*from w w w . j a v a 2 s.c o m*/ result.setPostReceiveHook(hook); return result; } }; setReceivePackFactory(rpf); }
From source file:org.webcat.core.git.http.ReceivePackRequestHandler.java
License:Open Source License
/** * Handles the request and generates the ReceivePack response. * * @param request the request// w ww .j a va 2 s . co m * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE); if (RECEIVE_PACK_REQUEST_TYPE.equals(contentType)) { final Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); ReceivePack rp = new ReceivePack(repo); rp.setBiDirectionalPipe(false); rp.setPostReceiveHook(new PostReceiveHook() { public void onPostReceive(ReceivePack pack, Collection<ReceiveCommand> commands) { // Once the pack is received, force a pull of the working // copy so that anyone using Web-DAV will get synched. GitUtilities.workingCopyForRepository(repo, true); } }); response.setHeader(RECEIVE_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE); InputStream input = RequestUtils.inputStreamForRequest(request); SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response); rp.receive(input, output, null); output.close(); } else { response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE); } }
From source file:playRepository.RepositoryService.java
License:Apache License
private static void receivePack(final InputStream input, Repository repository, final OutputStream output, final PreReceiveHook preReceiveHook, final PostReceiveHook postReceiveHook) { final ReceivePack receivePack = new ReceivePack(repository); receivePack.setBiDirectionalPipe(false); new Thread() { @Override/*from w ww. j a v a2 s . c o m*/ public void run() { try { receivePack.setPreReceiveHook(preReceiveHook); receivePack.setPostReceiveHook(postReceiveHook); receivePack.receive(input, output, null); } catch (IOException e) { Logger.error("receivePack failed", e); } closeStreams("receivePack", input, output); } }.start(); }